Introduction
Pub/sub in Redis lets programs send messages instantly, but it does not save messages for later. This means if a program is not listening when a message is sent, it will miss that message.
SUBSCRIBE channel_name PUBLISH channel_name message
SUBSCRIBE news
PUBLISH news "Hello subscribers!"SUBSCRIBE sports
PUBLISH sports "Game starts now!"# In one Redis client: SUBSCRIBE updates # In another Redis client: PUBLISH updates "New update available!"
news?SUBSCRIBE <channel>.SUBSCRIBE news subscribes to the channel named 'news'.Client A subscribes to channel 'chat'. Client B publishes message 'Hello' to 'chat'. Client C subscribes to 'chat' after the message is published.
SUBSCRIBE news PUBLISH news "Update 1"
Pass the test and this pattern moves unknown