Redis發布/訂閱

Redis實現了發布/訂閱消息傳遞機制。

它的概念很簡單:發布者在頻道上發送消息。多個訂戶收到它。

訂閱頻道使用

SUBSCRIBE <channel>

Publish to a channel using

PUBLISH <channel> <message>

Example:

SUBSCRIBE dogs

In another redis-cli window, type:

PUBLISH dogs "Roger"

Messages will be sent to the subscribers, and they’ll by default display the kind of event, the channel, and the message:

Subscribers can listen on multiple channels:

SUBSCRIBE dogs cats

and will receive messages coming from all of them.


More redis tutorials: