127.0.0.1:6379[1]> rpush k5 a b c a b c d a b c c a
(integer) 12
127.0.0.1:6379[1]> lrange k5 0 -1
1) "a"
2) "b"
3) "c"
4) "a"
5) "b"
6) "c"
7) "d"
8) "a"
9) "b"
10) "c"
11) "c"
12) "a"
127.0.0.1:6379[1]> lrem k5 5 c
(integer) 4
127.0.0.1:6379[1]> lrange k5 0 -1
1) "a"
2) "b"
3) "a"
4) "b"
5) "d"
6) "a"
7) "b"
8) "a"
127.0.0.1:6379[1]>
15、把指定索引位置的元素替换为另一个值
bash复制代码
127.0.0.1:6379[1]> lrange k5 0 -1
1) "a"
2) "b"
3) "a"
4) "b"
5) "d"
6) "a"
7) "b"
8) "a"
127.0.0.1:6379[1]> lset k5 2 c
OK
127.0.0.1:6379[1]> lrange k5 0 -1
1) "a"
2) "b"
3) "c"
4) "b"
5) "d"
6) "a"
7) "b"
8) "a"
127.0.0.1:6379[1]>
16、仅保留指定区间的数据,两边的数据被删除
bash复制代码
127.0.0.1:6379[1]> lrange k5 0 -1
1) "a"
2) "b"
3) "c"
4) "b"
5) "d"
6) "a"
7) "b"
8) "a"
127.0.0.1:6379[1]> ltrim k5 1 3
OK
127.0.0.1:6379[1]> lrange k5 0 -1
1) "b"
2) "c"
3) "b"
127.0.0.1:6379[1]>