当前位置:网站首页>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的功能单一,且不稳定
在实际开发中不会用到它,客户端消息的发布与订阅,我们会学一门技术专门做消息的通信与发布的
边栏推荐
- 金融市场,资产管理与投资基金
- 9 - class
- Redis introduction complete tutorial: client communication protocol
- The small program vant tab component solves the problem of too much text and incomplete display
- Redis入门完整教程:集合详解
- Summary of index operations in mongodb
- Notepad++--编辑的技巧
- MYSQL架构——逻辑架构
- Summary of wechat applet display style knowledge points
- Tweenmax emoticon button JS special effect
猜你喜欢
随机推荐
【机器学习】手写数字识别
LIst 相关待整理的知识点
Pagoda 7.9.2 pagoda control panel bypasses mobile phone binding authentication bypasses official authentication
页面关闭前,如何发送一个可靠请求
A complete tutorial for getting started with redis: hyperloglog
攻防世界 MISC 进阶区 3-11
刷题指南-public
colResizable. JS auto adjust table width plug-in
How to send a reliable request before closing the page
位运算符讲解
Hit the core in the advanced area of misc in the attack and defense world
Three stage operations in the attack and defense drill of the blue team
How to choose a securities company? Is it safe to open an account on your mobile phone
Taobao commodity review API interface (item_review get Taobao commodity review API interface), tmall commodity review API interface
Summary of wechat applet display style knowledge points
金融市场,资产管理与投资基金
One of the commonly used technical indicators, reading boll Bollinger line indicators
【剑指Offer】6-10题
Notepad++--编辑的技巧
Redis入门完整教程:键管理







![P2181 对角线和P1030 [NOIP2001 普及组] 求先序排列](/img/79/36c46421bce08284838f68f11cda29.png)

