Publish and subscribe is a message communication mode.
Redis publish and subscribe (pub / sub) implements a messaging system, and the sender (called the publisher in redis terms) sends the message when the receiver (subscriber) receives the message. The link that carries the message is called the channel
principle
当发布消息到频道后,消息会加到对应频道的列表中。简单使用,实际使用中,可以用MQ中间件。
举例:
打开两个客户端:
一个申请:SUBSCRIBE mychannel
一个发送:PUBLISH mychannel "hello, redis"
在申请端会看到如下消息:
1) "message" #消息
2) "mychannel" #哪个频道消息
3) "hello, redis" #消息具体内容