(二)Redis——List

因为是 List,所以所有相关的命令都以 L 开头。

LPUSH / RPUSH

LRANGE list 0 -1

-1 表示末尾

复制代码
127.0.0.1:6379> LPUSH list a
1
127.0.0.1:6379> LRANGE list 0 -1
a
127.0.0.1:6379> LPUSH list b
2
127.0.0.1:6379> LRANGE list 0 -1
b
a
127.0.0.1:6379> LPUSH list c d e
5
127.0.0.1:6379> LRANGE list 0 -1
e
d
c
b
a
127.0.0.1:6379> RPUSH list f
6
127.0.0.1:6379> LRANGE list 0 -1
e
d
c
b
a
f

LPOP / RPOP

复制代码
127.0.0.1:6379> RPOP list
f
127.0.0.1:6379> LRANGE list 0 -1
e
d
c
b
a
127.0.0.1:6379> LPOP list 2
ERR wrong number of arguments for 'lpop' command

LLEN

复制代码
127.0.0.1:6379> LLEN list
5

127.0.0.1:6379> LRANGE list 0 -1
e
d
c
b
a

LTRIM key start end

只保留 start, end 以内的元素(删除 start, end 之外的元素)

复制代码
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> lpush list a b c d e
5
127.0.0.1:6379> lrange list 0 -1
e
d
c
b
a
127.0.0.1:6379> LTRIM list 1 3
OK
127.0.0.1:6379> lrange list 0 -1
d
c
b
相关推荐
LZQqqqqo18 小时前
C# 中 ArrayList动态数组、List<T>列表与 Dictionary<T Key, T Value>字典的深度对比
windows·c#·list
海梨花20 小时前
【从零开始学习Redis】项目实战-黑马点评D2
java·数据库·redis·后端·缓存
指针满天飞20 小时前
Collections.synchronizedList是如何将List变为线程安全的
java·数据结构·list
鼠鼠我捏,要死了捏2 天前
生产环境Redis缓存穿透与雪崩防护性能优化实战指南
redis·cache
阿巴~阿巴~2 天前
深入解析C++ STL链表(List)模拟实现
开发语言·c++·链表·stl·list
曾经的三心草2 天前
微服务的编程测评系统11-jmeter-redis-竞赛列表
redis·jmeter·微服务
努力努力再努力wz2 天前
【c++深入系列】:万字详解模版(下)
java·c++·redis
2301_793086872 天前
Redis 04 Reactor
数据库·redis·缓存
AAA修煤气灶刘哥2 天前
搞定 Redis 不难:从安装到实战的保姆级教程
java·redis·后端
青鱼入云2 天前
redis怎么做rehash的
redis·缓存