localhost:6379> del students
localhost:6379> lpush students a b c
(integer) 3
localhost:6379> rpush students o p q
(integer) 6
localhost:6379> lrange students 1 4
1) "b"
2) "a"
3) "o"
4) "p"
localhost:6379> lrange students 1 -2
1) "b"
2) "a"
3) "o"
4) "p"
7.删除队列中指定的值(返回实际删除元素的个数)
lrem key count value
从队列中删除count个值等于value的元素。
count 为正数时:则从左向右 开始删除,直至达到count个元素或队列中没有元素值==value的元素为止
count 为负时:则从右向左开始删除,直至达到count个元素或队列中没有元素值==value的元素为止
count ==0 时:表示删除队列中所有元素值==value的元素
localhost:6379> del students
localhost:6379> lpush students c b a c b a c b a
(integer) 9
localhost:6379> lrange students 0 -1
1) "a"
2) "b"
3) "c"
4) "a"
5) "b"
6) "c"
7) "a"
8) "b"
9) "c"
localhost:6379> lrem students -2 c//从右侧删除2个元素值==c的元素
(integer) 2
localhost:6379> lrange students 0 -1
1) "a"
2) "b"
3) "c"
4) "a"
5) "b"
6) "a"
7) "b"
localhost:6379> lrem students 2 a//从左侧删除2个元素值==a的元素
(integer) 2
localhost:6379> lrange students 0 -1
1) "b"
2) "c"
3) "b"
4) "a"
5) "b"
8.按索引序号获取队列中的元素
lindex key index
元素序号值:队列最左侧元素序号为0,之后元素序号依次+1,最右侧元素为序号最大的元素
另一种元素序号值:最右侧元率序号为-1,之前的元素序号依次-1,最左侧 元素为序号最小的元素
localhost:6379> del students
localhost:6379> lpush students a b c d e f
(integer) 6
localhost:6379> lindex students 0
"f"
localhost:6379> lindex students -1
"a"
localhost:6379> lindex students 2
"d"
9,修改队列中的元素值
lset key index value
指定索引位置的元素值被value覆盖
localhost:6379> del students
(integer) 1
localhost:6379> lpush students a b c d e f g
(integer) 7
localhost:6379> lset students -2 x
OK
localhost:6379> lrange students 0 -1
1) "g"
2) "f"
3) "e"
4) "d"
5) "c"
6) "x"
7) "a"
localhost:6379> lset students 0 z
OK
localhost:6379> lrange students 0 -1
1) "z"
2) "f"
3) "e"
4) "d"
5) "c"
6) "x"
7) "a"
localhost:6379> del students
(integer) 1
localhost:6379> rpush students a b c d e f
(integer) 6
localhost:6379> lrange students 0 -1
1) "a"
2) "b"
3) "c"
4) "d"
5) "e"
6) "f"
localhost:6379> ltrim students 1 -2
OK
localhost:6379> lrange students 0 -1
1) "b"
2) "c"
3) "d"
4) "e"
localhost:6379> del students
(integer) 1
localhost:6379> rpush students a b c d e f
(integer) 6
localhost:6379> lrange students 0 -1
1) "a"
2) "b"
3) "c"
4) "d"
5) "e"
6) "f"
localhost:6379> linsert students before b x
(integer) 7
localhost:6379> lrange students 0 -1
1) "a"
2) "x"
3) "b"
4) "c"
5) "d"
6) "e"
7) "f"
localhost:6379> linsert students after e z
(integer) 8
localhost:6379> lrange students 0 -1
1) "a"
2) "x"
3) "b"
4) "c"
5) "d"
6) "e"
7) "z"
8) "f"