Redis study notes (19) Publish and subscribe (on)

Redis publish and subscribe (pub/sub) is a message communication mode: the sender (pub) sends messages, and the subscriber (sub) receives messages. Its publish and subscribe functions are composed of commands such as PUBLISH, SUBSCRIBE, and PSUBSCRIBE.

By executing the SUBSCRIBE command, a client can subscribe to one or more channels and become subscribers of these channels: whenever another client sends a message to the subscribed channel, all subscribers of the channel will receive this message.

Be lazy today to simulate the process of publishing and subscribing.

First start the server on port 6379:

Insert picture description here
Then start three clients through the redis-cli command, two of which execute
subscribe "newit" respectively //Subscribe to the newit channel
Now we publish a message to newit on the third client:

Insert picture description here
Now observe whether the two subscribed clients receive the message:
Insert picture description here
Insert picture description here
ok received the message.

Insert picture description here

Guess you like

Origin blog.csdn.net/xuetian0546/article/details/106698185