当前位置:网站首页>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的功能单一,且不稳定
在实际开发中不会用到它,客户端消息的发布与订阅,我们会学一门技术专门做消息的通信与发布的
边栏推荐
- 【ODX Studio编辑PDX】-0.3-如何删除/修改Variant变体中继承的(Inherited)元素
- Attack and defense world misc advanced area Hong
- 剑指 Offer 65. 不用加减乘除做加法
- Analysis of environmental encryption technology
- JS 3D explosive fragment image switching JS special effect
- Feature scaling normalization
- Redis入门完整教程:慢查询分析
- 刷题指南-public
- Google Earth engine (GEE) - tasks upgrade enables run all to download all images in task types with one click
- Advanced area a of attack and defense world misc Masters_ good_ idea
猜你喜欢
![[graph theory] topological sorting](/img/2c/238ab5813fb46a3f14d8de465b8999.png)
[graph theory] topological sorting

LabVIEW中比较两个VI

On-off and on-off of quality system construction

Advanced area of attack and defense world misc 3-11

集群的概述与定义,一看就会

Attack and defense world misc master advanced zone 001 normal_ png

攻防世界 MISC 進階區 Erik-Baleog-and-Olaf

Google Earth engine (GEE) - tasks upgrade enables run all to download all images in task types with one click

Redis introduction complete tutorial: Collection details
![[sword finger offer] questions 1-5](/img/54/b70d5290978e842939db99645c6ada.png)
[sword finger offer] questions 1-5
随机推荐
攻防世界 MISC 进阶区 hong
Redis入门完整教程:慢查询分析
vim编辑器知识总结
Hit the core in the advanced area of misc in the attack and defense world
Breakpoint debugging under vs2019 c release
A complete tutorial for getting started with redis: getting to know redis for the first time
P2181 对角线和P1030 [NOIP2001 普及组] 求先序排列
MYSQL架构——逻辑架构
Redis入門完整教程:Pipeline
Redis入门完整教程:Bitmaps
Attack and defense world misc advanced area can_ has_ stdio?
The overview and definition of clusters can be seen at a glance
PS style JS webpage graffiti board plug-in
Google collab trample pit
Tweenmax emoticon button JS special effect
页面关闭前,如何发送一个可靠请求
Create Ca and issue certificate through go language
Attack and Defense World MISC Advanced Area Erik baleog and Olaf
Redis入门完整教程:事务与Lua
VIM editor knowledge summary