|
@@ -25,8 +25,7 @@ require __DIR__ . '/Predis/Autoloader.php';
|
|
|
* 1.0.1 扩充了事务的使用方法.开发竞争类业务,圣树争夺战, gwang 2016.3.21 <br/>
|
|
|
* 1.0.0 pguan,基础功能, 方法与memcache看齐. <br/>
|
|
|
*/
|
|
|
-class CRedisUtil extends CMemBase
|
|
|
-{
|
|
|
+class CRedisUtil extends CMemBase {
|
|
|
|
|
|
public $keyDic = null;
|
|
|
|
|
@@ -39,13 +38,11 @@ class CRedisUtil extends CMemBase
|
|
|
/**
|
|
|
* 自动回收
|
|
|
*/
|
|
|
- function __destruct()
|
|
|
- {
|
|
|
+ function __destruct() {
|
|
|
$this->close();
|
|
|
}
|
|
|
|
|
|
- private static function debug()
|
|
|
- {
|
|
|
+ private static function debug() {
|
|
|
if (defined('Redis_Debug') && Redis_Debug) {
|
|
|
DebugHelper::print_stack_trace();
|
|
|
}
|
|
@@ -60,8 +57,7 @@ class CRedisUtil extends CMemBase
|
|
|
* @param int $ts=0 此值无效
|
|
|
* @return true 成功, false 失败,此key已经存在
|
|
|
*/
|
|
|
- public function add($key, $value, $ts = 0)
|
|
|
- {
|
|
|
+ public function add($key, $value, $ts = 0) {
|
|
|
self::debug();
|
|
|
return $this->setnx($key, JsonUtil::encode($value));
|
|
|
}
|
|
@@ -71,8 +67,7 @@ class CRedisUtil extends CMemBase
|
|
|
* @param string $surKey 源数据的key
|
|
|
* @param string $desKey 目的数据的key
|
|
|
*/
|
|
|
- public function copy($surKey, $desKey)
|
|
|
- {
|
|
|
+ public function copy($surKey, $desKey) {
|
|
|
self::debug();
|
|
|
return $this->set($desKey, $this->get($surKey));
|
|
|
}
|
|
@@ -82,8 +77,7 @@ class CRedisUtil extends CMemBase
|
|
|
* @param array(string) $keys
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function getMulti($keys)
|
|
|
- {
|
|
|
+ public function getMulti($keys) {
|
|
|
self::debug();
|
|
|
// var_dump($keys);
|
|
|
return $this->mget($keys);
|
|
@@ -95,8 +89,7 @@ class CRedisUtil extends CMemBase
|
|
|
* @param int $expireTs=0 此值无效
|
|
|
* @return true 永远成功
|
|
|
*/
|
|
|
- public function setMutlti($dict, $expireTs = 0)
|
|
|
- {
|
|
|
+ public function setMutlti($dict, $expireTs = 0) {
|
|
|
self::debug();
|
|
|
$params = array();
|
|
|
foreach ($dict as $key => $val) {
|
|
@@ -116,8 +109,7 @@ class CRedisUtil extends CMemBase
|
|
|
* @param int $ts
|
|
|
* @return boolean true 成功,false 失败
|
|
|
*/
|
|
|
- public function replace($key, $value, $ts = 0)
|
|
|
- {
|
|
|
+ public function replace($key, $value, $ts = 0) {
|
|
|
self::debug();
|
|
|
$ret = $this->redis->setex($key, $value, $ts);
|
|
|
if (strtolower($ret) == "ok") {
|
|
@@ -133,8 +125,7 @@ class CRedisUtil extends CMemBase
|
|
|
* @param type $key
|
|
|
* @return any
|
|
|
*/
|
|
|
- public function getWithoutJson($key)
|
|
|
- {
|
|
|
+ public function getWithoutJson($key) {
|
|
|
self::debug();
|
|
|
return $this->redis->get($key);
|
|
|
}
|
|
@@ -147,8 +138,7 @@ class CRedisUtil extends CMemBase
|
|
|
* @param int $ts
|
|
|
* @return boolean
|
|
|
*/
|
|
|
- public function setWithoutJson($key, $value, $ts = 0)
|
|
|
- {
|
|
|
+ public function setWithoutJson($key, $value, $ts = 0) {
|
|
|
self::debug();
|
|
|
$ret = $this->redis->set($key, $value, $ts);
|
|
|
if (strtolower($ret) == "ok") {
|
|
@@ -162,8 +152,7 @@ class CRedisUtil extends CMemBase
|
|
|
* 输出日志
|
|
|
* @param mixed $msg
|
|
|
*/
|
|
|
- private function logErr($msg)
|
|
|
- {
|
|
|
+ private function logErr($msg) {
|
|
|
CLog::err($msg, "Redis Err:");
|
|
|
}
|
|
|
|
|
@@ -174,8 +163,7 @@ class CRedisUtil extends CMemBase
|
|
|
* @param string $pwd
|
|
|
* @return \CRedisUtil
|
|
|
*/
|
|
|
- public function conn($host, $port, $pwd = "")
|
|
|
- {
|
|
|
+ public function conn($host, $port, $pwd = "") {
|
|
|
// DebugHelper::print_stack_trace();
|
|
|
$this->redis = new \Predis\Client(array(
|
|
|
'scheme' => 'tcp',
|
|
@@ -190,8 +178,7 @@ class CRedisUtil extends CMemBase
|
|
|
/**
|
|
|
* 关闭连接
|
|
|
*/
|
|
|
- public function close()
|
|
|
- {
|
|
|
+ public function close() {
|
|
|
$this->redis->quit();
|
|
|
}
|
|
|
|
|
@@ -200,8 +187,7 @@ class CRedisUtil extends CMemBase
|
|
|
* @param string $key
|
|
|
* @return any json_decode($result)
|
|
|
*/
|
|
|
- public function get($key)
|
|
|
- {
|
|
|
+ public function get($key) {
|
|
|
self::debug();
|
|
|
$result = $this->redis->get($key);
|
|
|
if (!$result || $result == "" || $result == null) {
|
|
@@ -218,8 +204,7 @@ class CRedisUtil extends CMemBase
|
|
|
* @param int $ts default(0) 过期时间(单位秒)
|
|
|
* @return boolean 成功true,失败false
|
|
|
*/
|
|
|
- public function set($key, $value, $ts = 0)
|
|
|
- {
|
|
|
+ public function set($key, $value, $ts = 0) {
|
|
|
self::debug();
|
|
|
if ($value === null || $value === "") { # 这里必须用全等符号
|
|
|
return false;
|
|
@@ -248,8 +233,7 @@ class CRedisUtil extends CMemBase
|
|
|
* @param any $value
|
|
|
* @return boolean 成功true,失败false
|
|
|
*/
|
|
|
- public function cas($key, $value, $ts = 0)
|
|
|
- {
|
|
|
+ public function cas($key, $value, $ts = 0) {
|
|
|
if (false) { # ps. 各云平台皆不支持eval方法执行lua脚本.等开放支持的时候才是真正支持cas的时候
|
|
|
$castoken = $this->keyDic->$key;
|
|
|
# # 定义一段脚本
|
|
@@ -277,8 +261,7 @@ casscript;
|
|
|
* @param string $keys
|
|
|
* @return int 删除键的个数
|
|
|
*/
|
|
|
- public function delete($key)
|
|
|
- {
|
|
|
+ public function delete($key) {
|
|
|
self::debug();
|
|
|
$infos = array();
|
|
|
array_push($infos, $key);
|
|
@@ -288,14 +271,14 @@ casscript;
|
|
|
// </editor-fold>
|
|
|
//
|
|
|
// <editor-fold defaultstate="collapsed" desc=" normal 普通对象操作 mget/mset">
|
|
|
+
|
|
|
/**
|
|
|
* 返回所有(一个或多个)给定 key 的值
|
|
|
* 如果给定的 key 里面,有某个 key 不存在,那么这个 key 返回特殊值 nil 。因此,该命令永不失败。
|
|
|
* @param array $keys
|
|
|
* @return array 一个包含所有给定 key 的值的列表
|
|
|
*/
|
|
|
- private function mget($keys)
|
|
|
- {
|
|
|
+ private function mget($keys) {
|
|
|
// self::debug();
|
|
|
$ret = array();
|
|
|
if (count($keys)) {
|
|
@@ -316,8 +299,7 @@ casscript;
|
|
|
* @param type $val
|
|
|
* @return boolean 成功true,失败false
|
|
|
*/
|
|
|
- private function setnx($key, $val)
|
|
|
- {
|
|
|
+ private function setnx($key, $val) {
|
|
|
self::debug();
|
|
|
$ret = $this->redis->setnx($key, $val);
|
|
|
// 成功返回1, 失败返回0
|
|
@@ -334,8 +316,7 @@ casscript;
|
|
|
* @param array $dict
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- private function mset($dict)
|
|
|
- {
|
|
|
+ private function mset($dict) {
|
|
|
self::debug();
|
|
|
return $this->redis->mset($dict);
|
|
|
}
|
|
@@ -347,8 +328,7 @@ casscript;
|
|
|
* @param array $dict
|
|
|
* @return int
|
|
|
*/
|
|
|
- public function msetnx($dict)
|
|
|
- {
|
|
|
+ public function msetnx($dict) {
|
|
|
self::debug();
|
|
|
$ret = $this->redis->msetnx($dict);
|
|
|
return $ret == 1;
|
|
@@ -359,8 +339,7 @@ casscript;
|
|
|
* @param type $key
|
|
|
* @return boolean true 存在, false 不存在
|
|
|
*/
|
|
|
- public function exists($key)
|
|
|
- {
|
|
|
+ public function exists($key) {
|
|
|
self::debug();
|
|
|
return $this->redis->exists($key) == 1;
|
|
|
}
|
|
@@ -373,8 +352,7 @@ casscript;
|
|
|
* @param type $key
|
|
|
* @return int 执行 INCR 命令之后 key 的值
|
|
|
*/
|
|
|
- public function increment($key)
|
|
|
- {
|
|
|
+ public function increment($key) {
|
|
|
self::debug();
|
|
|
return $this->redis->incr($key);
|
|
|
}
|
|
@@ -388,8 +366,7 @@ casscript;
|
|
|
* @param int $i 增加的值
|
|
|
* @return int 执行 INCR 命令之后 key 的值
|
|
|
*/
|
|
|
- public function incrby($key, $i)
|
|
|
- {
|
|
|
+ public function incrby($key, $i) {
|
|
|
self::debug();
|
|
|
return $this->redis->incrby($key, $i);
|
|
|
}
|
|
@@ -403,8 +380,7 @@ casscript;
|
|
|
* Server功能,看服务器是否连通
|
|
|
* @return boolean true连通正常
|
|
|
*/
|
|
|
- public function ping()
|
|
|
- {
|
|
|
+ public function ping() {
|
|
|
$ret = $this->redis->ping();
|
|
|
if ($ret == "PONG") {
|
|
|
return true;
|
|
@@ -418,8 +394,7 @@ casscript;
|
|
|
* @param array $values
|
|
|
* @return array
|
|
|
*/
|
|
|
- static private function json_encode_arr($values)
|
|
|
- {
|
|
|
+ static private function json_encode_arr($values) {
|
|
|
$arr = array();
|
|
|
if (is_array($values)) {
|
|
|
$arr = array_map(function($v) {
|
|
@@ -436,8 +411,7 @@ casscript;
|
|
|
* @param array $values
|
|
|
* @return array
|
|
|
*/
|
|
|
- static private function json_decode_arr(array $values)
|
|
|
- {
|
|
|
+ static private function json_decode_arr(array $values) {
|
|
|
$arr = array();
|
|
|
if (is_array($values)) {
|
|
|
$arr = array_map(function($v) {
|
|
@@ -457,24 +431,21 @@ casscript;
|
|
|
* 监视一个(或多个) key ,如果在事务执行之前这个(或这些) key 被其他命令所改动,那么事务将被打断。
|
|
|
* @param string $key
|
|
|
*/
|
|
|
- public function watch($key)
|
|
|
- {
|
|
|
+ public function watch($key) {
|
|
|
$this->redis->watch($key);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 取消监视
|
|
|
*/
|
|
|
- public function unwatch()
|
|
|
- {
|
|
|
+ public function unwatch() {
|
|
|
$this->redis->unwatch();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 开启事务
|
|
|
*/
|
|
|
- public function multi()
|
|
|
- {
|
|
|
+ public function multi() {
|
|
|
$this->redis->multi();
|
|
|
}
|
|
|
|
|
@@ -482,8 +453,7 @@ casscript;
|
|
|
* 执行事务
|
|
|
* @return type 事务块内所有命令的返回值,按命令执行的先后顺序排列。当操作被打断时,返回空值 nil 。
|
|
|
*/
|
|
|
- public function exec()
|
|
|
- {
|
|
|
+ public function exec() {
|
|
|
return $this->redis->exec();
|
|
|
}
|
|
|
|
|
@@ -501,8 +471,7 @@ casscript;
|
|
|
* @return int
|
|
|
* @expectedException type not set error
|
|
|
*/
|
|
|
- public function sadd($key, $members)
|
|
|
- {
|
|
|
+ public function sadd($key, $members) {
|
|
|
self::debug();
|
|
|
if (!is_array($members)) { # 防御: 参数不为数组
|
|
|
if (!is_string($members)) { # 防御: 参数不为字符串
|
|
@@ -521,8 +490,7 @@ casscript;
|
|
|
* @return int
|
|
|
* @expectedException type not set error
|
|
|
*/
|
|
|
- public function sremove($key, $members)
|
|
|
- {
|
|
|
+ public function sremove($key, $members) {
|
|
|
self::debug();
|
|
|
return $this->redis->srem($key, $members);
|
|
|
}
|
|
@@ -532,8 +500,7 @@ casscript;
|
|
|
* @param strig $key
|
|
|
* @return int
|
|
|
*/
|
|
|
- public function scard($key)
|
|
|
- {
|
|
|
+ public function scard($key) {
|
|
|
self::debug();
|
|
|
return $this->redis->scard($key);
|
|
|
}
|
|
@@ -544,8 +511,7 @@ casscript;
|
|
|
* @return int
|
|
|
*
|
|
|
*/
|
|
|
- public function slen($key)
|
|
|
- {
|
|
|
+ public function slen($key) {
|
|
|
self::debug();
|
|
|
return $this->scard($key);
|
|
|
}
|
|
@@ -556,8 +522,7 @@ casscript;
|
|
|
* @param string $member
|
|
|
* @return bool
|
|
|
*/
|
|
|
- public function sismember($key, $member)
|
|
|
- {
|
|
|
+ public function sismember($key, $member) {
|
|
|
self::debug();
|
|
|
return $this->redis->sismember($key, $member) == 1;
|
|
|
}
|
|
@@ -567,8 +532,7 @@ casscript;
|
|
|
* @param type $key
|
|
|
* @return array 不存在的key视为空集合
|
|
|
*/
|
|
|
- public function smembers($key)
|
|
|
- {
|
|
|
+ public function smembers($key) {
|
|
|
self::debug();
|
|
|
return $this->redis->smembers($key);
|
|
|
}
|
|
@@ -581,8 +545,7 @@ casscript;
|
|
|
* @param int $count =10
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function srandmember($key, $count = 10)
|
|
|
- {
|
|
|
+ public function srandmember($key, $count = 10) {
|
|
|
self::debug();
|
|
|
return $this->redis->srandmember($key, $count);
|
|
|
}
|
|
@@ -597,8 +560,7 @@ casscript;
|
|
|
* @param array $fields
|
|
|
* @return int 删除的字段的数量
|
|
|
*/
|
|
|
- public function hdel($key, $fields)
|
|
|
- {
|
|
|
+ public function hdel($key, $fields) {
|
|
|
self::debug();
|
|
|
return $this->redis->hdel($key, $fields);
|
|
|
}
|
|
@@ -609,8 +571,7 @@ casscript;
|
|
|
* @param string $field
|
|
|
* @return boolean true=存在,false 找不到
|
|
|
*/
|
|
|
- public function hexists($key, $field)
|
|
|
- {
|
|
|
+ public function hexists($key, $field) {
|
|
|
self::debug();
|
|
|
return $this->redis->hexists($key, $field) == 1;
|
|
|
}
|
|
@@ -621,8 +582,7 @@ casscript;
|
|
|
* @param string $field 字段名
|
|
|
* @return mixed json_decoded object
|
|
|
*/
|
|
|
- public function hget($key, $field)
|
|
|
- {
|
|
|
+ public function hget($key, $field) {
|
|
|
self::debug();
|
|
|
// echo $field, $key;
|
|
|
$ret = $this->redis->hget($key, $field);
|
|
@@ -635,8 +595,7 @@ casscript;
|
|
|
* @param string $key
|
|
|
* @return stdclass/associate_array (适用箭头取变量写法)
|
|
|
*/
|
|
|
- public function hgetall($key)
|
|
|
- {
|
|
|
+ public function hgetall($key) {
|
|
|
self::debug();
|
|
|
$ret = ArrayInit();
|
|
|
$arr = $this->redis->hgetall($key);
|
|
@@ -652,8 +611,7 @@ casscript;
|
|
|
* @param string $key
|
|
|
* @return int
|
|
|
*/
|
|
|
- public function hlen($key)
|
|
|
- {
|
|
|
+ public function hlen($key) {
|
|
|
self::debug();
|
|
|
return $this->redis->hlen($key);
|
|
|
}
|
|
@@ -664,8 +622,7 @@ casscript;
|
|
|
* @param array $fields
|
|
|
* @return Array
|
|
|
*/
|
|
|
- public function hmget($key, $fields)
|
|
|
- {
|
|
|
+ public function hmget($key, $fields) {
|
|
|
self::debug();
|
|
|
$ret = ArrayInit();
|
|
|
if (is_array($fields) && count($fields) > 0) {
|
|
@@ -684,8 +641,7 @@ casscript;
|
|
|
* @param assoc_array $dictionary
|
|
|
* @return boolean true成功
|
|
|
*/
|
|
|
- public function hmset($key, $dictionary)
|
|
|
- {
|
|
|
+ public function hmset($key, $dictionary) {
|
|
|
self::debug();
|
|
|
$newdic = ArrayInit();
|
|
|
foreach ($dictionary as $k => $v) {
|
|
@@ -705,8 +661,7 @@ casscript;
|
|
|
* @param $mixed $value
|
|
|
* @return int 0 覆盖旧值, 1 新建字段
|
|
|
*/
|
|
|
- public function hset($key, $field, $value)
|
|
|
- {
|
|
|
+ public function hset($key, $field, $value) {
|
|
|
self::debug();
|
|
|
return $this->redis->hset($key, $field, JsonUtil::encode($value));
|
|
|
}
|
|
@@ -718,8 +673,7 @@ casscript;
|
|
|
* @param string $value
|
|
|
* @return boolean true成功
|
|
|
*/
|
|
|
- public function hsetnx($key, $field, $value)
|
|
|
- {
|
|
|
+ public function hsetnx($key, $field, $value) {
|
|
|
self::debug();
|
|
|
return $this->redis->hsetnx($key, $field, JsonUtil::encode($value)) == 1;
|
|
|
}
|
|
@@ -731,8 +685,7 @@ casscript;
|
|
|
* @param int $increment
|
|
|
* @return int
|
|
|
*/
|
|
|
- public function hincrby($key, $field, $increment)
|
|
|
- {
|
|
|
+ public function hincrby($key, $field, $increment) {
|
|
|
self::debug();
|
|
|
return $this->redis->hincrby($key, $field, $increment);
|
|
|
}
|
|
@@ -744,8 +697,7 @@ casscript;
|
|
|
* @param string $increment float值用string
|
|
|
* @return string 用string存float值
|
|
|
*/
|
|
|
- public function hincrbyfloat($key, $field, $increment)
|
|
|
- {
|
|
|
+ public function hincrbyfloat($key, $field, $increment) {
|
|
|
self::debug();
|
|
|
return $this->redis->hincrbyfloat($key, $field, $increment);
|
|
|
}
|
|
@@ -754,8 +706,7 @@ casscript;
|
|
|
* @param string $key
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function hkeys($key)
|
|
|
- {
|
|
|
+ public function hkeys($key) {
|
|
|
self::debug();
|
|
|
return $this->redis->hkeys($key);
|
|
|
}
|
|
@@ -774,8 +725,7 @@ casscript;
|
|
|
* @param int $timeout
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function blpop(array $keys, $timeout)
|
|
|
- {
|
|
|
+ public function blpop(array $keys, $timeout) {
|
|
|
self::debug();
|
|
|
$arr = $this->redis->blpop($keys, $timeout);
|
|
|
$arr[1] = JsonUtil::decode($arr[1]); // 对value进行解包
|
|
@@ -786,8 +736,7 @@ casscript;
|
|
|
* 链表 - 阻塞队尾弹出, 当列表中没有元素的时候,命令会阻塞,直到等待超时或者有元素被添加到列表中.
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function brpop(array $keys, $timeout)
|
|
|
- {
|
|
|
+ public function brpop(array $keys, $timeout) {
|
|
|
self::debug();
|
|
|
$arr = $this->redis->brpop($keys, $timeout);
|
|
|
$arr[1] = JsonUtil::decode($arr[1]);
|
|
@@ -800,8 +749,7 @@ casscript;
|
|
|
* @return array 假如在指定时间内没有任何元素被弹出,则返回一个 nil 和等待时长。
|
|
|
* 反之,返回一个含有两个元素的列表,第一个元素是被弹出元素的值,第二个元素是等待时长。
|
|
|
*/
|
|
|
- public function brpoplpush($source, $destination, $timeout)
|
|
|
- {
|
|
|
+ public function brpoplpush($source, $destination, $timeout) {
|
|
|
self::debug();
|
|
|
$arr = $this->redis > brpoplpush($source, $destination, $timeout);
|
|
|
$arr[0] = JsonUtil::decode($arr[0]);
|
|
@@ -810,12 +758,12 @@ casscript;
|
|
|
|
|
|
// </editor-fold>
|
|
|
//
|
|
|
+
|
|
|
/**
|
|
|
* 链表 - 返回下标为index的元素
|
|
|
* @return string
|
|
|
*/
|
|
|
- public function lindex($key, $index)
|
|
|
- {
|
|
|
+ public function lindex($key, $index) {
|
|
|
self::debug();
|
|
|
$a = $this->redis->lindex($key, $index);
|
|
|
return JsonUtil::decode($a);
|
|
@@ -826,8 +774,7 @@ casscript;
|
|
|
* @return int
|
|
|
* @param type $key
|
|
|
*/
|
|
|
- public function llen($key)
|
|
|
- {
|
|
|
+ public function llen($key) {
|
|
|
self::debug();
|
|
|
return $this->redis->llen($key);
|
|
|
}
|
|
@@ -837,8 +784,7 @@ casscript;
|
|
|
* @return string
|
|
|
* @param type $key
|
|
|
*/
|
|
|
- public function lpop($key)
|
|
|
- {
|
|
|
+ public function lpop($key) {
|
|
|
self::debug();
|
|
|
$a = $this->redis->lpop($key);
|
|
|
return JsonUtil::decode($a);
|
|
@@ -850,8 +796,7 @@ casscript;
|
|
|
* @param type $key
|
|
|
* @param array $values
|
|
|
*/
|
|
|
- public function lpush($key, $values)
|
|
|
- {
|
|
|
+ public function lpush($key, $values) {
|
|
|
self::debug();
|
|
|
$arr = self::json_encode_arr($values);
|
|
|
return $this->redis->lpush($key, $arr);
|
|
@@ -864,8 +809,7 @@ casscript;
|
|
|
* @param int $start
|
|
|
* @param int $stop
|
|
|
*/
|
|
|
- public function lrange($key, $start, $stop)
|
|
|
- {
|
|
|
+ public function lrange($key, $start, $stop) {
|
|
|
self::debug();
|
|
|
$values = $this->redis->lrange($key, $start, $stop);
|
|
|
return self::json_decode_arr($values);
|
|
@@ -878,8 +822,7 @@ casscript;
|
|
|
* @param int $count
|
|
|
* @param string $value
|
|
|
*/
|
|
|
- public function lrem($key, $count, $value)
|
|
|
- {
|
|
|
+ public function lrem($key, $count, $value) {
|
|
|
self::debug();
|
|
|
return $this->redis->lrem($key, $count, JsonUtil::encode($value));
|
|
|
}
|
|
@@ -892,8 +835,7 @@ casscript;
|
|
|
* @param type $index
|
|
|
* @param type $value
|
|
|
*/
|
|
|
- public function lset($key, $index, $value)
|
|
|
- {
|
|
|
+ public function lset($key, $index, $value) {
|
|
|
self::debug();
|
|
|
return $this->redis->lset($key, $index, JsonUtil::encode($value));
|
|
|
}
|
|
@@ -905,8 +847,7 @@ casscript;
|
|
|
* @param int $start
|
|
|
* @param int $stop
|
|
|
*/
|
|
|
- public function ltrim($key, $start, $stop)
|
|
|
- {
|
|
|
+ public function ltrim($key, $start, $stop) {
|
|
|
self::debug();
|
|
|
// return mixed: ok or fails
|
|
|
$ret = $this->redis->ltrim($key, $start, $stop);
|
|
@@ -921,8 +862,7 @@ casscript;
|
|
|
* @param string $key
|
|
|
* @return string 列表的尾元素。当 key 不存在时,返回 nil
|
|
|
*/
|
|
|
- public function rpop($key)
|
|
|
- {
|
|
|
+ public function rpop($key) {
|
|
|
self::debug();
|
|
|
return JsonUtil::decode($this->redis->rpop($key));
|
|
|
}
|
|
@@ -933,8 +873,7 @@ casscript;
|
|
|
* @param array $values
|
|
|
* @return int
|
|
|
*/
|
|
|
- public function rpush($key, array $values)
|
|
|
- {
|
|
|
+ public function rpush($key, array $values) {
|
|
|
self::debug();
|
|
|
$arr = self::json_encode_arr($values);
|
|
|
return $this->redis->rpush($key, $arr);
|
|
@@ -995,8 +934,7 @@ casscript;
|
|
|
* @param array $membersAndScoresDictionary array( 'value'=>score,'value'=>score,...), score可以是int或float
|
|
|
* @return int 新增元素数量,不包含更新的元素
|
|
|
*/
|
|
|
- public function zadd($key, $membersAndScoresDictionary)
|
|
|
- {
|
|
|
+ public function zadd($key, $membersAndScoresDictionary) {
|
|
|
self::debug();
|
|
|
return $this->redis->zadd($key, $membersAndScoresDictionary);
|
|
|
}
|
|
@@ -1008,8 +946,7 @@ casscript;
|
|
|
* @param int $increment
|
|
|
* @return string
|
|
|
*/
|
|
|
- public function zincrby($key, $member, $increment = 1)
|
|
|
- {
|
|
|
+ public function zincrby($key, $member, $increment = 1) {
|
|
|
self::debug();
|
|
|
return $this->redis->zincrby($key, $increment, $member);
|
|
|
}
|
|
@@ -1019,8 +956,7 @@ casscript;
|
|
|
* @param string $key
|
|
|
* @return int
|
|
|
*/
|
|
|
- public function zlen($key)
|
|
|
- {
|
|
|
+ public function zlen($key) {
|
|
|
self::debug();
|
|
|
return $this->redis->zcard($key);
|
|
|
}
|
|
@@ -1032,8 +968,7 @@ casscript;
|
|
|
* @param int/float $max 最高分
|
|
|
* @return int
|
|
|
*/
|
|
|
- public function zcount($key, $min, $max)
|
|
|
- {
|
|
|
+ public function zcount($key, $min, $max) {
|
|
|
self::debug();
|
|
|
return $this->redis->zcount($key, $min, $max);
|
|
|
}
|
|
@@ -1046,8 +981,7 @@ casscript;
|
|
|
* @param boolean $withScore 返回值中是否带score字段
|
|
|
* @return array (index=>member) or assoc_array (member=>score)
|
|
|
*/
|
|
|
- public function zrange($key, $start, $stop, $withScore = false)
|
|
|
- {
|
|
|
+ public function zrange($key, $start, $stop, $withScore = false) {
|
|
|
self::debug();
|
|
|
if ($withScore) {
|
|
|
return $this->redis->zrange($key, $start, $stop, 'WITHSCORES');
|
|
@@ -1080,11 +1014,13 @@ casscript;
|
|
|
* @param boolean $withScore 返回值中是否带score字段 default(false)
|
|
|
* @return array (index=>member) or assoc_array (member=>score)
|
|
|
*/
|
|
|
- public function zrevrange($key, $start, $stop, $withScore = false)
|
|
|
- {
|
|
|
+ public function zrevrange($key, $start, $stop, $withScore = false) {
|
|
|
self::debug();
|
|
|
if ($withScore) {
|
|
|
- return $this->redis->zrevrange($key, $start, $stop, 'WITHSCORES');
|
|
|
+ echoLine("带分数取");
|
|
|
+ $r = $this->redis->zrevrange($key, $start, $stop, 'WITHSCORES');
|
|
|
+ var_dump($r);
|
|
|
+ return $r;
|
|
|
} else {
|
|
|
return $this->redis->zrevrange($key, $start, $stop);
|
|
|
}
|
|
@@ -1098,8 +1034,7 @@ casscript;
|
|
|
* @param boolean $withScore
|
|
|
* @return type
|
|
|
*/
|
|
|
- public function zrangebyscore($key, $min, $max, $withScore = false)
|
|
|
- {
|
|
|
+ public function zrangebyscore($key, $min, $max, $withScore = false) {
|
|
|
self::debug();
|
|
|
if ($withScore) {
|
|
|
return $this->redis->zrangebyscore($key, $min, $max, 'WITHSCORES');
|
|
@@ -1114,8 +1049,7 @@ casscript;
|
|
|
* @param string $member
|
|
|
* @return int
|
|
|
*/
|
|
|
- public function zrank($key, $member)
|
|
|
- {
|
|
|
+ public function zrank($key, $member) {
|
|
|
self::debug();
|
|
|
return $this->redis->zrank($key, $member);
|
|
|
}
|
|
@@ -1126,8 +1060,7 @@ casscript;
|
|
|
* @param string $member
|
|
|
* @return int
|
|
|
*/
|
|
|
- public function zrevrank($key, $member)
|
|
|
- {
|
|
|
+ public function zrevrank($key, $member) {
|
|
|
self::debug();
|
|
|
return $this->redis->zrevrank($key, $member);
|
|
|
}
|
|
@@ -1138,8 +1071,7 @@ casscript;
|
|
|
* @param string $member
|
|
|
* @return int/float
|
|
|
*/
|
|
|
- public function zscore($key, $member)
|
|
|
- {
|
|
|
+ public function zscore($key, $member) {
|
|
|
self::debug();
|
|
|
return $this->redis->zscore($key, $member);
|
|
|
}
|
|
@@ -1149,8 +1081,7 @@ casscript;
|
|
|
* @param string $key
|
|
|
* @param string $member
|
|
|
*/
|
|
|
- public function zrem($key, $member)
|
|
|
- {
|
|
|
+ public function zrem($key, $member) {
|
|
|
self::debug();
|
|
|
$this->redis->zrem($key, $member);
|
|
|
}
|
|
@@ -1161,8 +1092,7 @@ casscript;
|
|
|
* @param int $start
|
|
|
* @param int $stop
|
|
|
*/
|
|
|
- public function zremrangebyrank($key, $start, $stop)
|
|
|
- {
|
|
|
+ public function zremrangebyrank($key, $start, $stop) {
|
|
|
self::debug();
|
|
|
$this->redis->zremrangebyrank($key, $start, $stop);
|
|
|
}
|
|
@@ -1173,8 +1103,7 @@ casscript;
|
|
|
* @param int/float $min
|
|
|
* @param int/float $max
|
|
|
*/
|
|
|
- public function zremrangebyscore($key, $min, $max)
|
|
|
- {
|
|
|
+ public function zremrangebyscore($key, $min, $max) {
|
|
|
self::debug();
|
|
|
$this->redis->zremrangebyscore($key, $min, $max);
|
|
|
}
|