redis 列表(list)函数
列表(list)函数
lPush 命令/方法/函数
Description Adds the string value to the head (left) of the list. Creates the list if the key didn't exist. If the key exists and is not a list, FALSE is returned. 添加一个字符串值到LIST容器的顶部(左侧),如果KEY不存在,曾创建一个LIST容器,如果KEY存在并且不是一个LIST容器,那么返回FLASE。 Parameters key value String, value to push in key Return value LONG The new length of the list in case of success, FALSE in case of Failure. 返回LIST容器最新的长度,如果ADD成功。失败则返回FALSE。 Examples $redis->delete('key1'); $redis->lPush('key1', 'C'); // returns 1 $redis->lPush('key1', 'B'); // returns 2 $redis->lPush('key1', 'A'); // returns 3 /* key1 now points to the following list: [ 'A', 'B', 'C' ] */
rPush 命令/方法/函数
Description Adds the string value to the tail (right) of the list. Creates the list if the key didn't exist. If the key exists and is not a list, FALSE is returned. 添加一个字符串值到LIST容器的底部(右侧),如果KEY不存在,曾创建一个LIST容器,如果KEY存在并且不是一个LIST容器,那么返回FLASE。 Parameters key value String, value to push in key Return value LONG The new length of the list in case of success, FALSE in case of Failure. 返回LIST容器最新的长度,如果ADD成功。失败则返回FALSE。 Examples $redis->delete('key1'); $redis->rPush('key1', 'A'); // returns 1 $redis->rPush('key1', 'B'); // returns 2 $redis->rPush('key1', 'C'); // returns 3 /* key1 now points to the following list: [ 'A', 'B', 'C' ] */
lPushx 命令/方法/函数
Description Adds the string value to the head (left) of the list if the list exists. 添加一个VALUE到LIST容器的顶部(左侧)如果这个LIST存在的话。 Parameters key value String, value to push in key Return value LONG The new length of the list in case of success, FALSE in case of Failure. 如果ADD成功, 返回LIST容器最新的长度。失败则返回FALSE。 Examples $redis->delete('key1'); $redis->lPushx('key1', 'A'); // returns 0 $redis->lPush('key1', 'A'); // returns 1 $redis->lPushx('key1', 'B'); // returns 2 $redis->lPushx('key1', 'C'); // returns 3 /* key1 now points to the following list: [ 'A', 'B', 'C' ] */
rPushx 命令/方法/函数
Description Adds the string value to the tail (right) of the list if the ist exists. FALSE in case of Failure. 添加一个VALUE到LIST容器的底部(右侧)如果这个LIST存在的话。 Parameters key value String, value to push in key Return value LONG The new length of the list in case of success, FALSE in case of Failure. 如果ADD成功, 返回LIST容器最新的长度。失败则返回FALSE。 Examples $redis->delete('key1'); $redis->rPushx('key1', 'A'); // returns 0 $redis->rPush('key1', 'A'); // returns 1 $redis->rPushx('key1', 'B'); // returns 2 $redis->rPushx('key1', 'C'); // returns 3 /* key1 now points to the following list: [ 'A', 'B', 'C' ] */
lPop 命令/方法/函数
Description Return and remove the first element of the list. 返回LIST顶部(左侧)的VALUE,并且从LIST中把该VALUE弹出。 Parameters key Return value STRING if command executed successfully BOOL FALSE in case of failure (empty list) 取得VALUE成功,返回TURE。如果是一个空LIST则返回FLASE。 Example $redis->rPush('key1', 'A'); $redis->rPush('key1', 'B'); $redis->rPush('key1', 'C'); /* key1 => [ 'A', 'B', 'C' ] */ $redis->lPop('key1'); /* key1 => [ 'B', 'C' ] */
rPop 命令/方法/函数
Description Returns and removes the last element of the list. 返回LIST底部(右侧)的VALUE,并且从LIST中把该VALUE弹出。 Parameters key Return value STRING if command executed successfully BOOL FALSE in case of failure (empty list) 取得VALUE成功,返回TURE。如果是一个空LIST则返回FLASE。 Example $redis->rPush('key1', 'A'); $redis->rPush('key1', 'B'); $redis->rPush('key1', 'C'); /* key1 => [ 'A', 'B', 'C' ] */ $redis->rPop('key1'); /* key1 => [ 'A', 'B' ] */
blPop, brPop 命令/方法/函数
Description Is a blocking lPop(rPop) primitive. If at least one of the lists contains at least one element, the element will be popped from the head of the list and returned to the caller. Il all the list identified by the keys passed in arguments are empty, blPop will block during the specified timeout until an element is pushed to one of those lists. This element will be popped. lpop命令的block版本即阻塞版本。如果LIST容器中有VAULE,将会返回ARRAY('listName''element')。如果TIMEOUT参数为空,那么如果LIST为空,blPop或者brPop将或结束调用。如果设置了timeout参数,blPop或者brPop将被挂起暂停运行TIMEOUT参数的时间,在此期间如果LIST被PUSH了元素,将在TIMEOUT时间结束后,被POP出来。 Parameters ARRAY Array containing the keys of the lists INTEGER Timeout Or STRING Key1 STRING Key2 STRING Key3 ... STRING KeynINTEGER Timeout Return value ARRAY array('listName', 'element') Example /* Non blocking feature */ $redis->lPush('key1', 'A'); $redis->delete('key2'); $redis->blPop('key1', 'key2', 10); /* array('key1', 'A') */ /* OR */ $redis->blPop(array('key1', 'key2'), 10); /* array('key1', 'A') */ $redis->brPop('key1', 'key2', 10); /* array('key1', 'A') */ /* OR */ $redis->brPop(array('key1', 'key2'), 10); /* array('key1', 'A') */ /* Blocking feature */ /* process 1 */ $redis->delete('key1'); $redis->blPop('key1', 10); /* blocking for 10 seconds */ /* process 2 */ $redis->lPush('key1', 'A'); /* process 1 */ /* array('key1', 'A') is returned*/
lSize 命令/方法/函数
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 */
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 命令/方法/函数
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 命令/方法/函数
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 命令/方法/函数
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 命令/方法/函数
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 命令/方法/函数
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 */
rpoplpush 命令/方法/函数
Pops a value from the tail of a list, and pushes it to the front of another list. Also return this value. 从源LIST的最后弹出一个元素,并且把这个元素从目标LIST的顶部(左侧)压入目标LIST。 Parameters Key: srckey Key: dstkey Return value STRING The element that was moved in case of success, FALSE in case of failure. Example $redis->delete('x', 'y'); $redis->lPush('x', 'abc'); $redis->lPush('x', 'def'); $redis->lPush('y', '123'); $redis->lPush('y', '456'); // move the last of x to the front of y. var_dump($redis->rpoplpush('x', 'y')); var_dump($redis->lRange('x', 0, -1)); var_dump($redis->lRange('y', 0, -1)); Output: string(3) "abc" array(1) { [0]=> string(3) "def" } array(3) { [0]=> string(3) "abc" [1]=> string(3) "456" [2]=> string(3) "123" }
redis 列表(list)函数的更多相关文章
- Redis 列表 List 主要操作函数
/** * redis 列表 List Redis列表是简单的字符串列表,按照插入顺序排序.你可以添加一个元素导列表的头部(左边)或者尾部(右边) */ //lpush 新增一个列,多个列可以用空格隔 ...
- redis列表list
Redis Rpush 命令 Redis 列表(List) Redis Rpush 命令用于将一个或多个值插入到列表的尾部(最右边). 如果列表不存在,一个空列表会被创建并执行 RPUSH 操作. ...
- Redis 列表(List)
Redis列表是简单的字符串列表,按照插入顺序排序.你可以添加一个元素导列表的头部(左边)或者尾部(右边) 一个列表最多可以包含 232 - 1 个元素 (4294967295, 每个列表超过40亿个 ...
- 2016022610 - redis列表命令集合
参考网址:http://www.yiibai.com/redis/redis_lists.html Redis列表是简单的字符串列表,排序插入顺序.您可以在头部或列表的尾部Redis的列表添加元素.列 ...
- Python笔记(二):列表+列表数据处理+函数
#才疏学浅,难免有不恰当之处,请不吝指正,谢谢. #适合初学者. 列表的数据自下而上堆放(形成一个堆栈),类似于其他编程语言的数组.例如: user = ["张三","李 ...
- 由Redis的hGetAll函数所引发的一次服务宕机事件
昨晚通宵生产压测,终于算是将生产服务宕机的原因定位到了,心累.这篇博客,算作一个复盘和记录吧... 先来看看Redis的缓存淘汰算法思维导图: 说明:当实际占用的内存超过Redis配置的maxmemo ...
- Redis列表
Redis列表是简单的字符串列表,排序插入顺序.您可以在头部或列表的尾部Redis的列表添加元素. 列表的最大长度为232 – 1 (每个列表超过4十亿元素4294967295)元素. 例子 redi ...
- redis 列表
Redis 列表(List) Redis列表是简单的字符串列表,按照插入顺序排序.你可以添加一个元素导列表的头部(左边)或者尾部(右边) 一个列表最多可以包含 232 - 1 个元素 (4294967 ...
- 安装 rabbitmq ,通过生成器获取redis列表数据 与 Celery 分布式异步队列
一.安装rabbitmq @全体成员 超简易安装rabbitmq文档 1.安装配置epel源rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/ ...
随机推荐
- XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Siberia
1. GUI 按题意判断即可. #include<stdio.h> #include<iostream> #include<string.h> #include&l ...
- 新浪云SAE 关于部分函数不能使用的做法
例如:file_put_contents("test.txt","Hello World. Testing!"); 可以这样写: file_put_conten ...
- vue cli搭建项目
1.首先电脑要在安装node环境下才能运行 2.全局安装webpack:npm install webpack -g 3.安装vue脚手架: npm install vue-cli -g 4.新建文件 ...
- 30、进程的基础理论,并发(multiprocessing模块)
我们之前基于tcp所做的通信都只能一个一个链接只有关闭当前链接时才能去链接下一个通信,这显然与现实情况不合.今天我们将来学一个新的概念进程,来做一个python多进程的并发编程.还会贴一个用json序 ...
- Windowns Server 2016 + Nginx 1.10.2 + PHP 7.1.0 + Laravel 5.3 + Mariadb 10.1.19 开发环境设置
1.设置PHP 1.1.官网下载PHPhttp://windows.php.net/downloads/releases/php-7.1.0-nts-Win32-VC14-x86.zip 1.2.解压 ...
- jdbc连接oracle时报错 Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableC
错误: Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; ...
- JMeter参数化中存在逗号的解决方法
在Jmeter中通过CSV Data Set Config进行参数化时,如果参数化数据中存在逗号(,)我们可以通过一下方式进行设置 如何存在中文乱码,可以设置file encoding:gb2312
- iniReader,读取配置文件中数据
#include ”IniOperation.h" CString strPath = strIntancePath + _T("..\\config.ini"); // ...
- 【Java算法學習】斐波那契數列問題-兔子產子經典問題
/** * 用遞推算法求解斐波那契數列:Fn = Fn-2 +Fn-1; */ import java.util.*; public class Fibonacci { public static v ...
- JDK安装路径下的JRE与独立安装的JRE区别
在JDK安装目录下的子文件下,已经默认安装了一个jre.且与独立安装的JRE6所包含的文件几乎完全一样. JDK里面内置的JRE和独立的JRE是有一点差别的: 在JDK安装文件中包含了一个完整的独立版 ...