Bird
Raised Fist0
Redisquery~20 mins

Real-time notification pattern in Redis - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Redis Real-time Notification Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
What is the output of this Redis PUBSUB CHANNELS command?
Assume two clients subscribe to channels 'news' and 'sports'. What does the command PUBSUB CHANNELS return?
Redis
PUBSUB CHANNELS
A["news", "sports"]
B["news"]
C[]
D["news", "sports", "weather"]
Attempts:
2 left
💡 Hint
PUBSUB CHANNELS lists all active channels with subscribers.
🧠 Conceptual
intermediate
2:00remaining
Which Redis data structure is best for storing user notification preferences in a real-time system?
You want to store which types of notifications each user wants to receive. Which Redis data structure fits best?
ASorted Set
BSet
CList
DHash
Attempts:
2 left
💡 Hint
Think about storing multiple key-value pairs per user.
📝 Syntax
advanced
2:00remaining
Which Redis command syntax correctly publishes a message to a channel?
Select the correct syntax to publish the message 'Hello' to the channel 'updates'.
APUBLISH updates Hello
BPUBLISH 'updates' 'Hello'
CPUBLISH updates 'Hello'
DPUBLISH 'updates' Hello
Attempts:
2 left
💡 Hint
Redis commands do not require quotes for simple strings.
❓ optimization
advanced
2:00remaining
How to optimize Redis Pub/Sub for high message throughput?
You have many subscribers and high message volume. Which approach improves Redis Pub/Sub performance?
AUse a single Redis instance with many channels
BUse multiple Redis instances with sharded channels
CUse Redis transactions for publishing messages
DUse Redis sorted sets to queue messages
Attempts:
2 left
💡 Hint
Distributing load helps handle more messages.
🔧 Debug
expert
3:00remaining
Why does this Redis Pub/Sub subscriber not receive messages?
A client runs SUBSCRIBE news but never receives messages published to 'news'. What is the likely cause?
Redis
Client 1: SUBSCRIBE news
Client 2: PUBLISH news "Hello"
AClient 2 used wrong channel name in PUBLISH
BRedis server is down
CClient 1 subscribed after Client 2 published the message
DClient 1 did not run SUBSCRIBE command correctly
Attempts:
2 left
💡 Hint
Messages published before subscription are not received.

Practice

(1/5)
1. What is the main purpose of the PUBLISH command in Redis real-time notification pattern?
easy
A. To store data permanently
B. To send messages to a specific channel
C. To listen for messages on a channel
D. To delete a channel

Solution

  1. Step 1: Understand the role of PUBLISH

    The PUBLISH command is used to send messages to a channel in Redis.
  2. Step 2: Differentiate from SUBSCRIBE

    SUBSCRIBE listens for messages, but PUBLISH sends them.
  3. Final Answer:

    To send messages to a specific channel -> Option B
  4. Quick Check:

    PUBLISH sends messages [OK]
Hint: PUBLISH sends, SUBSCRIBE listens [OK]
Common Mistakes:
  • Confusing PUBLISH with SUBSCRIBE
  • Thinking PUBLISH stores data
  • Assuming PUBLISH deletes channels
2. Which of the following is the correct syntax to subscribe to a channel named news in Redis?
easy
A. LISTEN news
B. PUBLISH news
C. SUBSCRIBE('news')
D. SUBSCRIBE news

Solution

  1. Step 1: Recall Redis SUBSCRIBE syntax

    The correct syntax is SUBSCRIBE channel_name without parentheses.
  2. Step 2: Check each option

    SUBSCRIBE news matches the correct syntax. SUBSCRIBE('news') uses parentheses which is invalid in Redis CLI.
  3. Final Answer:

    SUBSCRIBE news -> Option D
  4. Quick Check:

    SUBSCRIBE channel_name [OK]
Hint: SUBSCRIBE uses plain command and channel name [OK]
Common Mistakes:
  • Using parentheses like a function call
  • Confusing PUBLISH with SUBSCRIBE
  • Using LISTEN which is not a Redis command
3. Consider this Redis command sequence:
SUBSCRIBE updates
PUBLISH updates "New message arrived"
What will the subscriber receive?
medium
A. "New message arrived" on the updates channel
B. No message because SUBSCRIBE blocks commands
C. An error because PUBLISH cannot be used after SUBSCRIBE
D. The message on a different channel

Solution

  1. Step 1: Understand SUBSCRIBE behavior

    SUBSCRIBE listens to messages on the specified channel and receives published messages.
  2. Step 2: Analyze PUBLISH effect

    PUBLISH sends the message "New message arrived" to the updates channel, which the subscriber listens to.
  3. Final Answer:

    "New message arrived" on the updates channel -> Option A
  4. Quick Check:

    SUBSCRIBE receives PUBLISH messages [OK]
Hint: SUBSCRIBE gets messages published to its channel [OK]
Common Mistakes:
  • Thinking SUBSCRIBE blocks all commands
  • Believing PUBLISH causes errors after SUBSCRIBE
  • Assuming messages go to wrong channels
4. You wrote this Redis command sequence:
SUBSCRIBE updates
PUBLISH updates "Hello"
UNSUBSCRIBE updates
PUBLISH updates "Bye"
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

  1. Step 1: Understand UNSUBSCRIBE effect

    UNSUBSCRIBE removes the subscriber from the channel, so it stops receiving messages.
  2. Step 2: Analyze message delivery after UNSUBSCRIBE

    After unsubscribing, the subscriber no longer listens, so "Bye" is not received.
  3. Final Answer:

    Because UNSUBSCRIBE stops listening to the channel -> Option C
  4. 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

  1. Step 1: Understand real-time delivery needs

    Real-time notifications require instant delivery without polling delays.
  2. Step 2: Evaluate options for message delivery

    PUBLISH/SUBSCRIBE keeps clients connected and delivers messages instantly to subscribed channels.
  3. 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.
  4. Final Answer:

    Use PUBLISH/SUBSCRIBE pattern and keep subscribers connected continuously -> Option A
  5. Quick Check:

    Continuous SUBSCRIBE ensures real-time messages [OK]
Hint: Keep subscribers connected with PUBLISH/SUBSCRIBE [OK]
Common Mistakes:
  • Using polling instead of real-time subscription
  • Trying to fetch messages manually
  • Misusing transactions for message delivery
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard