[Redis-CentOS7]Redis列表操作(三)

时间:2021-07-02 11:47:12

LPUSH添加列表

127.0.0.1:6379> LPUSH websites www.baidu.com
(integer) 1

LRANGE 获取全部值

127.0.0.1:6379> LRANGE 'websites' 0 -1
1) "www.baidu.com"

列表左侧添加字符

127.0.0.1:6379> LPUSH websites www.google.com
(integer) 2
127.0.0.1:6379> LRANGE 'websites' 0 -1
1) "www.google.com"
2) "www.baidu.com"
127.0.0.1:6379>

右侧添加字符串

127.0.0.1:6379> RPUSH websites www.163.com
(integer) 3
127.0.0.1:6379> LRANGE 'websites' 0 -1
1) "www.google.com"
2) "www.baidu.com"
3) "www.163.com"

左右删除列表值

127.0.0.1:6379> RPUSH websites www.qq.com
(integer) 4
# LPOP左删除
127.0.0.1:6379> LPOP websites
"www.google.com"
# RPOP右删除
127.0.0.1:6379> RPOP websites
"www.qq.com"
127.0.0.1:6379> LRANGE 'websites' 0 -1
1) "www.baidu.com"
2) "www.163.com"

LINDEX列表下标获取值

127.0.0.1:6379> LINDEX websites 0
"www.baidu.com"

LLEN列表长度

127.0.0.1:6379> LLEN websites
(integer) 2

参考链接 http://redisdoc.com/list/