当前位置:网站首页>Redis的发布与订阅
Redis的发布与订阅
2022-07-07 16:37:00 【珠峰下的沙砾】
什么是发布和订阅
一般来说,发布与订阅(又称pub/sub)的特点是订阅者(listener)负责订阅频道(channel),发布者(publisher)负责向频道发送二进制字符串消息(binary string message)。每当有消息被发送至给定频道时,频道的所有订阅者都会收到消息。我们也可以把频道看作是电台,其中订阅者可以同时收听多个电台,而发送者则可以在任何电台发送消息。
常用的发布与订阅命令
命令 | 含义 |
---|---|
subscribe | subscribe channel [channel …]----订阅给定的一个或多个频道 |
unsubscribe | unsubscribe channel [channel…]----退订给定的一个或多个频道,如果执行时没有给定任何频道,那么退订所有频道 |
publish | pushlish channel [channel …]— 向给定频道发送消息 |
psubscribe | psubscribe pattern [pattern…]—订阅与给定模式相匹配的所有频道 |
punsubscribe | punsubscribe pattern [pattern …]—退订给定的模式,如果执行时没有给定任何模式,那么退订所有模式 |
很少使用Redis的发布订阅的原因
- 原因一和redis系统的稳定性有关。对于旧版Redis来说,如果一个客户端订阅了某个或某些频道,但它读取消息的速度却不够快的话,那么不断积压的消息就会使得Redis输出缓冲区的体积变的越来越大,这可能会导致Redis的速度变慢,甚至直接崩溃。也可能会导致Redis被操作系统强制杀死,甚至操作操作系统本身不可用。新版Redis不会出现这种问题,因为它会自动断开不符合 client-output-buffer-limitpubsub配置选项要求的订阅客户端。
- 原因二和数据传输的可靠性有关。任何网络系统在执行操作时都可能会遇到断线的情况,而断线产生的连续错误通常会使得网络连接两端中的其中一端进行重新连接。但是,如果客户端在执行订阅操作的过程中断线,那么客户端将会丢失在断线期间发送的所有消息。
边栏推荐
- Automated testing: a practical skill that everyone wants to know about robot framework
- 元宇宙带来的创意性改变
- 开发一个小程序商城需要多少钱?
- [论文分享] Where’s Crypto?
- 【剑指 Offer】59 - I. 滑动窗口的最大值
- 【Unity Shader】插入Pass实现模型遮挡X光透视效果
- Tips for this week 134: make_ Unique and private constructors
- 海量数据去重的hash,bitmap与布隆过滤器Bloom Filter
- SD_DATA_SEND_SHIFT_REGISTER
- What skills can you master to be a "master tester" when doing software testing?
猜你喜欢
RIP和OSPF的区别和配置命令
上市十天就下线过万台,欧尚Z6产品实力备受点赞
Tear the Nacos source code by hand (tear the client source code first)
保证接口数据安全的10种方案
More than 10000 units were offline within ten days of listing, and the strength of Auchan Z6 products was highly praised
Using stored procedures, timers, triggers to solve data analysis problems
gsap动画库
Mui side navigation anchor positioning JS special effect
< code random recording two brushes> linked list
SD_DATA_RECEIVE_SHIFT_REGISTER
随机推荐
Kubernetes DevOps CD工具对比选型
Slider plug-in for swiper left and right switching
Chapter 3 business function development (to remember account and password)
清华、剑桥、UIC联合推出首个中文事实核查数据集:基于证据、涵盖医疗社会等多个领域
回归测试的分类
[trusted computing] Lesson 10: TPM password resource management (II)
2022年理财产品的一般收益率是多少?
Tear the Nacos source code by hand (tear the client source code first)
[PaddleSeg源码阅读] PaddleSeg Validation 中添加 Boundary IoU的计算(1)——val.py文件细节提示
Tips for this week 140: constants: safety idioms
CVPR 2022丨学习用于小样本语义分割的非目标知识
C语言中匿名的最高境界
Tips of this week 141: pay attention to implicit conversion to bool
How to clean when win11 C disk is full? Win11 method of cleaning C disk
Wireshark分析抓包数据*.cap
持续测试(CT)实战经验分享
数学分析_笔记_第11章:Fourier级数
The highest level of anonymity in C language
Test for 3 months, successful entry "byte", my interview experience summary
『HarmonyOS』DevEco的下载安装与开发环境搭建