当前位置:网站首页>Redis - message publish and subscribe
Redis - message publish and subscribe
2022-08-02 00:32:00 【Even though the sunset is not as beautiful as you】
Foreword
Redis publish-subscribe (pub/sub) is a message communication model: sender (pub) sends messages and subscribers (sub) receive messages.
Redis clients can subscribe to any number of channels!

First, the implementation method:
①Commands:
These commands are widely used to build instant messaging applications, such as online chat rooms (chatroom) and real-time broadcasting, real-time reminders, etc.

②Implementation of publish and subscribe:
1. Subscriber:
127.0.0.1:6379> pingPONG127.0.0.1:6379> SUBSCRIBE dingdada #Subscribe to the channel named dingdadaReading messages... (press Ctrl-C to quit)1) "subscribe"2) "dingdada"3) (integer) 1#Waiting for push information1) "message" #message2) "dingdada" #The message from which channel3) "hello world\xef\xbc\x81" # The specific content of the message1) "message"2) "dingdada"3) "my name is dyj\x81"2. Sender:
127.0.0.1:6379> pingPONG127.0.0.1:6379> PUBLISH dingdada "hello world!" #Send message to dingdada channel(integer) 1127.0.0.1:6379> PUBLISH dingdada "my name is dyj" #Send message to dingdada channel(integer) 1As shown in the picture:
Subscriber:
Sender: 
③PSUBSCRIBE command: subscribe to the specified channel!
③PSUBSCRIBE command: subscribe to the specified channel!
④PUBLISH command: send a message to the specified channel!
PUBLISH + channel + message #Send information message to the specified channel channel⑤PUNSUBSCRIBE command: unsubscribe!
#Instructs the client to unsubscribe from the specified mode, and exits all modes if no mode is provided.
⑥SUBSCRIBE: Subscription, same as above.Don't go into details!

⑦UNSUBSCRIBE: Unsubscribe, same as above, no details!

⑧Summary:
Pub/Sub literally means Publish and Subscribe. In Redis, you can set message publishing and message subscription for a certain key value. When a message is published on a key valueAfter that, all clients that subscribe to it will receive the corresponding message.The most obvious usage of this function is as a real-time messaging system, such as ordinary instant chat, group chat and other functions.
边栏推荐
- Multidimensional Correlation Time Series Modeling Method Based on Screening Partial Least Squares Regression of Correlation Variables
- How to find new potential projects?Tools recommended
- Task execution control in Ansible
- 08-SDRAM: Summary
- What is the function of the JSP Taglib directive?
- 接地气讲解TCP协议和网络程序设计
- 06-SDRAM :SDRAM控制模块
- 2022/08/01 学习笔记 (day21) 泛型和枚举
- 基于超参数自动寻优的工控网络入侵检测
- Ansible中的任务执行控制
猜你喜欢

Routing strategy

不了解SynchronousQueue?那ArrayBlockingQueue和LinkedBlockingQueue不会也不知道吧?

Play NFT summer: this collection of tools is worth collecting

当奈飞的NFT忘记了Web2的业务安全

电机原理动图合集

TCL: Pin Constraints Using the tcl Scripting Language in Quartus

认识USB、Type-C、闪电、雷电接口

【加密周报】经济衰退在加息气氛中蔓延 美联储“放手一搏”?盘点上周加密市场发生的重大事件

nodeJs--mime模块

磁盘与文件系统管理
随机推荐
Ansible中的任务执行控制
Statement执行update语句
Disk and file system management
Double queue implementation stack?Dual stack implementation queue?
JSP out.write()方法具有什么功能呢?
面试必问的HashCode技术内幕
当奈飞的NFT忘记了Web2的业务安全
A simple file transfer tools
【无标题】
Study Notes: The Return of Machine Learning
06-SDRAM :SDRAM控制模块
go语言标准库fmt包怎么使用
测试用例:四步测试设计法
Unknown CMake command “add_action_files“
玩转NFT夏季:这份工具宝典值得收藏
SphereEx Miao Liyao: Database Mesh R&D Practice under Cloud Native Architecture
具有通信时延的多自主体系统时变参考输入的平均一致性跟踪
IP Core: FIFO
短视频seo搜索优化主要内容
22. The support vector machine (SVM), gaussian kernel function