0
0
Redisquery~5 mins

PUBLISH to channels in Redis - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the PUBLISH command do in Redis?
The PUBLISH command sends a message to all subscribers of a given channel. It is used to broadcast messages in Redis's pub/sub system.
Click to reveal answer
beginner
How do subscribers receive messages in Redis?
Subscribers use the SUBSCRIBE command to listen to channels. When a message is published to those channels, subscribers receive the message instantly.
Click to reveal answer
beginner
What is the syntax of the PUBLISH command?
PUBLISH <channel> <message> — where <channel> is the name of the channel and <message> is the text to send.
Click to reveal answer
intermediate
Can PUBLISH send messages to multiple channels at once?
No, PUBLISH sends a message to one channel at a time. To send to multiple channels, you must call PUBLISH separately for each channel.
Click to reveal answer
intermediate
What happens if no clients are subscribed to a channel when a message is published?
The message is simply discarded. Redis does not store messages for channels; only active subscribers receive messages.
Click to reveal answer
What command do you use to send a message to subscribers in Redis?
APUBLISH
BSUBSCRIBE
CGET
DSET
If no clients are subscribed to a channel, what happens to a published message?
AIt is stored for later delivery
BIt is discarded
CIt is sent to all channels
DIt triggers an error
Which command do clients use to listen to messages on a channel?
ASUBSCRIBE
BPUBLISH
CUNSUBSCRIBE
DDEL
Can the PUBLISH command send a message to multiple channels in one call?
AYes, by listing channels separated by commas
BYes, but only in Redis Cluster
CYes, by using a wildcard
DNo, only one channel per PUBLISH call
What is the correct syntax to publish 'hello' to channel 'news'?
APUBLISH 'hello' news
BSUBSCRIBE news hello
CPUBLISH news hello
DSEND news hello
Explain how Redis pub/sub works with PUBLISH and SUBSCRIBE commands.
Think of a radio station broadcasting to listeners.
You got /4 concepts.
    Describe what happens when you publish a message to a channel with no subscribers.
    Imagine shouting in an empty room.
    You got /4 concepts.