lSize
Description
Returns the size of a list identified by Key. If the list didn't exist or is empty, the command returns 0. If the data type identified by Key is not a list, the command return FALSE.
根据KEY返回该KEY代表的LIST的长度,如果这个LIST不存在或者为空,那么ISIZE返回0,如果指定的KEY的数据类型不是LIST或者不为空,那么返回FALSE。所以在这里多说一句,当用ISize返回判断值的时候,===就有用处了,这里FLASE和0是两个概念了。
Parameters
Key
Return value
LONG The size of the list identified by Key exists.
如果KEY存在并且为LIST且有元素,那么返回KEY的长度,为空或者不存在返回0。
BOOL FALSE if the data type identified by Key is not list
如果KEY的数据类型不为空或者LIST,则返回FALSE。
Example $redis->rPush('key1', 'A');
$redis->rPush('key1', 'B');
$redis->rPush('key1', 'C'); /* key1 => [ 'A', 'B', 'C' ] */
$redis->lSize('key1');/* 3 */
$redis->rPop('key1');
$redis->lSize('key1');/* 2 */
lIndex, lGet
Description
Return the specified element of the list stored at the specified key. 0 the first element, 1 the second ... -1 the last element, -2 the penultimate ... Return FALSE in case of a bad index or a key that doesn't point to a list.
根据索引值返回指定KEY LIST中的元素。0为第一个元素,1为第二个元素。-1为倒数第一个元素,-2为倒数第二个元素。如果指定了一个不存在的索引值,则返回FLASE。
Parameters
key index
Return value
String the element at this index
Bool FALSE if the key identifies a non-string data type, or no value corresponds to this index in the list Key.
Example $redis->rPush('key1', 'A');
$redis->rPush('key1', 'B');
$redis->rPush('key1', 'C'); /* key1 => [ 'A', 'B', 'C' ] */
$redis->lGet('key1', 0); /* 'A' */
$redis->lGet('key1', -1); /* 'C' */
$redis->lGet('key1', 10); /* `FALSE` */
lSet
Description
Set the list at index with the new value.
根据索引值设置新的VAULE
Parameters
key index value
Return value
BOOL TRUE if the new value is setted. FALSE if the index is out of range, or data type identified by key is not a list.
如果设置成功返回TURE,如果KEY所指向的不是LIST,或者索引值超出LIST本身的长度范围,则返回flase。
Iset函数刚像是UPDATE或者EDIT的概念,而不是INSERT或者ADD的概念,顾只能在LIST本身的长度范围内,而不能超出。
Example $redis->rPush('key1', 'A');
$redis->rPush('key1', 'B');
$redis->rPush('key1', 'C'); /* key1 => [ 'A', 'B', 'C' ] */
$redis->lGet('key1', 0); /* 'A' */
$redis->lSet('key1', 0, 'X');
$redis->lGet('key1', 0); /* 'X' */
lRange, lGetRange
Description
Returns the specified elements of the list stored at the specified key in the range [start, end]. start and stop are interpretated as indices: 0 the first element, 1 the second ... -1 the last element, -2 the penultimate ...
取得指定索引值范围内的所有元素。
Parameters
key start end
Return value
Array containing the values in specified range.
Example $redis->rPush('key1', 'A');
$redis->rPush('key1', 'B');
$redis->rPush('key1', 'C');
$redis->lRange('key1', 0, -1); /* array('A', 'B', 'C') */
lTrim, listTrim
Description
Trims an existing list so that it will contain only a specified range of elements.
它将截取LIST中指定范围内的元素组成一个新的LIST并指向KEY。简短解说就是截取LIST。
这个可不是JS,或者PHP中清空空格的意思。
Parameters
key start stop
Return value
Array
Bool return FALSE if the key identify a non-list value.
Example $redis->rPush('key1', 'A');
$redis->rPush('key1', 'B');
$redis->rPush('key1', 'C');
$redis->lRange('key1', 0, -1); /* array('A', 'B', 'C') */
$redis->lTrim('key1', 0, 1);
$redis->lRange('key1', 0, -1); /* array('A', 'B') */
lRem, lRemove
Description
Removes the first count occurences of the value element from the list. If count is zero, all the matching elements are removed. If count is negative, elements are removed from tail to head.
IRem,IRemove函数,首先要去判断count参数,如果count参数为0,那么所有符合删除条件的元素都将被移除。如果count参数为整数,将从左至右删除count个符合条件的元素,如果为负数则从右至左删除count个符合条件的元素。
Note: The argument order is not the same as in the Redis documentation. This difference is kept for compatibility reasons.
函数参数的顺序不一定要一致,这样做是为了保持兼容性。
Parameters
key
value
count
Return value
LONG the number of elements to remove
BOOL FALSE if the value identified by key is not a list.
Example $redis->lPush('key1', 'A');
$redis->lPush('key1', 'B');
$redis->lPush('key1', 'C');
$redis->lPush('key1', 'A');
$redis->lPush('key1', 'A');
$redis->lRange('key1', 0, -1); /* array('A', 'A', 'C', 'B', 'A') */
$redis->lRem('key1', 'A', 2); /* 2 */
$redis->lRange('key1', 0, -1); /* array('C', 'B', 'A') */
lInsert
Description
Insert value in the list before or after the pivot value. the parameter options specify the position of the insert (before or after). If the list didn't exists, or the pivot didn't exists, the value is not inserted.
在指定LIST中的指定中枢VALUE的左侧或者右侧插入VALUE。如果这个LIST不存在,或者这个pivot(key position)不存在,那么这个VALUE不会被插入。
Parameters
key position Redis::BEFORE | Redis::AFTER pivot value
Return value
The number of the elements in the list, -1 if the pivot didn't exists.
Example $redis->delete('key1');
$redis->lInsert('key1', Redis::AFTER, 'A', 'X'); /* 0 */
$redis->lPush('key1', 'A');
$redis->lPush('key1', 'B');
$redis->lPush('key1', 'C');
$redis->lInsert('key1', Redis::BEFORE, 'C', 'X'); /* 4 */
$redis->lRange('key1', 0, -1); /* array('A', 'B', 'X', 'C') */
$redis->lInsert('key1', Redis::AFTER, 'C', 'Y'); /* 5 */
$redis->lRange('key1', 0, -1); /* array('A', 'B', 'X', 'C', 'Y') */
$redis->lInsert('key1', Redis::AFTER, 'W', 'value'); /* -1 */