Connect 连接类
<?php
namespace 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 测试
<?php
namespace 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();
}
}