发布订阅
Redis发布订阅(pub/sub)是一种消息的订阅模式:发送者发送消息,订阅者接收消息;
Redis客户端可以订阅任意数量的频道;
消息发送者,频道,消息接收者;
测试:
# 订阅端
[root@localhost bin]# ./redis-cli -p 6379
127.0.0.1:6379> SUBSCRIBE kuangshenshuo
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "kuangshenshuo"
3) (integer) 1
1) "message"
2) "kuangshenshuo"
3) "hello"
1) "message"
2) "kuangshenshuo"
3) "world"
# 发布端
127.0.0.1:6379> PUBLISH kuangshenshuo hello
(integer) 1
127.0.0.1:6379> PUBLISH kuangshenshuo world
(integer) 1