11 附录:更多列表操作命令¶
在某值之前/之后添加某个元素¶
语法:linsert key before|after pivot value 示例:
127.0.0.1:6379> linsert list3 before b A
(integer) 4
127.0.0.1:6379> lrange list3 0 -1
"a"
"A"
"b"
"c"
根据下标修改元素¶
语法:lset key index value 示例*:*
127.0.0.1:6379> lindex list3 0
"a"
127.0.0.1:6379> lset list3 0 A
OK
127.0.0.1:6379> lindex list3 0
"A"
根据下标删除元素¶
语法:ltrim key start stop 示例:
127.0.0.1:6379> lpush list a b c
(integer) 3
127.0.0.1:6379> ltrim list 0 1
OK
127.0.0.1:6379> lrange list 0 -1
1) "c"
2) "b"
查询列表的长度¶
语法:llen key 示例:
删除指定个数的元素¶
语法 :lrem key count value 示例:
127.0.0.1:6379> lpush list a a b b c c
(integer) 6
127.0.0.1:6379> lrem list 2 a
(integer) 2
127.0.0.1:6379> lrem list 1 b
(integer) 1
127.0.0.1:6379> lrange list 0 -1
1) "c"
2) "c"
3) "b"