当前位置:网站首页>Redis - how to understand publishing and subscribing
Redis - how to understand publishing and subscribing
2022-07-01 00:05:00 【Salted fish_ Turn over】
List of articles
brief introduction
Redis Publish subscription (publish/subscribe) It's a message communication mode , sender (publish) Send a message , subscriber (subscribe) Receiving and eliminating ,Redis Clients can subscribe to any number of channels .
subscribe / Release message map :
The picture below shows the channel channel1 , And three clients that subscribe to this channel —— client2 、 client5 and client1 The relationship between , When new news passes PUBLISH Command to channel channel1 when , This message will be sent to the three clients who subscribe to it :
Subscribe command
These are commands used to realize data communication , The real scene can be an Internet chat room , Radio, etc :
Subscription examples
Subscribers :
The sender :
Subscription principle
Redis yes C Language writing , When publishing and subscribing messages ,Redis Encapsulate it in a suffix named dot c In the file of ,pubsub.c
Every Redis The server processes all maintain a... That represents the state of the server redis.h/redisServer structure , Structural pubsub_channels Property is a dictionary , This dictionary is used to save subscription channel information , among , The key of the dictionary is the channel being subscribed , The value of a dictionary is a linked list , All clients subscribing to this channel are saved in the linked list . Client subscription , It is linked to the end of the linked list of the corresponding channel , Unsubscribe is to remove the client node from the list .
shortcoming :
1、 If a client subscribes to a channel , But I can't read messages fast enough , So the constant backlog of information will make redis The volume of the output buffer becomes larger and larger , This may make redis It's slowing down , Even the immediate collapse .
2、 It has to do with the reliability of data transmission , If the subscriber is disconnected , Then he'll lose all the news that the publisher posted in the short term .
Implementation scenarios for publishing and subscribing
1、 Real time communication message system
2、 WeChat official account ( Click to follow , Send a blog in the background , Subscribers can listen ) etc.
There are also some more complex scenes , Message oriented middleware can be used to ,RabbitMQ,RocketMQ,kafka…
边栏推荐
- 电商秒杀系统
- What is SRM system and how to standardize the internal procurement process of the company
- Tide - rust web framework based on async STD
- LVM snapshot: preparation of backup based on LVM snapshot
- PS2 handle-1 "recommended collection"
- 女朋友说:你要搞懂了MySQL三大日志,我就让你嘿嘿嘿!
- 2022-06-30:以下golang代码输出什么?A:0;B:2;C:运行错误。 package main import “fmt“ func main()
- Manage edge browser settings (ie mode, homepage binding, etc.) through group policy in the enterprise
- Prospects of world digitalization and machine intelligence in the next decade
- 1175. 質數排列 / 劍指 Offer II 104. 排列的數目
猜你喜欢

BeanUtils. Copyproperties() vs. mapstruct

ABAQUS 2022 software installation package and installation tutorial

Makefile notes (Yiwen Institute makefile)

HP notebook disable touchpad after mouse is inserted

Development of wireless U-shaped ultrasonic electric toothbrush

Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)

76 page comprehensive solution 2022 for smart Logistics Park (download attached)

Fastjson V2 simple user manual

Achieve secure data sharing among multiple parties and solve the problem of asymmetric information in Inclusive Finance

Solve arm_ release_ ver of this libmali is ‘g2p0-01eac0‘,rk_ so_ Ver is' 4 ', libgl1 mesa dev will not be installed, and there are unsatisfied dependencies
随机推荐
Pycharm is very fast to learn from installation to full armament. There are so many pictures because it is too detailed!
[leetcode] [SQL] notes
Sm2246en+ SanDisk 15131
[designmode] factory pattern
Qlineedit of QT notes (74) specifies the input type
Mysql database query optimization
NATs cluster deployment
Red Hat将在Project Atomic上运用容器负载服务器
股票开户要如何办理呢?办理手机开户安全吗
Rhai - rust's embedded scripting engine
leetcode 474. Ones and Zeroes 一和零(中等)
Software engineering best practices - project requirements analysis
未来十年世界数字化与机器智能展望
Explain kubernetes backup and recovery tools velero | learn more about carina series phase III
Is it safe to choose mobile phone for stock trading account opening in Guangzhou?
Understand target detection in one article: r-cnn, fast r-cnn, fast r-cnn, Yolo, SSD "suggestions collection"
Ride: get picture Base64
Red hat will apply container load server on project atomic
Detailed explanation of conv2d -- use in arrays and images
CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构