1 basic
Publish/Subscribe is a message communication pattern. Instead of publishing messages to subscribers, publishers publish to different channels. Subscribers accept messages of the channel they are interested in and do not need to contact the publisher.
Sub/pub are both client, and channel is server.
, the message is sent to the three sub client when the new message is posted to Channel1 via the Publish command.
2 commands
Subscribe to a channel on the CLI: Channel1
127.0.0.1:6379> SUBSCRIBE channel1reading Messages ... (Press Ctrl-c to quit) 1) "Subscribe" 2) "Channel1" 3) (integer) 1
In another CLI, publish messages to Channel1 via the Publish command
127.0.0.1:6379> PUBLISH channel1 1 (integer) 1127.0.0.1:6379> PUBLISH channel1 ' good ' (integer) 1
Already received on sub
127.0.0.1:6379> SUBSCRIBE channel1reading Messages ... (Press Ctrl-c to quit) 1) "Subscribe" 2) "Channel1" 3) (integer) one) "message" 2) "Channel1" 3) "1" 1) "message" 2) "Channel1" 3) "Good"
2-redis Pub/sub Publish a subscription