当前位置:网站首页>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…
边栏推荐
- How do it outsourcing resident personnel position their pain points?
- 基金銷售行為規範及信息管理
- Fund managers' corporate governance and risk management
- Maxpool2d explanation -- Application in arrays and images
- Zero sample and small sample learning
- What does it mean to open an account online? Is it safe to open an account online?
- In depth understanding of jetpack compose kernel: slottable system
- 基金销售行为规范及信息管理
- The college entrance examination in 2022 is over. Does anyone really think programmers don't need to study after work?
- When we look at the industrial Internet, we always look at it from the opposite of the consumer Internet
猜你喜欢

MaxPool2d详解--在数组和图像中的应用

QQmlApplicationEngine failed to load component qrc:/main. qml:-1 No such file or directory

5G智慧建筑解决方案2021

让企业数字化砸锅和IT主管背锅的软件供应链安全风险指北
![[leetcode] [SQL] notes](/img/8d/160a03b9176b8ccd8d52f59d4bb47f.png)
[leetcode] [SQL] notes

深入理解 Jetpack Compose 内核:SlotTable 系统

One revolution, two forces and three links: the "carbon reduction" road map behind the industrial energy efficiency improvement action plan

The college entrance examination in 2022 is over. Does anyone really think programmers don't need to study after work?

In depth understanding of jetpack compose kernel: slottable system

Wordpress blog uses volcano engine veimagex for static resource CDN acceleration (free)
随机推荐
[UML] UML class diagram
flutter - sort List排序
C language array interception, C string by array interception method (c/s)
NATs cluster deployment
深入理解 Jetpack Compose 内核:SlotTable 系统
When is it appropriate to replace a virtual machine with a virtual machine?
Which is better, server rental or hosting services in the United States?
In depth understanding of jetpack compose kernel: slottable system
[designmode] factory pattern
What does it mean to open an account online? Is it safe to open an account online?
Ditto set global paste only text shortcuts
ABAQUS 2022 latest edition - perfect realistic simulation solution
Matlab saves triangulation results as STL files
股票开户要如何办理呢?办理手机开户安全吗
206 page Shanghai BIM Technology Application and development report 2021
Bridge emqx cloud data to AWS IOT through the public network
Quick start of wechat applet -- project introduction
How do I open a stock account on my mobile phone? In addition, is it safe to open a mobile account?
Tide - rust web framework based on async STD
Fund clients and sales agencies