当前位置:网站首页>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
边栏推荐
- 玩转NanoPi 2 裸机教程编程-01点亮User LED难点解析
- Redis learning notes - detailed explanation of redis benchmark
- 通用分页(1)
- Utilisation du cookie du module de demande de noeud
- Redis learning notes - data type: ordered set (Zset)
- 学习SCI论文绘制技巧(E)
- 嵌入式系统概述(学习笔记)
- General paging (1)
- How to use "tomato working method" in flowus, notation and other note taking software?
- Balls and cows of leetcode topic analysis
猜你喜欢

Flink error --caused by: org apache. calcite. sql. parser. SqlParseException: Encountered “time“

瞄准海外宠物市场,「Grasphand 」做了一款独立于手机的智能追踪产品 | 早期项目
Redis learning notes - single key management

"Coach, I want to play basketball" -- AI Learning Series booklet for students who are making systems

173. Binary Search Tree Iterator

S5P4418裸机编程的实现(替换2ndboot)

Click Add drop-down box

Aiming at the overseas pet market, "grasshand" has developed an intelligent tracking product independent of mobile phones | early project

简易学生管理
![[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
随机推荐
Redis学习笔记—数据类型:字符串(string)
125. Valid Palindrome
How postman does interface testing 1: how to import swagger interface documents
【活动报名】SOFAStack × CSDN 联合举办开源系列 Meetup ,6 月 24 日火热开启
Redis学习笔记—客户端通讯协议RESP
自定义标签——jsp标签基础
Redis learning notes - data type: Set
Use of type dependent names must be prefixed with 'typename'
Best time to buy and sell stock
Unity grid programming 06
Redis学习笔记—数据类型:哈希(hash)
Unity grid programming 08
Redis learning notes - slow query analysis
一个采用直接映射方式的32KB缓存......存储器课后习题
173. Binary Search Tree Iterator
Redis学习笔记—Pipeline
Redis学习笔记—数据类型:有序集合(zset)
Redis学习笔记—持久化机制之RDB
Longest substring without repeated characters (C language)
如何在 FlowUs、Notion 等笔记软件中使用「番茄工作法」?