0
0
Redisquery~20 mins

UNSUBSCRIBE behavior in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis UNSUBSCRIBE Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What happens after UNSUBSCRIBE without arguments?
Consider a Redis client subscribed to channels 'news' and 'sports'. What is the output after executing UNSUBSCRIBE with no arguments?
Redis
SUBSCRIBE news sports
UNSUBSCRIBE
A1) unsubscribed from 'news' only, subscription count is 1
B1) unsubscribed from 'news', 2) unsubscribed from 'sports', 3) subscription count is 0
CError: UNSUBSCRIBE requires at least one channel
DNo output; client remains subscribed to all channels
Attempts:
2 left
💡 Hint
UNSUBSCRIBE with no arguments unsubscribes from all channels.
query_result
intermediate
2:00remaining
What is the output of UNSUBSCRIBE for a non-subscribed channel?
A Redis client is subscribed to channel 'chat'. What is the output after executing UNSUBSCRIBE news where 'news' is not subscribed?
Redis
SUBSCRIBE chat
UNSUBSCRIBE news
AError: Cannot unsubscribe from a channel not subscribed
BNo unsubscribe message; subscription count remains 1
CUnsubscribe message for 'news' with subscription count 1
DUnsubscribe message for 'chat' with subscription count 0
Attempts:
2 left
💡 Hint
UNSUBSCRIBE sends an unsubscribe message even if the client was not subscribed to the channel.
🧠 Conceptual
advanced
2:00remaining
How does UNSUBSCRIBE affect pattern subscriptions?
If a client is subscribed to channels 'a' and 'b' and also to pattern 'p*', what happens when UNSUBSCRIBE b is executed?
AUnsubscribes only from channel 'b'; pattern subscription remains active
BUnsubscribes from all channels and patterns
CUnsubscribes from channel 'b' and all pattern subscriptions
DNo effect; pattern subscriptions block UNSUBSCRIBE
Attempts:
2 left
💡 Hint
UNSUBSCRIBE affects only channel subscriptions, not pattern subscriptions.
📝 Syntax
advanced
2:00remaining
What error occurs with incorrect UNSUBSCRIBE syntax?
What error does Redis return when executing UNSUBSCRIBE 123 where 123 is a number instead of a string channel name?
ASyntax error: wrong number of arguments for 'UNSUBSCRIBE' command
BRuntime error: channel not found
CError: invalid channel name type
DNo error; Redis converts 123 to string and unsubscribes
Attempts:
2 left
💡 Hint
Redis treats all channel names as strings internally.
🔧 Debug
expert
3:00remaining
Why does UNSUBSCRIBE not reduce subscription count to zero?
A client subscribed to channels 'x', 'y' and pattern 'z*' executes UNSUBSCRIBE x y. Why does the subscription count reported remain 1 instead of 0?
ABecause pattern subscriptions are not affected by UNSUBSCRIBE and remain active
BBecause UNSUBSCRIBE only marks channels for removal but does not remove them immediately
CBecause the client must call PUNSUBSCRIBE to remove all subscriptions
DBecause UNSUBSCRIBE requires a delay before updating subscription count
Attempts:
2 left
💡 Hint
Pattern subscriptions are managed separately from channel subscriptions.