redis list命令操作

1.将值追加到列表
RPUSH key value [value ...]
summary: Append one or multiple values to a list
since: 1.0.0
127.0.0.1:6379> RPUSH mylist value1 value2 value3
(integer) 3

2.获取列表的长度
LLEN key
summary: Get the length of a list
since: 1.0.0

127.0.0.1:6379> llen mylist
(integer) 3

3.获取并移除列表中第一个元素
BLPOP key [key ...] timeout
summary: Remove and get the first element in a list, or block until one is available
since: 2.0.0

127.0.0.1:6379> blpop mylist 3
1) "mylist" ##列表key
2) "value1" #列表当前第一个值
127.0.0.1:6379> blpop mylist 3
1) "mylist"
2) "value2"
127.0.0.1:6379> blpop mylist 3
1) "mylist"
2) "value3"
127.0.0.1:6379> blpop mylist 3 列表已经不存在value

(nil)
(3.78s)

4.获取并移除列表中的最后一个元素
BRPOP key [key ...] timeout
summary: Remove and get the last element in a list, or block until one is available
since: 2.0.0
127.0.0.1:6379> brpop list1 3
1) "list1" #列表键名
2) "value3" #列表最后一个值

5.出栈list中的一个value,并放入另一个list中,并返回该值
BRPOPLPUSH source destination timeout
summary: Pop a value from a list, push it to another list and return it; or block until one is available
since: 2.2.0

127.0.0.1:6379> BRPOPLPUSH list1 list2 3
"value2"

6.获取指定位置的value值,返回的是该位置的值,无值或超出边界返回nil
LINDEX key index
summary: Get an element from a list by its index
since: 1.0.0

7.在列表一个元素的之前或之后插入一个元素,返回当前列表的长度
LINSERT key BEFORE|AFTER pivot value
summary: Insert an element before or after another element in a list
since: 2.2.0
127.0.0.1:6379> linsert ml before v2 value2
(integer) 5  在v2之前插入值value2

8.栈顶元素出栈
LPOP key
summary: Remove and get the first element in a list
since: 1.0.0
127.0.0.1:6379> lpop ml
"v1"

9.向list中添加一个或多个value,后加入的值,index在前(将元素压入栈顶)
LPUSH key value [value ...]
summary: Prepend one or multiple values to a list
since: 1.0.0
127.0.0.1:6379> lpush list2 val1 val2 val3 val4 val5
(integer) 6
127.0.0.1:6379> lindex list2 0
"val5"

10.只有当列表存在时,才从栈顶压入元素
LPUSHX key value
summary: Prepend a value to a list, only if the list exists
since: 2.2.0

11.获取指定范围的list的value值
LRANGE key start stop
summary: Get a range of elements from a list
since: 1.0.0

12.从列表中移除元素(当list中存在多个重复的值时,count确定要移除几个value)
LREM key count value
summary: Remove elements from a list
since: 1.0.0

13.通过元素的索引index设置value
LSET key index value
summary: Set the value of an element in a list by its index
since: 1.0.0
127.0.0.1:6379> lset list2 3 namew #修改第三个位置的值
OK

14. 
LTRIM key start stop
summary: Trim a list to the specified range
since: 1.0.0

15.移除并获取列表中的最后一个元素
RPOP key
summary: Remove and get the last element in a list
since: 1.0.0

16.移除列表中的最后一个元素,追加到另一个列表中,并返回该值
RPOPLPUSH source destination
summary: Remove the last element in a list, append it to another list and return it
since: 1.2.0

17.将值追加到列表中,只有当这个列表已经存在
RPUSHX key value
summary: Append a value to a list, only if the list exists
since: 2.2.0

时间: 2024-10-01 07:19:24

redis list命令操作的相关文章

redis hash命令操作

/*********redis hash命令操作 **********/ 1.删除一个或多个hash域 HDEL key field [field ...] summary: Delete one or more hash fields since: 2.0.0 127.0.0.1:6379> HDEL hash1 name (integer) 1 2.判断一个域是否存在 HEXISTS key field summary: Determine if a hash field exists si

Redis——常用命令操作

 一,启动   Centos6       进入到redis安装目录: cd redis-2.8.17     进入src目录: cd src     启动server:  ./redis-server    使用配置文件启动: ./redis-serverredis.conf      Ubuntu 启动server:redis-server 启动客户端:redis-cli    Windows   redis-cli.exe-h 127.0.0.1 -p 6379 二,使用命令对Redis基

redis sorted_set 命令操作

score 是set排序的值,越大越在前 1.添加 成员到sorted_set中,并设置score ZADD key score member [score member ...] summary: Add one or more members to a sorted set, or update its score if it already exists since: 1.2.0 127.0.0.1:6379> zadd sset1 2 val4 (integer) 1 2. 查询sort

redis set命令操作

1.添加一个或多个成员到set SADD key member [member ...] summary: Add one or more members to a set since: 1.0.0 127.0.0.1:6379> sadd set1 val1 val2 val3 (integer) 3 2.获取一个set的成员数量 SCARD key summary: Get the number of members in a set since: 1.0.0 127.0.0.1:6379>

redis transaction和connection命令操作

/*********** redis transaction命令操作 **********/ 1. DISCARD - summary: Discard all commands issued after MULTI since: 2.0.0 EXEC - summary: Execute all commands issued after MULTI since: 1.2.0 MULTI - summary: Mark the start of a transaction block sinc

redis server和scripting 命令操作

/********* redis server命令操作 *************/ BGREWRITEAOF - summary: Asynchronously rewrite the append-only file since: 1.0.0 BGSAVE - summary: Asynchronously save the dataset to disk since: 1.0.0 CLIENT GETNAME - summary: Get the current connection na

redis命令操作之generic和string.java

redis是键值对的内存数据库,属于Nosql范畴 登录redis自带的客户端 #redis-cli 127.0.0.1:6379> 1.设置redis 键值对 > set foo bar  #设置键foo的值为"bar" OK #设置成功 2.获得redis 键值对 > get foo #根据键获得值 "bar" #返回的结果 3.删除键值对  127.0.0.1:6379> del foo foo2 foo3 #删除键值对,可删除多个 (

第2讲 Redis常用命令与高级应用

目录 一.redis数据类型 5. sorted sets类型和操作 二.Redis常用命令 1.键值相关命令 2.服务器相关命令 三. redis高级应用 1. 给redis服务器设置密码 2.持久化 3.主从备份 一.redis数据类型 5. sorted sets类型和操作 sorted set是set的一个升级版本,它给集合中每个元素都定义一个分数,集合中的元素按照其分数排序. 1) zadd 键 分数1 值1 [分数2 值2-] 该命令添加指定的成员到key对应的有序集合中,每个成员都

redis-Ubuntu server 15.0.4安装Redis make命令不能执行

问题描述 Ubuntu server 15.0.4安装Redis make命令不能执行 按照官方的下载安装指导:http://redis.io/download#installation Download, extract and compile Redis with: $ wget http://download.redis.io/releases/redis-3.0.3.tar.gz $ tar xzf redis-3.0.3.tar.gz $ cd redis-3.0.3 $ make T