当前位置:网站首页>Redis learning notes - publish and subscribe
Redis learning notes - publish and subscribe
2022-06-23 09:11:00 【Love Guoba】
Redis Provides the basis for “ Release / subscribe ” Message mechanism of pattern , In this mode , Message publishers and subscribers do not communicate directly , The publisher client sends the specified channel (channel) Release the news , Every client subscribing to this channel can receive this message
And many professional message queuing systems ( for example Kafka、RocketMQ) comparison ,Redis Publish / subscribe is a bit rough , For example, message stacking and backtracking cannot be realized . But it's simple enough , If the current scene can tolerate these shortcomings , It's a good choice
Redis It mainly provides information release 、 Subscribed Channels 、 Unsubscribe and subscribe and unsubscribe according to the mode ;
Release the news
publish channel message
Release a "channel:sports" Sports Channel News "James in Los Angeles"
127.0.0.1:6379> publish channel:sports "James in Los Angeles"
(integer) 0
Subscribe to news
subscribe channel [channel ...]
You can subscribe to multiple messages
Subscribe to this sports channel
127.0.0.1:6379> subscribe channel:sports
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channel:sports"
3) (integer) 1
At this point, a new client will release a message to this channel
127.0.0.1:6379> publish channel:sports "Harden in Houston"
(integer) 1
At this time, the subscriber will be pushed by the news just released
127.0.0.1:6379> subscribe channel:sports
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channel:sports"
3) (integer) 1
1) "message"
2) "channel:sports"
3) "Harden in Houston"
- The client enters the subscription state after executing the subscription command , receive calls only subscribe、psubscribe、unsubscribe、punsubscribe The four orders of
- New subscription client , Unable to receive previous messages from this channel , because Redis No persistence of published messages
Unsubscribe
unsubscribe channel [channel ...]
Unsubscribe from the sports channel
127.0.0.1:6379> unsubscribe channel:sports
1) "unsubscribe"
2) "channel:sports"
3) (integer) 0
Subscribe and unsubscribe according to the pattern
psubscribe pattern [pattern...]
punsubscribe [pattern [pattern ...]]
Subscribe to it All the channels at the beginning
127.0.0.1:6379> psubscribe it*
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "it*"
3) (integer) 1
Query subscription
1. View active channels
pubsub channels [pattern]
Being active means that at least one person subscribes , among [pattern] Yes, you can specify specific patterns
127.0.0.1:6379> pubsub channels
1) "channel:sports"
2. View channel subscriptions
pubsub numsub [channel ...]
Inquire about channel:sports Number of channel subscriptions is 1 individual
127.0.0.1:6379> pubsub numsub channel:sports
1) "channel:sports"
2) (integer) 1
3. View the number of mode subscriptions
pubsub numpat
Currently subscribed through the mode are 1 A client
127.0.0.1:6379> pubsub numpat
(integer) 1
边栏推荐
- 4sum of leetcode topic analysis
- JS mask important data of ID card and mobile phone number with * *
- 在小程序中实现视频通话及互动直播的一种方法
- [qnx hypervisor 2.2 user manual]6.1 using the QNX hypervisor system
- 'coach, I want to play basketball!'—— AI Learning Series booklet for system students
- Mysql 数据库入门总结
- Ionic5 form input box and radio button
- 【NanoPi2试用体验】裸机第一步
- How postman does interface testing 1: how to import swagger interface documents
- Unity grid programming 06
猜你喜欢

Quartz Crystal Drive Level Calculation

297. Serialize and Deserialize Binary Tree
![[event registration] sofastack × CSDN jointly held the open source series meetup, which was launched on June 24](/img/e1/97c92290a2a5e68f05cdbd5bf525e8.png)
[event registration] sofastack × CSDN jointly held the open source series meetup, which was launched on June 24

【云原生 | Kubernetes篇】Kubernetes原理与安装(二)

Redis学习笔记—持久化机制之RDB

In depth interpretation of poca smart contract platform gear: the road to parallel architecture public chain

Learn SCI thesis drawing skills (E)
Redis学习笔记—Redis与Lua

js 用**遮罩身份证以及手机号的重要数据

Community article | mosn building subset optimization ideas sharing
随机推荐
Tencent cloud arm server evaluation practice
Servlet-02 生命周期
36氪首发|云原生数据库公司「拓数派」完成新一轮战略融资,估值已达准独角兽级别
An idea of using keep alive to cache data in vue3 form pages
Redis学习笔记—Redis与Lua
Jog运动模式
Utilisation du cookie du module de demande de noeud
“教练,我想打篮球“ —— 给做系统的同学们准备的 AI 学习系列小册
Redis学习笔记—数据类型:有序集合(zset)
Click Add drop-down box
[qnx hypervisor 2.2 user manual]6.2 network
Which is better, semrush or ahrefs? Which is more suitable for GoogleSEO keyword analysis
RGB与CMYK颜色模式
How to use matrix analysis to build your thinking scaffold in flowus, notation and other note taking software
16.系统启动流程
Cookie和Session入门
栈(Stack)的链式实现详解----线性结构
Zone d'entrée du formulaire ionic5 et boutons radio
ionic5表单输入框和单选按钮
C#之Lambda不得不说的用法