thinkphp6框架中封装redis操作类
在Thinkphp6框架项目中封装一个简单的Redis单例操作类:
<?php
namespace app\Api\server;
class Redis
{
protected $redis;
private static $instance;
private function __construct()
{
$this->redis = new \Redis();
$this->redis->connect('127.0.0.1', 6379);
}
private function __clone()
{
// TODO: Implement __clone() method.
}
static public function getInstance()
{
if (self::$instance) {
return self::$instance;
}
self::$instance = new self();
return self::$instance;
}
/**
*@return \Redis
*/
public function get($key)
{
return $this->redis->get($key);
}
/**
*@return \Redis
*/
public function set($key, $val, $ttl=99999999999999999)
{
return $this->redis->setex($key, $ttl, $val);
}
/**
*求出队列的长度
*@return bool|int
*/
public function lLen($key)
{
return $this->redis->lLen($key);
}
/**
*@$param
*@return bool
*/
public function sIsMember($setName, $member)
{
return $this->redis->sIsMember($setName, $member);
}
public function sAdd($setName, $member)
{
return $this->redis->sAdd($setName,$member);
}
public function lpop($lname)
{
return $this->redis->lPop($lname);
}
相关文章