1. Listen on a channel
SUBSCRIBE registers the client to receive every message published to the named channel.
SUBSCRIBE newsTyporithm · medium
Step 1 of 8 · intro card
Patterns
SUBSCRIBE listens on a channel and PSUBSCRIBE on a glob pattern; PUBLISH sends a message to all current subscribers as fire-and-forget with no persistence. UNSUBSCRIBE stops listening, and PUBSUB CHANNELS introspects the active channels.
Redis Pub/Sub is a lightweight messaging layer. A client calls SUBSCRIBE news to listen on a channel, or PSUBSCRIBE news.* to match a glob pattern across many channels at once.
PUBLISH news "hello" sends a message to every client subscribed at that moment. It is fire-and-forget: there is no queue and no persistence, so any message published while no one is subscribed is simply lost.
UNSUBSCRIBE stops a client from receiving further messages, and PUBSUB CHANNELS lets you introspect which channels currently have subscribers. When you need durable, replayable messages, reach for Redis Streams instead.
SUBSCRIBE for a channel; PSUBSCRIBE for a glob pattern.
PUBLISH is fire-and-forget — no persistence.
PUBSUB CHANNELS lists active channels.
SUBSCRIBE news
PSUBSCRIBE news.*
PUBLISH news "hello"
UNSUBSCRIBE news
PUBSUB CHANNELSConnect each part of the code to the concept before you type.
SUBSCRIBE registers the client to receive every message published to the named channel.
SUBSCRIBE newsPSUBSCRIBE matches a glob pattern, so news.* catches news.sports, news.tech, and so on.
PSUBSCRIBE news.*PUBLISH delivers a message to all current subscribers — fire-and-forget, with no persistence.
PUBLISH news "hello"UNSUBSCRIBE removes the client from the channel so it stops receiving messages.
UNSUBSCRIBE newsPUBSUB CHANNELS lists the channels that currently have at least one subscriber.
PUBSUB CHANNELSRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.