86 lines
2.4 KiB
PHP
86 lines
2.4 KiB
PHP
<?php
|
|
namespace app\common\driver;
|
|
|
|
use think\cache\driver\Redis;
|
|
|
|
class CustomRedis extends Redis
|
|
{
|
|
//增加自有方法
|
|
//常规方法
|
|
public function keys($name) {
|
|
$keys_list=$this->handler->keys($this->options['prefix'].$name);
|
|
$start_index=strlen($this->options['prefix']);
|
|
foreach ($keys_list as $k=>$v) {
|
|
$keys_list[$k]=substr($v,$start_index);
|
|
}
|
|
return $keys_list;
|
|
}
|
|
|
|
public function batch_del($name) {
|
|
if (is_array($name)) {
|
|
foreach ($name as $k=>$v) {
|
|
$name[$k]=$this->options['prefix'].$v;
|
|
}
|
|
} else {
|
|
$name=$this->options['prefix'].$name;
|
|
}
|
|
return $this->handler->delete($name);
|
|
}
|
|
|
|
public function expire($name,$timeout) {
|
|
return $this->handler->expire($this->options['prefix'].$name,$timeout);
|
|
}
|
|
|
|
//LIST相关操作方法
|
|
public function lpush($name,$value) {
|
|
return $this->handler->lpush($this->options['prefix'].$name,$value);
|
|
}
|
|
|
|
public function lrange($name) {
|
|
return $this->handler->lrange($this->options['prefix'].$name,0,-1);
|
|
}
|
|
|
|
public function llen($name) {
|
|
return $this->handler->llen($this->options['prefix'].$name);
|
|
}
|
|
|
|
public function lrem($name,$value,$count=0) {
|
|
return $this->handler->lrem($this->options['prefix'].$name,$value,$count);
|
|
}
|
|
|
|
public function rpoplpush($name) {
|
|
return $this->handler->rpoplpush($this->options['prefix'].$name,$this->options['prefix'].$name);
|
|
}
|
|
|
|
public function rpop($name) {
|
|
return $this->handler->rpop($this->options['prefix'].$name);
|
|
}
|
|
|
|
public function brpop($name,$timeout) {
|
|
return $this->handler->brpop($this->options['prefix'].$name,$timeout);
|
|
}
|
|
//--
|
|
|
|
//增加hashset方法
|
|
public function hset($name,$key,$value) {
|
|
return $this->handler->hset($this->options['prefix'].$name,$key,$value);
|
|
}
|
|
|
|
public function hget($name,$key) {
|
|
return $this->handler->hget($this->options['prefix'].$name,$key);
|
|
}
|
|
|
|
public function hmget($name,$key_list) {
|
|
return $this->handler->hmget($this->options['prefix'].$name,$key_list);
|
|
}
|
|
|
|
public function hdel($name,$key) {
|
|
return $this->handler->hdel($this->options['prefix'].$name,$key);
|
|
}
|
|
|
|
public function hkeys($name) {
|
|
return $this->handler->hkeys($this->options['prefix'].$name);
|
|
}
|
|
//--
|
|
}
|