当前位置:网站首页>Redis:Redis消息的发布与订阅(了解)
Redis:Redis消息的发布与订阅(了解)
2022-07-04 22:44:00 【dengfengling999】
为了实现客户端的通信,提供了频道的概念
1.Redis发布订阅
Redis 发布订阅(pub/sub)是一种消息通信模式:发送者(pub)发送消息,订阅者(sub)接收消息。Redis 客户端可以订阅任意数量的频道。
Redis发布订阅示意图
图一:消息订阅者(client2 、 client5 和 client1)订阅频道 channel1:
图二:消息发布者发布消息到频道channel1,会被发送到三个订阅者:
Redis发布订阅的常用命令
1.subscribe
语法:subscribe channel [channel…]
功能:订阅一个或多个频道的信息
返回值:订阅的消息
例如:
2.publish
语法:publish chanel message
功能:将信息发送到指定的频道。
返回值:数字。接收到消息订阅者的数量。
另一个客户端:
ch1就接收到了
3.psubscribe
语法:psubscribe pattern [pattern]
功能:订阅一个或多个符合给定模式的频道。模式以 * 作为通配符,例如:news.* 匹配所有以 news. 开头的频道。
返回值:订阅的信息。
由于Redis的功能单一,且不稳定
在实际开发中不会用到它,客户端消息的发布与订阅,我们会学一门技术专门做消息的通信与发布的
边栏推荐
- [OpenGL] note 29 anti aliasing (MSAA)
- 攻防世界 MISC 进阶区 can_has_stdio?
- Taobao commodity review API interface (item_review get Taobao commodity review API interface), tmall commodity review API interface
- The overview and definition of clusters can be seen at a glance
- 【剑指offer】1-5题
- Sword finger offer 68 - ii The nearest common ancestor of binary tree
- 剑指 Offer 65. 不用加减乘除做加法
- Redis introduction complete tutorial: List explanation
- Attack and defense world misc advanced area can_ has_ stdio?
- [Lua] Int64 support
猜你喜欢
Redis introduction complete tutorial: client communication protocol
LabVIEW中比较两个VI
MySQL Architecture - user rights and management
Redis getting started complete tutorial: hash description
浅聊一下中间件
The overview and definition of clusters can be seen at a glance
Redis入门完整教程:事务与Lua
JS card style countdown days
【剑指Offer】6-10题
Unity vscode emmylua configuration error resolution
随机推荐
Common methods in string class
Redis getting started complete tutorial: publish and subscribe
[roommate learned to use Bi report data processing in the time of King glory in one game]
Breakpoint debugging under vs2019 c release
Redis introduction complete tutorial: slow query analysis
Wechat official account solves the cache problem of entering from the customized menu
MySQL Architecture - logical architecture
Analysis of environmental encryption technology
攻防世界 MISC 进阶区 Ditf
Redis: redis configuration file related configuration and redis persistence
[OpenGL] note 29 anti aliasing (MSAA)
Redis introduction complete tutorial: client communication protocol
colResizable. JS auto adjust table width plug-in
On-off and on-off of quality system construction
Attack and defense world misc advanced area Hong
Attack and Defense World MISC Advanced Area Erik baleog and Olaf
A complete tutorial for getting started with redis: hyperloglog
UML图记忆技巧
Record: how to scroll screenshots of web pages on Microsoft edge in win10 system?
攻防世界 MISC 进阶区 can_has_stdio?