redis基本数据类型 List

 

复制代码
127.0.0.1:6379> LPUSH test a
(integer) 1
127.0.0.1:6379> LPUSH test b
(integer) 2
127.0.0.1:6379> LPUSH test c
(integer) 3
127.0.0.1:6379> LRANGE test 0 2
1) "c"
2) "b"
3) "a"
127.0.0.1:6379> RPUSH test d
(integer) 4
127.0.0.1:6379> LRANGE test 0 3
1) "c"
2) "b"
3) "a"
4) "d"
127.0.0.1:6379> LPOP test 2
1) "c"
2) "b"
127.0.0.1:6379> LRANGE test 0 3
1) "a"
2) "d"
127.0.0.1:6379> BLPOP test 20
1) "test"
2) "a"
127.0.0.1:6379> BLPOP test 20
1) "test"
2) "d"
127.0.0.1:6379> BLPOP test 20
(nil)
(20.09s)
127.0.0.1:6379> 
复制代码

思考:

如何利用List结构模拟一个栈?

入口和出口在同一边

如何利用List结构模拟一个队列?

入口和出口在不同边

 如何利用List结构模拟一个阻塞队列?

入口和出口在不同边
出队时采用BLPOP或BRPOP
posted @   高佳丰  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
点击右上角即可分享
微信分享提示