Understand Redis Pub/Sub terminology — PUBLISH and SUBSCRIBE commands, PSUBSCRIBE pattern channels, the RESP protocol push model, and how Pub/Sub differs from Redis Streams for reliable messaging.
0 / 5 completed
1 / 5
What does the Redis PUBLISH command do?
PUBLISH channel message sends a message to a channel and returns the number of clients that received it. The message is fire-and-forget — if no subscribers are connected at the time of publish, the message is lost. This distinguishes Pub/Sub from Streams, which persist messages.
2 / 5
What does PSUBSCRIBE do differently from SUBSCRIBE?
PSUBSCRIBE uses glob patterns (?, *, [chars]) to subscribe to multiple channels at once. A client running PSUBSCRIBE order.* receives messages published to order.created, order.shipped, etc. The delivered message includes the matched pattern and the actual channel name.
3 / 5
When a client issues SUBSCRIBE, what state does it enter?
After SUBSCRIBE, a Redis client enters a restricted state. The connection is dedicated to receiving Pub/Sub messages and can only issue subscription management commands. To run regular commands again, the client must UNSUBSCRIBE from all channels or use a separate connection.
4 / 5
How does Redis Pub/Sub relate to the RESP protocol?
Redis Pub/Sub operates over the standard RESP (Redis Serialisation Protocol) connection. The server pushes message arrays to subscribed clients unprompted — a 3-element array of ["message", channel, payload]. Client libraries decode these push responses and invoke registered message handlers.
5 / 5
What is the main advantage of Redis Streams over Pub/Sub for reliable messaging?
Redis Streams persist entries to an append-only log and support consumer groups where each message is delivered to one consumer and must be acknowledged with XACK. Unacknowledged messages can be reclaimed. Pub/Sub, by contrast, is ephemeral — messages published when no subscriber is listening are permanently lost.