Redis › Pub/Sub

How do you subscribe to and publish messages on a specific Redis channel?

Beginner

Answer

You use the SUBSCRIBE command with a channel name to start listening for messages on that channel, and the PUBLISH command with a channel name and message content from a different client to send a message that all current subscribers of that channel will immediately receive.
SUBSCRIBE weather_updates
PUBLISH weather_updates 'Storm warning issued for the area'
Real-world example A weather alert system publishes severe weather warnings to a dedicated channel, instantly notifying every subscribed application or device that is currently listening for updates.

Common follow-ups: What happens to a client's subscription if it disconnects and reconnects?;Can you unsubscribe from a channel without disconnecting entirely?