redis list命令
将一个或多个字符串插入list LPUSHX key value
127.0.0.1:6379> lpush kaner hello
(integer) 1
127.0.0.1:6379> lpush kaner redis
(integer) 2
127.0.0.1:6379> lpush my
127.0.0.1:6379> lpush kaner my
(integer) 3
127.0.0.1:6379> lpush kaner love
(integer) 4
127.0.0.1:6379> lrange kaner 0 3
1) "love"
2) "my"
3) "redis"
4) "hello"
获取列表长度 LLEN KEY
127.0.0.1:6379> llen kaner
(integer) 4
通过索引获取列表中的元素 LINDEX key index
127.0.0.1:6379> lindex kaner 2
"redis"
移出并获取列表的第一个元素 LPOP KEY
127.0.0.1:6379> lpop kaner
"love"
127.0.0.1:6379> lrange kaner 0 3
1) "my"
2) "redis"
3) "hello"
移出并获取列表的最后一个元素 RPOP key
127.0.0.1:6379> lrange kaner 0 3
1) "my"
2) "redis"
从尾部将一个或多个字符串插入list RPUSH KEY VALUE
127.0.0.1:6379> rpush kaner hello
(integer) 3
127.0.0.1:6379> lrange kaner 0 3
1) "my"
2) "redis"
3) "hello"
通过索引设置列表元素的值 LSET key index value
127.0.0.1:6379> lset kaner 3 study
OK
127.0.0.1:6379> lrange kaner 0 5
1) "love"
2) "my"
3) "redis"
4) "study"
5) "hello"
6) "world"
对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除 LTRIM key start stop
127.0.0.1:6379> ltrim kaner 0 3
OK
127.0.0.1:6379> lrange kaner 0 5
1) "love"
2) "my"
3) "redis"
4) "study"
移除列表的最后一个元素,并将该元素添加到另一个列表并返回 RPOPLPUSH source destination
127.0.0.1:6379> rpoplpush kaner kaner1
"study"
127.0.0.1:6379> lrange kaner1 0 5
1) "study"
为已存在的列表添加值 RPUSHX key value
127.0.0.1:6379> lpushx kaner aaa
(integer) 4
127.0.0.1:6379> rpushx kaner aaa
(integer) 5
在列表的元素前或者后插入元素 LINSERT key BEFORE|AFTER pivot value
127.0.0.1:6379> linsert kaner1 before study I
(integer) 2
127.0.0.1:6379> lrange kaner1 0 -1
1) "I"
2) "study"
127.0.0.1:6379> linsert kaner1 after study hardI
(integer) 3
127.0.0.1:6379> lrange kaner1 0 -1
1) "I"
2) "study"
3) "hardI"
获取列表指定范围内的元素 LRANGE KEY START STOP
127.0.0.1:6379> lrange kaner1 0 -1
1) "I"
2) "study"
3) "hardI"
移除列表元素 LREM key count value
127.0.0.1:6379> lrange kaner1 0 -1
1) "hello"
2) "hello"
3) "study"
4) "hardI"
127.0.0.1:6379> lrem kaner1 -2 hello
(integer) 2