Redis 常用命令学四:列表类型命令

1.在列表两端增加值的命令

127.0.0.1:6379> lpush 1
(error) ERR wrong number of arguments for 'lpush' command
127.0.0.1:6379> lpush rs 1
(integer) 1
127.0.0.1:6379> lpush rs 2 3
(integer) 3
127.0.0.1:6379> rpush rs 4 5 6
(integer) 6

2.查看某个范围内的值

127.0.0.1:6379> LRANGE rs 2 4
1) "1"
2) "4"
3) "5"
127.0.0.1:6379> LRANGE rs 0 7
1) "3"
2) "2"
3) "1"
4) "4"
5) "5"
6) "6"
127.0.0.1:6379> LRANGE rs -3 -1
1) "4"
2) "5"
3) "6

3.从列表中删除值

127.0.0.1:6379> LPOP rs
"3"
127.0.0.1:6379> RPOP rs
"6"

4.获取列表长度

127.0.0.1:6379> LLEN rs
(integer) 4

5.从左边删除3个为4的值,原来列表中只有一个

127.0.0.1:6379> LREM rs 3 4
(integer) 1

6.获得指定的索引的元素值

127.0.0.1:6379> LINDEX rs 2
"5"

7.为指定的索引赋值

127.0.0.1:6379> LSET rs 2 100
OK
127.0.0.1:6379> LINDEX rs 2
"100"
posted @ 2017-12-27 23:38  潇湘旧友  阅读(189)  评论(0编辑  收藏  举报