PHP Redis,phpredis
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 ?>