首页 > 编程学习 > redis 模仿队列

redis 模仿队列

发布时间:2022/11/24 23:20:46

Connect 连接类

<?phpnamespace redis\string;use Redis;class Connect
{public $redis = null;/*** Connect constructor.* @param null $redis*/public function __construct(){$redis = new Redis();$redis->connect('127.0.0.1', 6379);$this->redis = $redis;}}

RedisStringTest 使用

<?php
namespace redis\string;/*** Class RedisStringTest* @package redis\string*/
class RedisStringTest extends Connect
{private $key = 'mylist';public function re(){$arr = array('h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd');foreach ($arr as $k => $v) {$this->redis->rpush($this->key, $v);}}public function de(){//list类型出队操作$value = $this->redis->lpop($this->key);if ($value) {echo "出队的值".$value;} else {echo "出队完成";}}}

RedisTest 测试

<?phpnamespace app\index\controller;use redis\string\RedisStringTest;
use think\Controller;class RedisTest extends Controller
{private $key = null;public function re(RedisStringTest $redisStringTest){$redisStringTest->re();echo 'success';}public function de(RedisStringTest $redisStringTest){$redisStringTest->de();}}

本文链接:https://www.ngui.cc/el/2111883.html
Copyright © 2010-2022 ngui.cc 版权所有 |关于我们| 联系方式| 豫B2-20100000