Redis发布订阅(pub/sub)是一种消息通信模式:
发送者(pub)发送消息,订阅者(sub)接收消息。
Redis客户端可以订阅任意数量的频道。
subscribe channel [channel ...] 订阅一个或多个频道的消息
psubscribe pattern[pattern...] 订阅一个或多个符合给定模式的频道的消息
publish channel message 将消息发送到指定的频道
unsubscribe channel [channel ...] 退订指定的频道
punsubscribe pattern[pattern...] 退订所有给定模式的频道
Redis客户端1:
(订阅cctv9)
Redis客户端2:
(发送消息)
Redis客户端1:
(收到的订阅信息)
这一功能最明显的用法就是构建实时消息系统,比如普通的即时聊天,群聊等功能
1、在一个博客网站中,有1000个粉丝订阅了你,当你发布新文章时,就可以推送消息给粉丝
2、微信公众号模式
原文:https://www.cnblogs.com/schangxiang/p/11340329.html