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 @ 2023-01-31 16:58  高佳丰  阅读(17)  评论(0编辑  收藏  举报