·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> PHPRedis

PHPRedis

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23
   1 <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 
   2 class Myredis
   3 {
   4     //redis所有已知命令:
   5     //append,auth,bgrewriteaof,bgsave,bitcount,bitop,blpop,brpop,brpoplpush,client-kill,client-list,client-getname, client-setname,config-get,config-set,config-resetstat,dbsize,debug-object,debug-segfault,decr,decrby,del,discard, dump,echo,eval,evalsha,exec,exists,expire,expireat,flushall,flushdb,get,getbit,getrange,getset,hdel,hexists,hget, hgetall,hincrby,hincrbyfloat,hkeys,hlen,hmget,hmset,hset,hsetnx,hvals,incr,incrby,incrbyfloat,info,keys,lastsave, lindex,linsert,llen,lpop,lpush,lpushx,lrange,lrem,lset,ltrim,mget,migrate,monitor,move,mset,msetnx,multi,object, persist,pexpire,pexpireat,pfadd,pfcount,pfmerge,ping,psetex,psubscribe,pttl,publish,punsubscribe,quit,randomkey,rename,renamenx,restore, rpop,rpoplpush,rpush,rpushx,sadd,save,scard,script-exists,script-flush,script-kill,script-load,sdiff,sdiffstore, select,set,setbit,setex,setnx,setrange,shutdown,sinter,sinterstore,sismember,slaveof,slowlog,smembers,smove,sort, spop,srandmember,srem,strlen,subscribe,sunion,sunionstore,sync,time,ttl,type,unsubscribe,unwatch,watch,zadd,zcard, zcount,zincrby,zinterstore,zrange,zrangebyscore,zrank,zrem,zremrangebyrank,zremrangebyscore,zrevrange, zrevrangebyscore,zrevrank,zscore,zunionstore,pubsub,config-rewrite,client-pause,hscan,scan,sscan,zscan
   6 
   7     PRivate static $redis;
   8 
   9     public function __construct($arConfig = array('host'=>'127.0.0.1', 'port'=> 6379))
  10     {
  11         $this->host    =    $arConfig['host'];
  12         $this->port    =    $arConfig['port'];
  13         self::$redis    =    new    Redis();
  14         self::$redis->connect($this->host, $this->port);
  15         return self::$redis;
  16     }
  17 
  18     public function __call($sMethod, $arParam)
  19     {
  20         return call_user_func_array(array(self::$redis, $sMethod), $arParam);
  21     }
  22 
  23     /******************* key *********************/
  24 
  25     /**
  26      * 查找所有符合给定模式 pattern 的 key 。
  27      * KEYS * 匹配数据库中所有 key 。
  28      * KEYS h?llo 匹配 hello , hallo 和 hxllo 等。
  29      * KEYS h*llo 匹配 hllo 和 heeeeello 等。
  30      * KEYS h[ae]llo 匹配 hello 和 hallo ,但不匹配 hillo 。
  31      * 特殊符号用 \ 隔开。
  32      * @author    zhaoyingnan    2015-10-16 17:33
  33      * @param    string        $sPattern    匹配模式
  34      * @return    array
  35      **/
  36     public function keys($sPattern = '*')
  37     {
  38         //echo $sPattern;
  39         return self::$redis->keys($sPattern);
  40     }
  41 
  42     /**
  43      * 返回key是否存在。
  44      * @author    zhaoyingnan    2015-10-16 17:40
  45      * @param    string        $sKey        要检测的 key
  46      * @return    bool
  47      **/
  48     public function exists($sKey)
  49     {
  50         if(!$sKey)return FALSE;
  51         return self::$redis->exists($sKey);
  52     }
  53 
  54     /**
  55      * 设置key的过期时间。如果key已过期,将会被自动删除。设置了过期时间的key被称之为volatile。
  56      * 在key过期之前可以重新更新他的过期时间,也可以使用PERSIST命令删除key的过期时间。
  57      * @author    zhaoyingnan    2015-10-16 17:46
  58      * @param    string        $sKey        key
  59      * @param    int            $iSecond    生存周期(秒)
  60      * @return    bool
  61      **/
  62     public function expire($sKey, $iSecond = 60)
  63     {
  64         if(!$sKey)return FALSE;
  65         return self::$redis->expire($sKey, $iSecond);
  66     }
  67 
  68     /**
  69      * 这个命令和 EXPIRE 命令的作用类似,但是它以毫秒为单位设置 key 的生存时间,而不像 EXPIRE 命令那样,以秒为单位。
  70      * @author    zhaoyingnan    2015-10-19 16:00
  71      * @param    string        $sKey        key
  72      * @param    int            $iSecond    生存周期(秒)
  73      * @return    bool
  74      **/
  75     public function pexpire($sKey, $iMilliseconds = 60000)
  76     {
  77         if(!$sKey)return FALSE;
  78         return self::$redis->pexpire($sKey, $iMilliseconds);
  79     }
  80 
  81     /**
  82      * EXPIREAT 的作用和 EXPIRE类似,都用于为 key 设置生存时间。不同在于 EXPIREAT 命令接受的时间参数是 UNIX 时间戳 Unix timestamp 。
  83      * @author    zhaoyingnan    2015-10-16 18:03
  84      * @param    string        $sKey        key
  85      * @param    int            $iUnixtimestamp    UNIX 时间戳(秒)
  86      * @return    bool
  87      **/
  88     public function expireat($sKey, $iUnixtimestamp)
  89     {
  90         if(!$sKey || !$iUnixtimestamp)return FALSE;
  91         return self::$redis->expireat($sKey, $iUnixtimestamp);
  92     }
  93 
  94     /**
  95      * PEXPIREAT 这个命令和 EXPIREAT命令类似,但它以毫秒为单位设置 key 的过期 unix 时间戳,而不是像 EXPIREAT 那样,以秒为单位。
  96      * EXPIREAT 的作用和 EXPIRE类似,都用于为 key 设置生存时间。不同在于 EXPIREAT 命令接受的时间参数是 UNIX 时间戳 Unix timestamp 。
  97      * @author    zhaoyingnan    2015-10-16 18:03
  98      * @param    string        $sKey        key
  99      * @param    int            $iMilliseconds    UNIX 时间戳(毫秒)
 100      * @return    bool
 101      **/
 102     public function pexpireat($sKey, $iMilliseconds)
 103     {
 104         if(!$sKey || !$iMilliseconds)return FALSE;
 105         return self::$redis->pexpireat($sKey, $iMilliseconds);
 106     }
 107 
 108     /**
 109      * 以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。
 110      * @author    zhaoyingnan    2015-10-16 17:52
 111      * @param    string        $sKey        key
 112      * @return    int            当 key 不存在时,返回 -2 。当 key 存在但没有设置剩余生存时间时,返回 -1 。否则,以秒为单位,返回 key 的剩余生存时间。
 113      **/
 114     public function ttl($sKey)
 115     {
 116         if(!$sKey)return -2;
 117         return self::$redis->ttl($sKey);
 118     }
 119 
 120     /**
 121      * 这个命令类似于 TTL 命令,但它以毫秒为单位返回 key 的剩余生存时间,而不是像 TTL 命令那样,以秒为单位。
 122      * @author    zhaoyingnan    2015-10-19 16:06
 123      * @param    string        $sKey        key
 124      * @return    int            当 key 不存在时,返回 -2 。当 key 存在但没有设置剩余生存时间时,返回 -1 。否则,以秒为单位,返回 key 的剩余生存时间。
 125      **/
 126     public function pttl($sKey)
 127     {
 128         if(!$sKey)return -2;
 129         return self::$redis->pttl($sKey);
 130     }
 131 
 132     /**
 133      * 将 key 原子性地从当前实例传送到目标实例的指定数据库上,一旦传送成功, key 保证会出现在目标实例上,而当前实例上的 key 会被删除。
 134      * 这个命令是一个原子操作,它在执行的时候会阻塞进行迁移的两个实例,直到以下任意结果发生:迁移成功,迁移失败,等到超时。
 135      * @author    zhaoyingnan    2015-10-16 18:24
 136      * @param    string        $sHost        目标 ip
 137      * @param    int            $iPort        端口
 138      * @param    string        $sKey        要操作的 key
 139      * @param    int            $iDb        目标实例的数据库的编号
 140      * @param    int            $iTimeout    timeout 参数以毫秒为格式,指定当前实例和目标实例进行沟通的最大间隔时间。这说明操作并不一定要在 timeout 毫秒内完成,只是说数据传送的时间不能超过这个 timeout 数。
 141      * @return    bool        注:当目标实例的指定的数据库中存在指定的 key 返回 FALS,当前实例中的 key 并没有被删除,也没有移动到目标实例上,目标实例上的 key 还是原来的
 142      **/
 143     public function migrate($sHost, $iPort, $sKey, $iDb, $iTimeout)
 144     {
 145         if(!$sHost || !$iPort || !$sKey || !$iDb || !$iTimeout)return FALSE;
 146         return self::$redis->migrate($sHost, $iPort, $sKey, $iDb, $iTimeout);
 147     }
 148 
 149     /**
 150      * 将当前数据库的 key 移动到给定的数据库 db 当中。
 151      * 如果当前数据库(源数据库)和给定数据库(目标数据库)有相同名字的给定 key ,或者 key 不存在于当前数据库,那么 MOVE 没有任何效果。
 152      * @author    zhaoyingnan    2015-10-19 15:42
 153      * @param    string        $sKey    key
 154      * @param    int            $iDb    移动到给定的数据库 id
 155      * @return    bool
 156      **/
 157     public function move($sKey, $iDb)
 158     {
 159         if(!$sKey || !$iDb)return FALSE;    
 160         return self::$redis->move($sKey, $iDb);
 161     }
 162 
 163     /**
 164      * 移除给定key的生存时间,将这个 key 从『易失的』(带生存时间 key )转换成『持久的』(一个不带生存时间、永不过期的 key )。
 165      * @author    zhaoyingnan    2015-10-19 15:55
 166      * @param    string        $sKey    key
 167      * @return    bool        当生存时间移除成功时,返回 1  如果 key 不存在或 key 没有设置生存时间,返回 0
 168      **/
 169     public function persist($sKey)
 170     {
 171         if(!$sKey)return FALSE;    
 172         return self::$redis->persist($sKey);
 173     }
 174 
 175     /**
 176      * 从当前数据库返回一个随机的key。
 177      * @author    zhaoyingnan    2015-10-19 16:08
 178      * @return    string        如果数据库没有任何key,返回nil,否则返回一个随机的key。    
 179      **/
 180     public function randomkey()
 181     {
 182         return self::$redis->randomkey();
 183     }
 184 
 185     /**
 186      * 将key重命名为newkey,如果key与newkey相同,将返回一个错误。如果newkey已经存在,则值将被覆盖。
 187      * @author    zhaoyingnan    2015-10-19 16:12
 188      * @param    string        $sKey    key
 189      * @param    string        $sNewKey    重命名后的 key 值    
 190      * @return    bool
 191      **/
 192     public function rename($sKey, $sNewKey)
 193     {
 194         if(!$sKey || !$sNewKey)return FALSE;    
 195         return self::$redis->rename($sKey, $sNewKey);
 196     }
 197 
 198     /**
 199      * 当且仅当 newkey 不存在时,将 key 改名为 newkey 。当 key 不存在时,返回一个错误。
 200      * @author    zhaoyingnan    2015-10-19 16:16
 201      * @param    string        $sKey    key
 202      * @param    string        $sNewKey    重命名后的 key 值    
 203      * @return    bool
 204      **/
 205     public function renamenx($sKey, $sNewKey)
 206     {
 207         if(!$sKey || !$sNewKey)return FALSE;    
 208         return self::$redis->renamenx($sKey, $sNewKey);
 209     }
 210 
 211     /**
 212      * 返回 key 所储存的值的类型。
 213      * @author    zhaoyingnan    2015-10-19 16:25
 214      * @param    string        $sKey    key
 215      * @return    string        none (key不存在) string (字符串) list (列表) set (集合) zset (有序集) hash (哈希表)
 216      **/
 217     public function type($sKey)
 218     {
 219         return self::$redis->type($sKey);
 220     }
 221 
 222     /******************* string *********************/
 223 
 224     /**
 225      * 将key和value对应。如果key已经存在了,它会被覆盖,而不管它是什么类型。
 226      * @author    zhaoyingnan    2015-10-19 16:35
 227      * @param    string        $sKey        key
 228      * @param    string        $sValue        key 对应的值
 229      * @return    bool
 230      **/
 231     public function set($sKey, $sValue)
 232     {
 233         if(!$sKey)return FALSE;
 234         return self::$redis->set($sKey, $sValue);
 235     }
 236 
 237     /**
 238      * 设置key对应字符串value,并且设置key在给定的 seconds 时间之后超时过期。
 239      * @author    zhaoyingnan    2015-11-03 11:25
 240      * @param    string        $sKey        被操作的 key
 241      * @param    int            $iSecond    生命周期(秒)
 242      * @param    string        $sValue        key 对应的 value
 243      * @return    bool
 244      **/
 245     public function setex($sKey, $iSecond, $sValue)
 246     {
 247         if(!$sKey || !$sValue)return FALSE;
 248         $iSecond = $iSecond ? abs((intval($iSecond))) : 30;
 249         return self::$redis->setex($sKey, $iSecond, $sValue);
 250     }
 251 
 252     /**
 253      * 设置key对应字符串value,并且设置key在给定的 milliseconds 时间之后超时过期。
 254      * @author    zhaoyingnan    2015-11-03 11:25
 255      * @param    string        $sKey        被操作的 key
 256      * @param    int            $iMillSecond    生命周期(毫秒)
 257      * @param    string        $sValue        key 对应的 value
 258      * @return    bool
 259      **/
 260     public function psetex($sKey, $iMilliseconds , $sValue)
 261     {
 262         if(!$sKey || !$sValue)return FALSE;
 263         $iMilliseconds = $iMilliseconds ? abs((intval($iMilliseconds))) : 30;
 264         return self::$redis->psetex($sKey, $iMilliseconds, $sValue);
 265     }
 266 
 267     /**
 268      * 自动将key对应到value并且返回原来key对应的value。如果key存在但是对应的value不是字符串,就返回错误。
 269      * @author    zhaoyingnan    2015-10-19 18:10
 270      * @param    string        $sKey        key
 271      * @param    string        $sValue        设置的新的值
 272      * @return    string
 273      **/
 274     public function getset($sKey, $sValue)
 275     {
 276         if(!$sKey)return '';
 277         return self::$redis->getset($sKey, $sValue);
 278     }
 279 
 280     /**
 281      * 对应给定的keys到他们相应的values上。MSET会用新的value替换已经存在的value,就像普通的SET命令一样。
 282      * 如果你不想覆盖已经存在的values,请参看命令MSETNX。
 283      * MSET是原子的,所以所有给定的keys是一次性set的。客户端不可能看到这种一部分keys被更新而另外的没有改变的情况。
 284      * @author    zhaoyingnan    2015-11-03 11:04
 285      * @param    array        $arArray    被设置的关联数组
 286      * @return    bool
 287      **/
 288     public function mset($arArray = array())
 289     {
 290         if(!$arArray)return FALSE;
 291         return self::$redis->mset($arArray);
 292     }
 293 
 294     /**
 295      * 对应给定的keys到他们相应的values上。
 296      * 只要有一个key已经存在,MSETNX一个操作都不会执行。 
 297      * 由于这种特性,MSETNX可以实现要么所有的操作都成功,要么一个都不执行,这样可以用来设置不同的key,来表示一个唯一的对象的不同字段。
 298      * MSETNX是原子的,所以所有给定的keys是一次性set的。客户端不可能看到这种一部分keys被更新而另外的没有改变的情况。
 299      * @author    zhaoyingnan    2015-11-03 11:11
 300      * @param    array        $arArray    被设置的关联数组
 301      * @return    bool        TRUE 所有的key被set, FALSE 没有key被set(至少其中有一个key是存在的)
 302      **/
 303     public function    msetnx($arArray = array())
 304     {
 305         if(!$arArray)return FALSE;
 306         return self::$redis->msetnx($arArray);
 307     }
 308 
 309     /**
 310      * 如果key不存在,就设置key对应字符串value。
 311      * 在这种情况下,该命令和SET一样。当key已经存在时,就不做任何操作。
 312      * SETNX是"SET if Not eXists"。
 313      * @author    zhaoyingnan    2015-11-03 11:49
 314      * @param    string        $sKey        key
 315      * @param    string        $sValue        值
 316      * @return    bool        TRUE key被set, FALSE key没有被set
 317      **/
 318     public function setnx($sKey, $sValue)
 319     {
 320         if(!$sKey)return FALSE;
 321         return self::$redis->setnx($sKey, $sValue);
 322     }
 323 
 324     /**
 325      * 返回key的value。如果key不存在,返回特殊值nil。如果key的value不是string,就返回错误,因为GET只处理string类型的values。
 326      * @author    zhaoyingnan    2015-10-19 17:57
 327      * @param    string        $sKey        key
 328      * @return    string
 329      **/
 330     public function get($sKey)
 331     {
 332         if(!$sKey)return '';
 333         return self::$redis->get($sKey);
 334     }
 335 
 336     /**
 337      * 返回所有指定的key的value。对于每个不对应string或者不存在的key,都返回特殊值nil。正因为此,这个操作从来不会失败。
 338      * @author    zhaoyingnan    2015-11-03 10:55
 339      * @param    array        $arKey        要获取的 key 的数组
 340      * @return    array        redis返回的是以数字为索引的数组,这里返回的是一个关联数组
 341      **/
 342     public function mget($arKey = array())
 343     {
 344         if(!$arKey)return array();
 345         $arResult = self::$redis->mget($arKey);
 346         return array_combine($arKey, $arResult);
 347     }
 348 
 349     /**
 350      * 如果 key 已经存在,并且值为字符串,那么这个命令会把 value 追加到原来值(value)的结尾。
 351      * 如果 key 不存在,那么它将首先创建一个空字符串的key,再执行追加操作,这种情况 APPEND 将类似于 SET 操作。
 352      * @author    zhaoyingnan    2015-10-19 16:34
 353      * @param    string        $sKey        key
 354      * @param    string        $sValue        追加的值
 355      * @return    int
 356      **/
 357     public function append($sKey, $sValue)
 358     {
 359         if(!$sKey)return FALSE;
 360         return self::$redis->append($sKey, $sValue);
 361     }
 362 
 363     /**
 364      * 对key对应的数字做加1操作。如果key不存在,那么在操作之前,这个key对应的值会被置为0。
 365      * 如果key有一个错误类型的value或者是一个不能表示成数字的字符串,就返回错误。
 366      * 这个操作最大支持在64位有符号的整型数字。
 367      * @author    zhaoyingnan    2015-10-19 17:44
 368      * @param    string        $sKey        key
 369      * @return    string
 370      **/
 371     public function incr($sKey)
 372     {
 373         if(!$sKey)return '';
 374         return self::$redis->incr($sKey);
 375     }
 376 
 377     /**
 378      * 将key对应的数字加decrement。如果key不存在,操作之前,key就会被置为0。
 379      * 如果key的value类型错误或者是个不能表示成数字的字符串,就返回错误。这个操作最多支持64位有符号的正型数字。
 380      * @author    zhaoyingnan    2015-10-19 17:44
 381      * @param    string        $sKey        key
 382      * @param    int            $iIncrement    步进值
 383      * @return    string
 384      **/
 385     public function incrby($sKey, $iIncrement)
 386     {
 387         if(!$sKey || !$iIncrement)return '';
 388         return self::$redis->incrby($sKey, $iIncrement);
 389     }
 390 
 391     /**
 392      * 将key对应的数字加decrement。如果key不存在,操作之前,key就会被置为0。
 393      * 如果key的value类型错误或者是个不能表示成数字的字符串,就返回错误。这个操作最多支持64位有符号的正型数字。
 394      * @author    zhaoyingnan    2015-10-19 17:44
 395      * @param    string        $sKey        key
 396      * @param    fload        $floatIncrement    步进值
 397      * @return    string
 398      **/
 399     public function incrbyfloat($sKey, $floatIncrement)
 400     {
 401         if(!$sKey || !$floatIncrement)return '';
 402         return self::$redis->incrbyfloat($sKey, $floatIncrement);
 403     }
 404 
 405     /**
 406      * 对key对应的数字做减1操作。如果key不存在,那么在操作之前,这个key对应的值会被置为0。
 407      * 如果key有一个错误类型的value或者是一个不能表示成数字的字符串,就返回错误。这个操作最大支持在64位有符号的整型数字。
 408      * @author    zhaoyingnan    2015-10-19 17:44
 409      * @param    string        $sKey        key
 410      * @return    string
 411      **/
 412     public function decr($sKey)
 413     {
 414         if(!$sKey)return '';
 415         return self::$redis->decr($sKey);
 416     }
 417 
 418     /**
 419      * 将key对应的数字减decrement。如果key不存在,操作之前,key就会被置为0。
 420      * 如果key的value类型错误或者是个不能表示成数字的字符串,就返回错误。这个操作最多支持64位有符号的正型数字。
 421      * @author    zhaoyingnan    2015-10-19 17:44
 422      * @param    string        $sKey        key
 423      * @param    int            $iIncrement    步进值
 424      * @return    string
 425      **/
 426     public function decrby($sKey, $iIncrement)
 427     {
 428         if(!$sKey || !$iIncrement)return '';
 429         return self::$redis->decrby($sKey, $iIncrement);
 430     }
 431 
 432     /**
 433      * 这个命令是被改成GETRANGE的,在小于2.0的Redis版本中叫SUBSTR。 
 434      * 返回key对应的字符串value的子串,这个子串是由start和end位移决定的(两者都在string内)。
 435      * 可以用负的位移来表示从string尾部开始数的下标。所以-1就是最后一个字符,-2就是倒数第二个,以此类推。
 436      * 这个函数处理超出范围的请求时,都把结果限制在string内。
 437      * @author    zhaoyingnan    2015-10-19 18:04
 438      * @param    string        $sKey        key
 439      * @pause    int            $iStart        开始位置
 440      * @pause    int            $iEnd        结束位置
 441      * @return    string
 442      **/
 443     public function getrange($sKey, $iStart = 0, $iEnd = -1)
 444     {
 445         if(!$sKey)return '';
 446         return self::$redis->getrange($sKey, $iStart, $iEnd);
 447     }
 448 
 449     /**
 450      * 返回key的string类型value的长度。如果key对应的非string类型,就返回错误。
 451      * @author    zhaoyingnan    2015-11-03 11:40
 452      * @param    string        $sKey
 453      * @return    
 454      **/
 455     public function strlen($sKey)
 456     {
 457         if(!$sKey)return FALSE;
 458         return self::$redis->strlen($sKey);
 459     }
 460 
 461     /******************* list *********************/
 462 
 463     /**
 464      * 将所有指定的值插入到存于 key 的列表的头部。如果 key 不存在,那么在进行 push 操作前会创建一个空列表。 
 465      * 如果 key 对应的值不是一个 list 的话,那么会返回一个错误。
 466      * 可以使用一个命令把多个元素 push 进入列表,只需在命令末尾加上多个指定的参数。
 467      * 元素是从最左端的到最右端的、一个接一个被插入到 list 的头部。 所以对于这个命令例子 LPUSH mylist a b c,返回的列表是 c 为第一个元素, b 为第二个元素, a 为第三个元素。
 468      * @author    zhaoyingnan    2015-11-03 11:59
 469      * @param    string        $sKey
 470      * @param    array        $arValue    需要 push 到 key 中的值的数组
 471      * @return    int            在 push 操作后的 list 长度。
 472      **/
 473     public function lpush($sKey, $arValue = array())
 474     {
 475         if(!$sKey || !$arValue)return 0;
 476         foreach($arValue as $val)
 477             self::$redis->lpush($sKey, $val);
 478         return self::llen($sKey);
 479     }
 480 
 481     /**
 482      * 只有当 key 已经存在并且存着一个 list 的时候,在这个 key 下面的 list 的头部插入 value。 
 483      * 与 LPUSH 相反,当 key 不存在的时候不会进行任何操作。
 484      * @author    zhaoyingnan    2015-11-03 13:21
 485      * @param    string        $sKey
 486      * @param    array        $arValue    需要 push 到 key 中的值的数组
 487      * @return    int
 488      **/
 489     public function lpushx($sKey, $arValue = array())
 490     {
 491         if(!$sKey || !$arValue)return 0;
 492         foreach($arValue as $val)
 493             self::$redis->lpushx($sKey, $val);
 494         return self::llen($sKey);
 495     }
 496 
 497     /**
 498      * 向存于 key 的列表的尾部插入所有指定的值。如果 key 不存在,那么会创建一个空的列表然后再进行 push 操作。 
 499      * 当 key 保存的不是一个列表,那么会返回一个错误。
 500      * 可以使用一个命令把多个元素打入队列,只需要在命令后面指定多个参数。
 501      * 元素是从左到右一个接一个从列表尾部插入。 比如命令 RPUSH mylist a b c 会返回一个列表,其第一个元素是 a ,第二个元素是 b ,第三个元素是 c。
 502      * @author    zhaoyingnan    2015-11-03 12:15
 503      * @param    string        $sKey
 504      * @param    array        $arValue    需要 push 到 key 中的值的数组
 505      * @return    int            在 push 操作后的 list 长度。
 506      **/
 507     public function rpush($sKey, $arValue = array())
 508     {
 509         if(!$sKey || !$arValue)return 0;
 510         foreach($arValue as $val)
 511             self::$redis->lpush($sKey, $val);
 512         return self::llen($sKey);
 513     }
 514 
 515     /**
 516      * 将值 value 插入到列表 key 的表尾, 当且仅当 key 存在并且是一个列表。 
 517      * 和 RPUSH 命令相反, 当 key 不存在时,RPUSHX 命令什么也不做。
 518      * @author    zhaoyingnan    2015-11-03 13:23
 519      * @param    string        $sKey
 520      * @param    array        $arValue    需要 push 到 key 中的值的数组
 521      * @return    int            在 push 操作后的 list 长度。
 522      **/
 523     public function rpushx($sKey, $arValue = array())
 524     {
 525         if(!$sKey || !$arValue)return 0;
 526         foreach($arValue as $val)
 527             self::$redis->rpushx($sKey, $val);
 528         return self::llen($sKey);
 529     }
 530 
 531     /**
 532      * 返回存储在 key 里的list的长度。 
 533      * @author    zhaoyingnan    2015-11-03 12:12
 534      * @param    string        $sKey
 535      * @return    bool        如果 key 不存在,那么就被看作是空list,并且返回长度为 0。 当存储在 key 里的值不是一个list的话,会返回error。
 536      **/
 537     public function llen($sKey)
 538     {
 539         if(!$sKey)return 0;
 540         return self::$redis->llen($sKey);
 541     }
 542 
 543     /**
 544      * 返回 key 对应的列表里的元素的索引 index 的值
 545      * 下标是从0开始索引的,所以 0 是表示第一个元素, 1 表示第二个元素,并以此类推。 
 546      * 负数索引用于指定从列表尾部开始索引的元素。在这种方法下,-1 表示最后一个元素,-2 表示倒数第二个元素,并以此往前推。
 547      * 当 key 位置的值不是一个列表的时候,会返回一个error。
 548      * @author    zhaoyingnan    2015-11-03 13:30
 549      * @param    string        $sKey
 550      * @param    array        $index        key 对应的列表中的 index 索引
 551      * @return    mix
 552      **/
 553     public function lindex($sKey, $index = 0)
 554     {
 555         if(!$sKey)return FALSE;
 556         return self::$redis->lindex($sKey, intval($index));
 557     }
 558 
 559     /**
 560      * 设置 index 位置的list元素的值为 value。
 561      * 下标是从0开始索引的,所以 0 是表示第一个元素, 1 表示第二个元素,并以此类推。 
 562      * 当index超出范围时会返回一个error。
 563      * @author    zhaoyingnan    2015-11-03 14:27
 564      * @param    string        $sKey
 565      * @param    int            $index        key 对应的 list 中小标为 index
 566      * @param    string        $sValue        被设置的值
 567      * @return    
 568      **/
 569     public function lset($sKey, $index, $sValue)
 570     {
 571         if(!$sKey || !$sValue)return FALSE;
 572         return self::$redis->lset($sKey, $index, $sValue);
 573     }
 574 
 575     /**
 576      * 把 value 插入存于 key 的列表中在基准值 pivot 的前面或后面。
 577      * 当 key 不存在时,这个list会被看作是空list,任何操作都不会发生。
 578      * 当 key 存在,但保存的不是一个list的时候,会返回error。
 579      * @author    zhaoyingnan    2015-11-03 13:42
 580      * @param    string        $sKey
 581      * @param    string        $sPosion    在基准值前面或者后面(BEFORE or AFTER)
 582      * @param    string        $pivot        列表中的基准值
 583      * @param    string        $sValue        被插入的值
 584      * @return    mix            经过插入操作后的list长度,或者当 pivot 值找不到的时候返回 -1。
 585      **/
 586     public function linsert($sKey, $sPosion, $pivot, $sValue)
 587     {
 588         if(!$sKey || !$pivot || !$sValue)return FALSE;
 589         $sPosion = in_array($sPosion, array('BEFORE', 'AFTER')) ? strtoupper($sPosion) : 'BEFORE';
 590         return self::$redis->linsert($sKey, $sPosion, $pivot, $sValue);
 591     }
 592 
 593     /**
 594      * 从存于 key 的列表里移除前 count 次出现的值为 value 的元素。 这个 count 参数通过下面几种方式影响这个操作:
 595      * count > 0: 从头往尾移除值为 value 的元素。
 596      * count < 0: 从尾往头移除值为 value 的元素。
 597      * count = 0: 移除所有值为 value 的元素。
 598      * 比如, LREM list -2 "hello" 会从存于 list 的列表里移除最后两个出现的 "hello"。
 599      * 需要注意的是,如果list里没有存在key就会被当作空list处理,所以当 key 不存在的时候,这个命令会返回 0。
 600      * @author    zhaoyingnan    2015-11-03 13:53
 601      * @param    string        $sKey
 602      * @param    int            $iCount        count > 0: 从头往尾移除值为 value 的元素。 count < 0: 从尾往头移除值为 value 的元素。 count = 0: 移除所有值为 value 的元素。
 603      * @param    string        $sValue        要删除的值
 604      * @return    int
 605      **/
 606     //public function lremu($sKey, $iCount, $sValue)
 607     //{
 608     //    var_dump($sValue);
 609     //    if(!$sKey || !$sValue)return FALSE;
 610     //    return self::$redis->lrem($sKey, intval($iCount), $sValue);
 611     //}
 612 
 613     /**
 614      * 修剪(trim)一个已存在的 list,这样 list 就会只包含指定范围的指定元素。
 615      * start 和 stop 都是由0开始计数的, 这里的 0 是列表里的第一个元素(表头),1 是第二个元素,以此类推。
 616      * @author    zhaoyingnan    2015-11-03 14:45
 617      * @param    string        $sKey
 618      * @param    int            $iStart        指定范围内的开始位置
 619      * @param    int            $iEnd        制定范围内的结束位置
 620      * @return    bool
 621      **/
 622     public function ltrim($sKey, $iStart, $iEnd)
 623     {
 624         if(!$sKey)return FALSE;
 625         return self::$redis->ltrim($sKey, intval($iStart), intval($iEnd));
 626     }
 627 
 628     /**
 629      * 返回存储在 key 的列表里指定范围内的元素。
 630      * start 和 end 偏移量都是基于0的下标,即list的第一个元素下标是0(list的表头),第二个元素下标是1,以此类推。
 631      * 偏移量也可以是负数,表示偏移量是从list尾部开始计数。 例如, -1 表示列表的最后一个元素,-2 是倒数第二个,以此类推。
 632      * @author    zhaoyingnan    2015-11-03 14:54
 633      * @param    string        $sKey
 634      * @param    int            $iStart        开始位置
 635      * @param    int            $iEnd        结束位置
 636      * @return    array
 637      **/
 638     public function lrange($sKey, $iStart, $iEnd)
 639     {
 640         if(!$sKey)return FALSE;
 641         return self::$redis->lrange($sKey, intval($iStart), intval($iEnd));
 642     }
 643 
 644     /**
 645      * 移除并且返回 key 对应的 list 的第一个元素。
 646      * @author    zhaoyingnan    2015-11-03 21:49
 647      * @param    string        $sKey
 648      * @return    bool
 649      **/
 650     public function lpop($sKey)
 651     {
 652         if(!$sKey)return FALSE;
 653         return self::$redis->lpop($sKey);
 654     }
 655 
 656     /**
 657      * 移除并返回存于 key 的 list 的最后一个元素。
 658      * @author    zhaoyingnan    2015-11-03 21:49
 659      * @param    string        $sKey
 660      * @return    bool
 661      **/
 662     public function rpop($sKey)
 663     {
 664         if(!$sKey)return FALSE;
 665         return self::$redis->rpop($sKey);
 666     }
 667 
 668     /******************* set *********************/
 669 
 670     /**
 671      * 添加一个或多个指定的member元素到集合的 key中.
 672      * 指定的一个或者多个元素member 如果已经在集合key中存在则忽略.
 673      * 如果集合key 不存在,则新建集合key,并添加member元素到集合key中.
 674      * 如果key 的类型不是集合则返回错误.
 675      * @author    zhaoyingnan    2015-11-03 21:55
 676      * @param    string        $sKey
 677      * @param    array        $arMember    被添加的元素的数组
 678      * @return    int            返回新成功添加到集合里元素的数量,不包括已经存在于集合中的元素.
 679      **/
 680     public function sadd($sKey, $arMember = array())
 681     {
 682         if(!$sKey)return FALSE;
 683         $iCount = 0;
 684         foreach($arMember as $val)
 685         {
 686             if(self::$redis->sadd($sKey, $val))
 687                 $iCount++;
 688         }
 689         return $iCount;
 690     }
 691 
 692     /**
 693      * 返回集合存储的key的基数 (集合元素的数量).
 694      * @author    zhaoyingnan    2015-11-03 22:09
 695      * @param    string        $sKey
 696      * @return    int
 697      **/
 698     public function scard($sKey)
 699     {
 700         if(!$sKey)return 0;
 701         return self::$redis->scard($sKey);
 702     }
 703 
 704     /**
 705      * 返回一个集合与给定集合的差集的元素.
 706      * @author    zhaoyingnan    2015-11-03 22:13
 707      * @param    array        $arKey
 708      * @return    array
 709      **/
 710     public function sdiff($arKey)
 711     {
 712         if(!$arKey)return array();
 713         return self::$redis->sdiff($arKey);
 714     }
 715 
 716     /**
 717      * 该命令类似于 SDIFF, 不同之处在于该命令不返回结果集,而是将结果存放在destination集合中.
 718      * 如果destination 已经存在, 则将其覆盖重写.
 719      * @author    zhaoyingnan    2015-11-04 10:16
 720      * @param    string        $sNewKey
 721      * @param    array        $arKey
 722      * @return    int            结果集元素的个数.
 723      **/
 724     public function sdiffstore($sNewKey, $arKey)
 725     {
 726         if(!$arKey || !$sNewKey)return 0;
 727         if($arResult = self::$redis->sdiff($arKey))
 728             return $this->sadd($sNewKey, $arResult);
 729         return 0;
 730     }
 731 
 732     /**
 733      * 返回指定所有的集合的成员的交集.
 734      * @author    zhaoyingnan    2015-11-04 10:18
 735      * @param    array        $arKey
 736      * @return    array
 737      **/
 738     public function sinter($arKey)
 739     {
 740         if(!$arKey)return array();
 741         return self::$redis->sinter($arKey);
 742     }
 743 
 744     /**
 745      * 这个命令与SINTER命令类似, 但是它并不是直接返回结果集,而是将结果保存在 destination集合中.
 746      * 如果destination 集合存在, 则会被重写.
 747      * @author    zhaoyingnan    2015-11-04 10:23
 748      * @param    string        $sNewKey
 749      * @param    array        $arKey
 750      * @return    int            结果集元素的个数.
 751      **/
 752     public function sinterstore($sNewKey, $arKey)
 753     {
 754         if(!$arKey || !$sNewKey)return 0;
 755         if($arResult = self::$redis->sinter($arKey))
 756             return $this->sadd($sNewKey, $arResult);
 757         return 0;
 758     }
 759 
 760     /**
 761      * 返回成员 member 是否是存储的集合 key的成员.
 762      * @author    zhaoyingnan    2015-11-04 10:25
 763      * @param    string        $sKey
 764      * @param    string        $member
 765      * @return    int            如果member元素是集合key的成员,则返回1,如果member元素不是key的成员,或者集合key不存在,则返回0
 766      **/
 767     public function sismember($sKey, $member)
 768     {
 769         if(!$sKey || !$member)return FALSE;
 770         return self::$redis->sismember($sKey, $member);
 771     }
 772 
 773     /**
 774      * 返回key集合所有的元素.
 775      * @author    zhaoyingnan    2015-11-04 10:29
 776      * @param    string        $sKey
 777      * @return    array
 778      **/
 779     public function smembers($sKey)
 780     {
 781         if(!$sKey)return array();
 782         return self::$redis->smembers($sKey);
 783     }
 784 
 785     /**
 786      * 将member从source集合移动到destination集合中.
 787      * 如果source 集合不存在或者不包含指定的元素,smove命令不执行任何操作并且返回0.
 788      * 否则对象将会从source集合中移除,并添加到destination集合中去,
 789      * 如果destination集合已经存在该元素,则smove命令仅将该元素充source集合中移除.
 790      * 如果source 和destination不是集合类型,则返回错误.
 791      * @author    zhaoyingnan    2015-11-04 10:33
 792      * @param    string        $sFromKey
 793      * @param    string        $sToKsy
 794      * @param    string        $member
 795      * @return    bool
 796      **/
 797     public function smove($sFromKey, $sToKsy, $member)
 798     {
 799         if(!$sFromKey || !$sToKsy || !$member)return FALSE;
 800         return self::$redis->smove($sFromKey, $sToKsy, $member);
 801     }
 802 
 803     /**
 804      * 移除并返回一个集合中的随机元素
 805      * 该命令与 SRANDMEMBER相似,不同的是srandmember命令返回一个随机元素但是不移除.
 806      * @author    zhaoyingnan    2015-11-04 10:42
 807      * @param    string        $sKey
 808      * @return    mix
 809      **/
 810     public function spop($sKey)
 811     {
 812         if(!$sKey)return FALSE;
 813         return self::$redis->spop($sKey);
 814     }
 815 
 816     /**
 817      * 仅提供key参数,那么随机返回key集合中的一个元素.
 818      * 仅提供key参数时,该命令作用类似于SPOP命令, 不同的是SPOP命令会将被选择的随机元素从集合中移除, 而SRANDMEMBER仅仅是返回该随记元素,而不做任何操作.
 819      * Redis 2.6开始, 可以接受 count 参数,
 820      * 如果count是整数且小于元素的个数,返回含有 count 个不同的元素的数组,
 821      * 如果count是个整数且大于集合中元素的个数时,仅返回整个集合的所有元素,
 822      * 当count是负数,则会返回一个包含count的绝对值的个数元素的数组,
 823      * 如果count的绝对值大于元素的个数,则返回的结果集里会出现一个元素出现多次的情况.
 824      * @author    zhaoyingnan    2015-11-04 10:46
 825      * @param    string        $sKey
 826      * @param    int            $iCount
 827      * @return    mix
 828      **/
 829     public function srandmember($sKey, $iCount = 1)
 830     {
 831         if(!$sKey)return FALSE;
 832         return self::$redis->srandmember($sKey, $iCount);
 833     }
 834 
 835     /**
 836      * 在key集合中移除指定的元素. 
 837      * 如果指定的元素不是key集合中的元素则忽略 如果key集合不存在则被视为一个空的集合,该命令返回0.
 838      * 如果key的类型不是一个集合,则返回错误.
 839      * @author    zhaoyingnan    2015-11-04 10:53
 840      * @param    string        $sKey
 841      * @param    array        $member
 842      * @return    mix
 843      **/
 844     public function srem($sKey, $member = array())
 845     {
 846         if(!$sKey || !$member)return FALSE;
 847         $iCount = 0;
 848         foreach($member as $val)
 849         {
 850             if(self::$redis->srem($sKey, $val))
 851                 $iCount++;
 852         }
 853         return $iCount;
 854     }
 855 
 856     /**
 857      * 返回给定的多个集合的并集中的所有成员.
 858      * @author    zhaoyingnan    2015-11-04 10:59
 859      * @param    array        $arKey
 860      * @return    array
 861      **/
 862     public function sunion($arKey)
 863     {
 864         if(!$arKey)return array();
 865         return self::$redis->sunion($arKey);
 866     }
 867 
 868     /**
 869      * 该命令作用类似于SUNION命令,不同的是它并不返回结果集,而是将结果存储在destination集合中.
 870      * 如果destination 已经存在,则将其覆盖.
 871      * @author    zhaoyingnan    2015-11-04 11:05
 872      * @param    string        $sNewKey    新的key
 873      * @param    array        $arKey        多个 key 的数组
 874      * @return    int            结果集中元素的个数.
 875      **/
 876     public function sunionstore($sNewKey, $arKey)
 877     {
 878         if(!$arKey || !$sNewKey)return 0;
 879         if($arResult = self::$redis->sunion($arKey))
 880         {
 881             return $this->sadd($sNewKey, $arResult);
 882         }
 883         return 0;
 884     }
 885 
 886     /******************* set *********************/
 887 
 888     /**
 889      * 命令添加指定的成员到key对应的有序集合中,每个成员都有一个分数。你可以指定多个分数/成员组合。
 890      * 如果一个指定的成员已经在对应的有序集合中了,那么其分数就会被更新成最新的,并且该成员会重新调整到正确的位置,以确保集合有序。
 891      * 如果key不存在,就会创建一个含有这些成员的有序集合,就好像往一个空的集合中添加一样。
 892      * 如果key存在,但是它并不是一个有序集合,那么就返回一个错误。
 893      * 分数的值必须是一个表示数字的字符串,并且可以是double类型的浮点数。
 894      * @author    zhaoyingnan    2015-11-04 13:45
 895      * @param    string        $sKey
 896      * @param    array        $arMember    array(array('score1', 'member1'), array('score2', 'member2'),.....)
 897      * @return    mix
 898      **/
 899     public function zadd($sKey, $arMember)
 900     {
 901         if(!$sKey || !$arMember || !is_array($arMember))return 0;
 902         $iCount = 0;
 903         foreach($arMember as $arVal)
 904         {
 905             if(self::$redis->zadd($sKey, $arVal[0], $arVal[1]))
 906                 $iCount++;
 907         }
 908         return $iCount;
 909     }
 910 
 911     /**
 912      * 返回key的有序集元素个数
 913      * @author    zhaoyingnan    2015-11-04 13:48
 914      * @param    string        $sKey
 915      * @return    int
 916      **/
 917     public function zcard($sKey)
 918     {
 919         if(!$sKey)return 0;
 920         return self::$redis->zcard($sKey);
 921     }
 922 
 923     /**
 924      * 返回有序集key中,score值在min和max之间(默认包括score值等于min或max)的成员
 925      * @author    zhaoyingnan    2015-11-04 13:54
 926      * @param    string        $sKey
 927      * @param    int            $min
 928      * @param    int            $max
 929      * @return    int
 930      **/
 931     public function zcount($sKey, $min = 0, $max = -1)
 932     {
 933         if(!$sKey)return 0;
 934         return self::$redis->zcount($sKey, $min, $max);
 935     }
 936 
 937     /**
 938      * 返回有序集key中,成员member的score值。
 939      * 如果member元素不是有序集key的成员,或key不存在,返回nil。
 940      * @access    public
 941      * @author    zhaoyingnan    2015-11-10 15:26
 942      * @param    string        $sKey
 943      * @param    string        $member
 944      * @return    mix
 945      * @note    
 946      **/
 947     public function zscore($sKey, $member)
 948     {
 949         if(!$sKey || !$member)return 0;
 950         return self::$redis->zscore($sKey, $member);
 951     }
 952 
 953     /**
 954      * 为有序集key的成员member的score值加上增量increment。
 955      * 如果key中不存在member,就在key中添加一个member,score是increment(就好像它之前的score是0.0)。
 956      * 如果key不存在,就创建一个只含有指定member成员的有序集合。
 957      * 当key不是有序集类型时,返回一个错误。
 958      * score值必须是字符串表示的整数值或双精度浮点数,并且能接受double精度的浮点数。也有可能给一个负数来减少score的值。
 959      * @access    public
 960      * @author    zhaoyingnan    2015-11-10 13:48
 961      * @param    string        $sVar
 962      * @param    int            $iVar
 963      * @param    string        $sVar
 964      * @return    mix            member成员的新score值,以字符串形式表示。当key不是有序集类型时,返回一个错误。
 965      * @note    
 966      **/
 967     public function zincrby($sKey, $iIncrement, $member)
 968     {
 969         if(!$sKey || !$iIncrement || !$member)return FALSE;
 970         return self::$redis->zincrby($sKey, $iIncrement, $member);
 971     }
 972 
 973     /**
 974      * 返回有序集key中,指定区间内的成员(按下标指定区间)
 975      * 下标参数start和stop都以0为底,也就是说,以0表示有序集第一个成员,以1表示有序集第二个成员,以此类推。 
 976      * 你也可以使用负数下标,以-1表示最后一个成员,-2表示倒数第二个成员,以此类推。
 977      * 如果你需要成员按score值递减(score相等时按字典序递减)来排列,请使用ZREVRANGE命令。 
 978      * 可以通过使用WITHSCORES选项,来让成员和它的score值一并返回,返回列表以value1,score1, ..., valueN,scoreN的格式表示,而不是value1,...,valueN。
 979      * 客户端库可能会返回一些更复杂的数据类型,比如数组、元组等。
 980      * @author    zhaoyingnan    2015-11-04 14:00
 981      * @param    string        $sKey
 982      * @param    int            $iStart
 983      * @param    int            $iEnd
 984      * @return    array
 985      **/
 986     public function zrange($sKey, $iStart = 0, $iEnd = -1, $isWITHSCORES = FALSE)
 987     {
 988         if(!$sKey)return 0;
 989         return self::$redis->zrange($sKey, $iStart, $iEnd, $isWITHSCORES);
 990     }
 991 
 992     /**
 993      * 返回有序集key中,指定区间内的成员。
 994      * 其中成员的位置按score值递减(从大到小)来排列。具有相同score值的成员按字典序的反序排列。 
 995      * 除了成员按score值递减的次序排列这一点外,ZREVRANGE命令的其他方面和ZRANGE命令一样
 996      * @access    public
 997      * @author    zhaoyingnan    2015-11-10 14:44
 998      * @param    string        $sKey
 999      * @param    int            $iStart
1000      * @param    int            $iEnd
1001      * @return    array
1002      * @note    
1003      **/
1004     public function zrevrange($sKey, $iStart = 0, $iEnd = -1, $isWITHSCORES = FALSE)
1005     {
1006         if(!$sKey)return 0;
1007         return self::$redis->zrevrange($sKey, $iStart, $iEnd, $isWITHSCORES);
1008     }
1009 
1010     /**
1011      * 返回key的有序集合中的分数在min和max之间的所有元素(包括分数等于max或者min的元素)。
1012      * 元素被认为是从低分到高分排序的。 
1013      * 具有相同分数的元素按字典序排列(这个根据redis对有序集合实现的情况而定,并不需要进一步计算)。 
1014      * 可选的LIMIT参数指定返回结果的数量及区间(类似SQL中SELECT LIMIT offset, count)。
1015      * 注意,如果offset太大,定位offset就可能遍历整个有序集合,这会增加O(N)的复杂度。 
1016      * 可选参数WITHSCORES会返回元素和其分数,而不只是元素。这个选项在redis2.0之后的版本都可用。
1017      * 区间及无限
1018      * min和max可以是-inf和+inf,这样一来,你就可以在不知道有序集的最低和最高score值的情况下,使用ZRANGEBYSCORE这类命令。
1019      * 默认情况下,区间的取值使用闭区间(小于等于或大于等于),你也可以通过给参数前增加(符号来使用可选的开区间(小于或大于)。
1020      * @author    zhaoyingnan    2015-11-04 14:18
1021      * @param    string        $sKey
1022      * @param    mix            $min        分数的区间的最小值(闭区间)
1023      * @param    mix            $max        分数的区间的最大值(闭区间)
1024      * @param    array        $arWith = array('withscores' => TRUE, 'limit' => array(0, 1))
1025      * @return    array
1026      **/
1027     public function zrangebyscore($sKey, $min = '-inf', $max = '+inf', $arWith = array('withscores'=>TRUE, 'limit'=>array(0, 1)))
1028     {
1029         if(!$sKey)return array();
1030         return self::$redis->zrangebyscore($sKey, $min, $max, $arWith);
1031     }
1032 
1033     /**
1034      * 返回key的有序集合中的分数在max和min之间的所有元素(包括分数等于max或者min的元素)。
1035      * 与有序集合的默认排序相反,对于这个命令,元素被认为是从高分到低具有相同分数的元素按字典反序。
1036      * 除了反序之外, ng, ZREVRANGEBYSCORE 和ZRANGEBYSCORE类似。
1037      * @access    public
1038      * @author    zhaoyingnan    2015-11-10 14:39
1039      * @param    string        $sKey
1040      * @param    mix            $max        分数的区间的最大值(闭区间)
1041      * @param    mix            $min        分数的区间的最小值(闭区间)
1042      * @param    array        $arWith = array('withscores' => TRUE, 'limit' => array(0, 1))
1043      **/
1044     public function zrevrangebyscore($sKey, $max = '+inf', $min = '-inf', $arWith = array('withscores'=>TRUE, 'limit'=>array(0, 1)))
1045     {
1046         if(!$sKey)return array();
1047         return self::$redis-> zrevrangebyscore($sKey, $max, $min, $arWith);
1048     }
1049 
1050     /**
1051      * 返回有序集key中成员member的排名。
1052      * 其中有序集成员按score值递增(从小到大)顺序排列。
1053      * 排名以0为底,也就是说,score值最小的成员排名为0,那实际的排名则为1
1054      * @access    public
1055      * @author    zhaoyingnan    2015-11-10 13:38
1056      * @param    string        $sKey
1057      * @param    string        $member
1058      * @return    int            返回实际的排名
1059      * @note    
1060      **/
1061     public function zrank($sKey, $member)
1062     {
1063         if(!$sKey || !$member)return 0;
1064         return self::$redis->zrank($sKey, $member)+1;
1065     }
1066 
1067     /**
1068      * 返回有序集key中成员member的排名,其中有序集成员按score值从大到小排列。排名以0为底,也就是说,score值最大的成员排名为0。
1069      * 使用ZRANK命令可以获得成员按score值递增(从小到大)排列的排名。
1070      * @access    public
1071      * @author    zhaoyingnan    2015-11-10 14:51
1072      * @param    string        $sKey
1073      * @param    string        $member
1074      * @return    int            返回实际的排名
1075      * @note    
1076      **/
1077     public function zrevrank($sKey, $member)
1078     {
1079         if(!$sKey || !$member)return 0;
1080         return self::$redis->zrevrank($sKey, $member)+1;
1081     }
1082 
1083     /**
1084      * 从key对应的有序集合中删除给定的成员。如果给定的成员不存在就忽略。
1085      * @access    public
1086      * @author    zhaoyingnan    2015-11-10 15:01
1087      * @param    string        $sKey
1088      * @param    array        $arMember    倍删除的成员数组
1089      * @return    int            返回的是从有序集合中删除的成员个数,不包括不存在的成员。
1090      * @note    
1091      **/
1092     public function zrem($sKey, $arMember = array())
1093     {
1094         if(!$sKey || !$arMember)return 0;
1095         $iCount = 0;
1096         foreach($arMember as $sVal)
1097         {
1098             if(self::$redis->zrem($sKey, $sVal))
1099                 $iCount++;
1100         }
1101         return $iCount;
1102     }
1103 
1104     /**
1105      * 移除有序集key中,指定排名(rank)区间内的所有成员。下标参数start和stop都以0为底,0处是分数最小的那个元素。
1106      * 这些索引也可是负数,表示位移从最高分处开始数。例如,-1是分数最高的元素,-2是分数第二高的,依次类推。
1107      * @access    public
1108      * @author    zhaoyingnan    2015-11-10 15:08
1109      * @param    string        $sKey
1110      * @param    int            $iStart        指定的开始排名区间(闭区间)
1111      * @param    int            $iEnd        指定的结束排名区间(闭区间)
1112      * @return    int            删除的元素的个数。    
1113      * @note    
1114      **/
1115     public function zremrangebyrank($sKey, $iStart = 0, $iEnd = -1)
1116     {
1117         //如果不填写$iStart和$iEnd不填写的话,会删除$sKey的所有成员
1118         if(!$sKey)return 0;
1119         return self::$redis->zremrangebyrank($sKey, $iStart, $iEnd);
1120     }
1121 
1122     /**
1123      * 移除有序集key中,所有score值介于min和max之间(包括等于min或max)的成员。
1124      * 自版本2.1.6开始,score值等于min或max的成员也可以不包括在内,语法请参见ZRANGEBYSCORE命令。
1125      * @access    public
1126      * @author    zhaoyingnan    2015-11-10 15:08
1127      * @param    string        $sKey
1128      * @param    mix            $min        指定的 score 区间的最小值(闭区间)
1129      * @param    mix            $max        指定的 score 区间的最大值(闭区间)
1130      * @return    int            删除的元素的个数。
1131      * @note    
1132      **/
1133     public function zremrangebyscore($sKey, $min = '-inf', $max = '+inf')
1134     {
1135         //如果不填写$min和$max不填写的话,会删除$sKey的所有成员
1136         if(!$sKey)return 0;
1137         return self::$redis->zremrangebyscore($sKey, $min, $max);
1138     }
1139 }
1140 ?>