当前位置:网站首页>redis发布订阅
redis发布订阅
2022-04-22 18:17:00 【RB_VER】
redis发布订阅(pub/sub)是一种消息通信模式:发布者发送消息,订阅者接收消息。
redis客户端可以订阅任意数量的频道。

下面展示了频道channel1,以及订阅这个频道的三个客户端之间的关系:

当有新消息通过publish命令发送给频道channel1时,这个消息就会被发送给订阅它的三个客户端:

原理:
redis通过publish、subscribe和psubscribe等命令实现发布和订阅功能。
通过subscribe命令订阅某频道后,redis-server里维护了一个字典,字典的键就是一个个channel,而字典的值则是一个链表,链表中保存了所有订阅这个channel的客户端。subscribe命令的关键,就是将客户端添加到给定的channel的订阅链表中。
通过publish命令向订阅者发送消息,redis-server会使用给定的频道作为键,在它所维护的channel字典中查找记录了订阅这个频道的所有客户端的链表,遍历这个链表,将消息发布给所有订阅者。
版权声明
本文为[RB_VER]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_41242680/article/details/124347947
边栏推荐
- leetcode 108:将有序数组转换为二叉搜索树
- [fundamentals of interface testing] Chapter 11 | detailed explanation of postman associated interface and batch execution use case set
- HackMyvm(二十五)Helium,系列文章持续更新
- [Lane] ultra fast lane detection (1) custom dataset training
- 学习文档。
- Read and write txt files in C language
- MySQL----索引
- 接口测试 Mock 实战(二) | 结合 jq 完成批量化的手工 Mock
- 【Lane】Ultra-Fast-Lane-Detection(1)自定义数据集训练
- Alipay open platform application - Township Health Center Application
猜你喜欢

Why don't I use flomo anymore
![[fundamentals of interface testing] Part 8 common assertions of postman and the working principle of assertions](/img/7c/eaf5802b7ff801cf1f6b06da986537.png)
[fundamentals of interface testing] Part 8 common assertions of postman and the working principle of assertions

Guiyitong appointment registration
![[thinking and progress]: regret about yourself](/img/e4/1658eae714440ccc1800aee5b2048c.jpg)
[thinking and progress]: regret about yourself

leetcode-470. 用 Rand7() 实现 Rand10()

因索引合并导致的MySQL死锁分析与解决实战!

Leetcode 108: convert an ordered array into a binary search tree

Design the test paper storage scheme of ten million students management system

Pytoch Note58 CNN可视化

图像的卷积——【torch学习笔记】
随机推荐
[fundamentals of interface testing] Chapter 10 | explain the pre script of postman request and its working principle in detail
PiKachu-File Inclusion(文件包含漏洞)
一个没啥L用,但可以装X的IDEA插件
How do I completely delete files on my computer?
Esprima ECMAScript 解析架构
In depth analysis of filter execution principle (BitSet mechanism and caching mechanism)
因索引合并导致的MySQL死锁分析与解决实战!
208. 实现 Trie (前缀树)
MySQL - index
Pikachu File Inclusion (File Inclusion Vulnerability)
The content exported by the rich text editor is PDF or docx
Research Report on the development of asset management and custody banking industry in 2021
WiFi Technology Overview: WiFi things
Use of ES6 generator function
我国有哪些完全自研的电脑硬件?
秒雲助力中電科32所發布“基於擬態應用集成框架的SaaS雲管理平臺解决方案”
I still don't understand the relative path and absolute path. This article takes you to analyze it briefly
电脑上怎么快速切换显示不同的软件界面
[fundamentals of interface testing] Part 8 common assertions of postman and the working principle of assertions
Applet - API