当前位置:网站首页>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的功能单一,且不稳定
在实际开发中不会用到它,客户端消息的发布与订阅,我们会学一门技术专门做消息的通信与发布的
边栏推荐
- Sword finger offer 65 Add without adding, subtracting, multiplying, dividing
- Detailed explanation of heap sort code
- [try to hack] wide byte injection
- 攻防世界 MISC 進階區 Erik-Baleog-and-Olaf
- colResizable. JS auto adjust table width plug-in
- Redis: redis configuration file related configuration and redis persistence
- 智力考验看成语猜古诗句微信小程序源码
- MP进阶操作: 时间操作, sql,querywapper,lambdaQueryWapper(条件构造器)快速筛选 枚举类
- Duplicate ADMAS part name
- Explanation of bitwise operators
猜你喜欢

Redis入门完整教程:Bitmaps

Breakpoint debugging under vs2019 c release

Attack and defense world misc advanced area ditf

colResizable. JS auto adjust table width plug-in

MySQL Architecture - logical architecture

Qt加法计算器(简单案例)

攻防世界 MISC 进阶区 hong

浅聊一下中间件

Redis getting started complete tutorial: publish and subscribe

Redis getting started complete tutorial: Geo
随机推荐
Google Earth engine (GEE) -- take modis/006/mcd19a2 as an example to batch download the daily mean, maximum, minimum, standard deviation, statistical analysis of variance and CSV download of daily AOD
PS style JS webpage graffiti board plug-in
【二叉树】节点与其祖先之间的最大差值
位运算符讲解
Redis入门完整教程:初识Redis
该如何去选择证券公司,手机上开户安不安全
字体设计符号组合多功能微信小程序源码
MySQL Architecture - logical architecture
Lost in the lock world of MySQL
Insert sort, select sort, bubble sort
[Lua] Int64 support
Redis getting started complete tutorial: publish and subscribe
Redis入门完整教程:Redis Shell
【ODX Studio編輯PDX】-0.2-如何對比Compare兩個PDX/ODX文件
剑指Offer 68 - II. 二叉树的最近公共祖先
常用技术指标之一文读懂BOLL布林线指标
攻防世界 MISC 進階區 Erik-Baleog-and-Olaf
Three stage operations in the attack and defense drill of the blue team
Summary of index operations in mongodb
S32 Design Studio for ARM 2.2 快速入门