Challenge - 5 Problems
PSUBSCRIBE Pattern Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What messages does this PSUBSCRIBE receive?
Given the Redis command
PSUBSCRIBE news.*, which published messages will the subscriber receive?Redis
PSUBSCRIBE news.* PUBLISH news.sports "Sports update" PUBLISH news.weather "Weather update" PUBLISH news "General news" PUBLISH news.sports.football "Football news"
Attempts:
2 left
💡 Hint
Remember that the asterisk (*) matches any characters in the channel name after the prefix.
✗ Incorrect
The pattern 'news.*' matches any channel starting with 'news.' followed by any characters. So it matches 'news.sports', 'news.weather', and 'news.sports.football'. It does not match 'news' alone because there is no dot after 'news'.
📝 Syntax
intermediate1:30remaining
Identify the correct PSUBSCRIBE command syntax
Which of the following Redis commands correctly subscribes to all channels starting with 'chat.'?
Attempts:
2 left
💡 Hint
PSUBSCRIBE supports patterns, SUBSCRIBE does not.
✗ Incorrect
PSUBSCRIBE is used for pattern matching subscriptions. The pattern 'chat.*' matches all channels starting with 'chat.'. SUBSCRIBE does not support patterns and treats the argument as a literal channel name.
❓ optimization
advanced2:30remaining
Optimizing pattern subscriptions for multiple similar channels
You want to subscribe to all channels related to user notifications, which are named like 'user.123', 'user.456', 'user.789'. Which PSUBSCRIBE pattern is the most efficient and correct?
Attempts:
2 left
💡 Hint
Consider how Redis pattern matching works with wildcards.
✗ Incorrect
The pattern 'user.*' matches any channel starting with 'user.' followed by any characters, which covers all user notification channels. 'user.?' matches only channels with exactly one character after 'user.'. 'user.[0-9]*' requires the character immediately after 'user.' to be a digit followed by any characters, which is overly restrictive. 'user' matches only the exact channel 'user'.
🔧 Debug
advanced2:30remaining
Why does this PSUBSCRIBE pattern not receive expected messages?
A developer runs
PSUBSCRIBE user.*.notifications but does not receive messages published to 'user.123notifications'. What is the likely cause?Attempts:
2 left
💡 Hint
Check how Redis pattern matching treats the '*' wildcard.
✗ Incorrect
In Redis, the '*' wildcard matches any sequence of characters including dots. However, the pattern 'user.*.notifications' expects a literal dot after the '*', so it matches channels starting with 'user.', followed by any characters (including dots), then a dot, then 'notifications'. But since '*' can match dots, the pattern effectively expects two dots, which does not match 'user.123notifications' as expected. The correct pattern to match 'user.123notifications' is 'user.*notifications' without the extra dot.
🧠 Conceptual
expert3:00remaining
Understanding PSUBSCRIBE pattern matching behavior
Which statement correctly describes how Redis PSUBSCRIBE pattern matching works?
Attempts:
2 left
💡 Hint
Think about how the '*' wildcard behaves in Redis channel patterns.
✗ Incorrect
In Redis PSUBSCRIBE, the '*' wildcard matches any sequence of characters, including dots. Patterns are matched against the entire channel name, not just a prefix. Redis does not use regular expressions for PSUBSCRIBE patterns.