1 基本
发布/订阅是一种消息通信模式。发布者不是将消息发布给订阅者,而是发布到不同频道。订阅者接受自己感兴趣的频道的消息,不需要接触发布者。
sub/pub都是client,而channel是server。
如图,当新消息通过publish命令发布到channel1时,这个消息就会被发送到三个sub client。
2 命令
在cli上订阅一个频道:channel1
127.0.0.1:6379> SUBSCRIBE channel1Reading messages... (press Ctrl-C to quit)1) "subscribe"2) "channel1"3) (integer) 1
在另一个cli,通过publish命令向channel1发布消息
127.0.0.1:6379> PUBLISH channel1 1(integer) 1127.0.0.1:6379> PUBLISH channel1 ‘good‘(integer) 1
在sub上已经收到
127.0.0.1:6379> SUBSCRIBE channel1Reading messages... (press Ctrl-C to quit)1) "subscribe"2) "channel1"3) (integer) 11) "message"2) "channel1"3) "1"1) "message"2) "channel1"3) "good"
2-redis的pub/sub发布订阅
原文地址:https://www.cnblogs.com/jabbok/p/8600941.html