Redis发布订阅
-
Redis发布订阅,是一种消息通信模式,发布者pub发送消息,订阅者,sub接受消息,微信,微博,关注系统!
-
订阅发布消息图
-
第一个:消息发送者,第二个:频道,第三个:消息订阅者!
-
-
测试
订阅端:
-
127.0.0.1:6379> subscribe xiaoduanshuo Reading messages... (press Ctrl-C to quit) 1) "subscribe" 2) "xiaoduanshuo" 3) (integer) 1 1) "message" 2) "xiaoduanshuo" 3) "hello,xiaoduan"
发送端:
-
127.0.0.1:6379> publish xiaoduanshuo "hello,xiaoduan" (integer) 1
-
-
使用场景
- 实时消息系统!
- 实时聊天!(频道当做聊天室,将信息回显给所有人!)
- 订阅,关注系统都是可以的!
- 稍微复杂的场景,我们就会使用消息中间件!