Challenge - 5 Problems
Redis Set Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What is the result of adding members with SADD?
You have an empty Redis set named
fruits. You run the command SADD fruits apple banana apple. What is the return value of this command?Redis
SADD fruits apple banana apple
Attempts:
2 left
💡 Hint
SADD adds only unique members and returns the number of new elements added.
✗ Incorrect
The command adds 'apple' and 'banana' to the set. 'apple' is repeated but only counted once. So 2 new members are added.
❓ query_result
intermediate1:30remaining
What happens when removing members with SREM?
Given a Redis set
colors containing {red, green, blue}, what does the command SREM colors green yellow return?Redis
SREM colors green yellow
Attempts:
2 left
💡 Hint
SREM returns the number of members actually removed from the set.
✗ Incorrect
Only 'green' exists in the set and is removed. 'yellow' does not exist, so only 1 member is removed.
📝 Syntax
advanced1:30remaining
Which SADD command is syntactically correct?
Choose the correct syntax to add multiple members to a Redis set named
pets:Attempts:
2 left
💡 Hint
Redis commands list members separated by spaces without brackets or quotes.
✗ Incorrect
Option C uses the correct syntax: command name, key, then members separated by spaces.
❓ query_result
advanced2:00remaining
What is the set content after SADD and SREM commands?
Starting with an empty set
1.
2.
3.
What members does the set
numbers, you run these commands in order:1.
SADD numbers 1 2 3 42.
SREM numbers 2 53.
SADD numbers 5 6What members does the set
numbers contain now?Redis
SADD numbers 1 2 3 4 SREM numbers 2 5 SADD numbers 5 6
Attempts:
2 left
💡 Hint
Remember SREM removes only existing members; SADD adds unique members.
✗ Incorrect
After first SADD: {1,2,3,4}. SREM removes 2 (exists) and 5 (does not exist), so set is {1,3,4}. Then SADD adds 5 and 6, final set is {1,3,4,5,6}.
🧠 Conceptual
expert2:00remaining
Why does SADD return 0 sometimes?
You run
SADD animals dog cat on a set that already contains {dog, cat}. What does the return value 0 mean in this context?Attempts:
2 left
💡 Hint
SADD returns the count of new unique members added, not total members.
✗ Incorrect
If all members are already in the set, SADD returns 0 indicating no new additions.