List类型:先进先出队列
1 设置和获取值
127.0.0.1:6379> lpush list1 1 2 3 4
(integer) 4
127.0.0.1:6379> rpush list2 1 2 3 4
(integer) 4
127.0.0.1:6379> lrange list1 0 -1
1) "4"
2) "3"
3) "2"
4) "1"
127.0.0.1:6379> lrange list2 0 -1
1) "1"
2) "2"
3) "3"
4) "4"
127.0.0.1:6379> lpop list1
"4"
127.0.0.1:6379> lpop list2
"1"
127.0.0.1:6379> rpop list1
"1"
127.0.0.1:6379> rpop list2
"4"
127.0.0.1:6379> lrange list1 0 -1
1) "3"
2) "2"
127.0.0.1:6379> lrange list2 0 -1
1) "2"
2) "3"
127.0.0.1:6379> lpush list3 1 2 3 4
(integer) 4
127.0.0.1:6379> lindex list3 0
"4"
2 大小
127.0.0.1:6379> llen list3
(integer) 4
3 插入与修改
127.0.0.1:6379> lrange list3 0 -1
1) "3"
2) "2"
3) "1"
127.0.0.1:6379> linsert list3 before 2 5
(integer) 4
127.0.0.1:6379> lrange list3 0 -1
1) "3"
2) "5"
3) "2"
4) "1"
127.0.0.1:6379> lset list3 2 4
OK
127.0.0.1:6379> lrange list3 0 -1
1) "3"
2) "5"
3) "4"
4) "1"
4 删除
127.0.0.1:6379> lrange list3 0 -1
1) "3"
2) "5"
3) "4"
4) "5"
127.0.0.1:6379> lrem list3 2 5
(integer) 2
127.0.0.1:6379> lrange list3 0 -1
1) "3"
2) "4"
127.0.0.1:6379>
5 截取
127.0.0.1:6379> lrange list3 0 -1
1) "4"
2) "3"
3) "2"
4) "1"
127.0.0.1:6379> ltrim list3 0 2
OK
127.0.0.1:6379> lrange list3 0 -1
1) "4"
2) "3"
3) "2"