[redis] redis’s message mechanism publish subscribe

Time:2021-4-22

At present, go fly customer service system records the mapping relationship between customer service and visitors through memory. It can not be used in distributed environment, and can only be used in a single machine. If you want to support distributed service in the future, you can consider the pub / sub mechanism of redis

1. Based on the characteristics of pub / sub, its typical use scenario is real-time messaging system, such as instant chat, group chat and other functions

2. It is also used to reduce the pressure of high concurrency I / O writing, such as a large number of log writing operations. If real-time writing log files or databases will cause I / O overload and reduce system performance, then you can use pub / sub mode. Instead of writing, you can publish a log message to the log channel, and then have a separate log program to subscribe to the log channel, Asynchronously reads log messages and writes them to a file or database

3. It can also be used to replace the message queue of list, which can be consumed by multiple consumers

 

The basic usage is:

subscriber:

Subscribe channel / / will be blocked at this time

Publisher:

Publish channel / / publish message to channel

 

 

Recommended Today

What knowledge points have I gained by using vue3.0 (1)

The front-end development is full of flowers, and one skill is not yet mature.At a loss, I don’t know what to do. I pay close attention to the small editor’s success. I feel very busy recently. I don’t have much time to write articles. Today’s article is mainly about my early studyVue3.0Some of the notes […]