learn-tech/专栏/Redis核心原理与实战/11附录:更多列表操作命令.md
2024-10-16 06:37:41 +08:00

76 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

因收到Google相关通知网站将会择期关闭。相关通知内容
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 示例:
127.0.0.1:6379> llen list
(integer) 2
删除指定个数的元素
语法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"