Why does the subscriber not receive the "Bye" message?
medium
A. Because SUBSCRIBE blocks PUBLISH commands
B. Because PUBLISH only works before SUBSCRIBE
C. Because UNSUBSCRIBE stops listening to the channel
D. Because messages are lost after first publish
Solution
Step 1: Understand UNSUBSCRIBE effect
UNSUBSCRIBE removes the subscriber from the channel, so it stops receiving messages.
Step 2: Analyze message delivery after UNSUBSCRIBE
After unsubscribing, the subscriber no longer listens, so "Bye" is not received.
Final Answer:
Because UNSUBSCRIBE stops listening to the channel -> Option C
Quick Check:
UNSUBSCRIBE stops message reception [OK]
Hint: UNSUBSCRIBE stops listening, no more messages [OK]
Common Mistakes:
Thinking PUBLISH only works before SUBSCRIBE
Assuming messages are lost after first publish
Believing SUBSCRIBE blocks PUBLISH commands
5. You want to build a real-time notification system using Redis where multiple users subscribe to different channels. Which approach ensures users only get messages for their subscribed channels without missing any messages?
hard
A. Use PUBLISH/SUBSCRIBE pattern and keep subscribers connected continuously
B. Use Redis lists to push messages and clients poll periodically
C. Use PUBLISH to send messages and clients fetch keys manually
D. Use Redis transactions to lock channels during message send
Solution
Step 1: Understand real-time delivery needs
Real-time notifications require instant delivery without polling delays.
Step 2: Evaluate options for message delivery
PUBLISH/SUBSCRIBE keeps clients connected and delivers messages instantly to subscribed channels.
Step 3: Compare with alternatives
Polling (Use Redis lists to push messages and clients poll periodically) causes delays; fetching keys manually (Use PUBLISH to send messages and clients fetch keys manually) is inefficient; transactions (Use Redis transactions to lock channels during message send) do not help with message delivery.
Final Answer:
Use PUBLISH/SUBSCRIBE pattern and keep subscribers connected continuously -> Option A