当前位置:网站首页>Redis的发布和订阅
Redis的发布和订阅
2022-07-17 07:23:00 【幻清】
1. 什么是发布和订阅
Redis 发布订阅 (pub/sub) 是一种消息通信模式:发送者 (pub) 发送消息,订阅者 (sub) 接收消息。 Redis 客户端可以订阅任意数量的频道。
2. Redis 的发布和订阅
1、客户端可以订阅频道如下图
一个客户端可以订阅多个频道。
2、当给这个频道发布消息后,消息就会发送给订阅的客户端
3. 发布订阅命令行实现
1、打开一个客户端订阅 channel1
SUBSCRIBE channel1

2、打开另一个客户端,给channel1发布消息hello
publish channel1 hello

返回的1是订阅者数量
3、打开第一个客户端可以看到发送的消息
注:
发布的消息没有持久化,如果在订阅的客户端收不到hello,只能收到订阅后发布的消息
边栏推荐
- Go language Bible
- Set settings in vscode json
- Spark miscellaneous -- why reuse exchange and subquery
- [C# 类和对象]-C# 中的方法以及类和对象编程
- 经典通用的Pbootcms花卉网站模板源码,自适应手机端,带后台管理
- [characteristic Engineering]
- How did "leek" give money to "sickle"? 2020-03-07
- How does the V8 engine recycle garbage memory?
- Redis data persistence
- 812. 最大三角形面积
猜你喜欢

US pressure surges, tiktok changes global safety director

STM32F103C8T6硬件IIC控制4针0.96寸OLED显示屏

First experience of openvino machine learning

才意识到自己“奇葩”的360,会不会有些晚?

从赌场逻辑,分析平台币的投资价值 2020-03-03

How to check whether the app has user information and data leakage vulnerabilities

写代码遇到Qt相关问题

Viewing the technology stack of distributed system from the crash report of station B

Redis distributed lock
![leetcode:287. Find the repetition number [fast and slow pointer board]](/img/4c/6278584f528f00776ed75f846edb3a.png)
leetcode:287. Find the repetition number [fast and slow pointer board]
随机推荐
No module named 'yaml' solution
“韭菜”是怎么把钱送给“镰刀”的? 2020-03-07
Complete square number
[kernel] character device that drives development and learning
be vigilant! Another phishing attack: uniswap stolen $8.1 million
最新一代互联网:WEB 3.0
Openpyxl copy sheet pages across workbooks
通过ip获取归属地
Yolov5 label and establish your own data set
Array exercise 3
Interview question: outer margin folding problem (bug of block level elements in ordinary document flow)
Shenzhen Prudential written examination record
真实案例:系统上线后Cpu使用率飙升如何排查?
Viewing the technology stack of distributed system from the crash report of station B
New redis6 features
行为型模式之策略模式
手把手实践一个DAPP,通往Web3.0之路!
History and value of forked coins | eth, BCH, BSV 2020-03-08
OpenCV极坐标转换函数warpPolar的使用
How did "leek" give money to "sickle"? 2020-03-07