根据b站UP主狂神说Redis课程所写的个人学习笔记
视频地址:https://www.bilibili.com/video/BV1S54y1R7SB
Redis发布订阅是一种消息通信模式
Redis客户端可以订阅任意数量的频道
第一个:消息发送者
第二个:频道
第三个:消息订阅者
测试:
订阅端:
127.0.0.1:6379> subscribe lin
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "lin"
3) (integer) 1
1) "message" #消息
2) "lin" #哪个频道的消息
3) "hello,lin" #具体内容
发送端:
127.0.0.1:6379> publish lin "hello,lin"
(integer) 1
使用场景:
1.实时消息系统
2.实时聊天
3.订阅 关注系统
稍微复杂的场景我们会用消息中间件