当前位置:网站首页>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配置选项要求的订阅客户端。
- 原因二和数据传输的可靠性有关。任何网络系统在执行操作时都可能会遇到断线的情况,而断线产生的连续错误通常会使得网络连接两端中的其中一端进行重新连接。但是,如果客户端在执行订阅操作的过程中断线,那么客户端将会丢失在断线期间发送的所有消息。
边栏推荐
- Tear the Nacos source code by hand (tear the client source code first)
- Disk storage chain B-tree and b+ tree
- 直播软件搭建,canvas文字加粗
- 现货白银分析中的一些要点
- Afghan interim government security forces launched military operations against a hideout of the extremist organization "Islamic state"
- AI defeated mankind and designed a better economic mechanism
- Personal best practice demo sharing of enum + validation
- Five network IO models
- 上市十天就下线过万台,欧尚Z6产品实力备受点赞
- Sanxian Guidong JS game source code
猜你喜欢
数学分析_笔记_第11章:Fourier级数
String type, constant type and container type of go language
Idea completely uninstalls installation and configuration notes
【Unity Shader】插入Pass实现模型遮挡X光透视效果
Wireshark分析抓包数据*.cap
Introduction of common API for socket programming and code implementation of socket, select, poll, epoll high concurrency server model
能同时做三个分割任务的模型,性能和效率优于MaskFormer!Meta&UIUC提出通用分割模型,性能优于任务特定模型!开源!...
SD_DATA_RECEIVE_SHIFT_REGISTER
Mui side navigation anchor positioning JS special effect
[4500 word summary] a complete set of skills that a software testing engineer needs to master
随机推荐
[demo] circular queue and conditional lock realize the communication between goroutines
云安全日报220707:思科Expressway系列和网真视频通信服务器发现远程攻击漏洞,需要尽快升级
Disk storage chain B-tree and b+ tree
Wireshark analyzes packet capture data * cap
【蓝桥杯集训100题】scratch从小到大排序 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第17题
The highest level of anonymity in C language
nest.js入门之 database
手撕Nacos源码(先撕客户端源码)
Tear the Nacos source code by hand (tear the client source code first)
Live broadcast software construction, canvas Text Bold
开发一个小程序商城需要多少钱?
低代码助力企业数字化转型会让程序员失业?
socket编程之常用api介绍与socket、select、poll、epoll高并发服务器模型代码实现
Tips of this week 135: test the contract instead of implementation
AI defeated mankind and designed a better economic mechanism
同消费互联网的较为短暂的产业链不同,产业互联网的产业链是相当漫长的
[trusted computing] Lesson 13: TPM extended authorization and key management
Ten thousand words nanny level long article -- offline installation guide for datahub of LinkedIn metadata management platform
PHP面试题 foreach($arr as &$value)与foreach($arr as $value)的用法
Idea completely uninstalls installation and configuration notes