当前位置:网站首页>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 edit PDX] - 0.2-how to compare two pdx/odx files of compare
- 剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
- Redis introduction complete tutorial: detailed explanation of ordered collection
- 攻防世界 MISC 高手进阶区 001 normal_png
- 微信公众号解决从自定义菜单进入的缓存问题
- Create Ca and issue certificate through go language
- Principle of lazy loading of pictures
- Qt加法计算器(简单案例)
- Sword finger offer 68 - I. nearest common ancestor of binary search tree
- The overview and definition of clusters can be seen at a glance
猜你喜欢

【剑指offer】1-5题

Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf

Lost in the lock world of MySQL

JS 3D explosive fragment image switching JS special effect

Unity Xiuxian mobile game | Lua dynamic sliding function (specific implementation of three source codes)

攻防世界 MISC 进阶区 Ditf

攻防世界 MISC 高手进阶区 001 normal_png

Breakpoint debugging under vs2019 c release

MySQL Architecture - logical architecture

Redis démarrer le tutoriel complet: Pipeline
随机推荐
攻防世界 MISC 进阶 glance-50
攻防世界 MISC 進階區 Erik-Baleog-and-Olaf
Redis入门完整教程:发布订阅
The new version judges the code of PC and mobile terminal, the mobile terminal jumps to the mobile terminal, and the PC jumps to the latest valid code of PC terminal
How to send a reliable request before closing the page
Redis introduction complete tutorial: List explanation
LabVIEW中比较两个VI
ETCD数据库源码分析——处理Entry记录简要流程
Editplus-- usage -- shortcut key / configuration / background color / font size
[ODX studio edit PDX] - 0.2-how to compare two pdx/odx files of compare
MYSQL架构——用户权限与管理
LIst 相关待整理的知识点
Breakpoint debugging under vs2019 c release
[graph theory] topological sorting
The small program vant tab component solves the problem of too much text and incomplete display
Erik baleog and Olaf, advanced area of misc in the attack and defense world
MySQL Architecture - user rights and management
[try to hack] wide byte injection
JS 3D explosive fragment image switching JS special effect
Unity Xiuxian mobile game | Lua dynamic sliding function (specific implementation of three source codes)