Challenge - 5 Problems
Redis Set Size Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What is the output of SCARD on a non-empty set?
Given a Redis set stored at key myset containing the elements
{"apple", "banana", "cherry"}, what will the command SCARD myset return?Redis
SADD myset apple banana cherry SCARD myset
Attempts:
2 left
💡 Hint
SCARD returns the number of elements in the set stored at the given key.
✗ Incorrect
The SCARD command returns the number of elements in the set stored at the specified key. Since myset contains three elements, the output is 3.
❓ query_result
intermediate1:30remaining
What does SCARD return for a non-existent key?
If you run
SCARD unknownkey on a Redis database where unknownkey does not exist, what will be the output?Redis
SCARD unknownkey
Attempts:
2 left
💡 Hint
SCARD returns zero if the key does not exist or is empty.
✗ Incorrect
When the key does not exist, Redis treats it as an empty set. Therefore, SCARD returns 0.
📝 Syntax
advanced1:00remaining
Which SCARD command syntax is correct?
Identify the correct syntax to get the size of a set named
fruits in Redis.Attempts:
2 left
💡 Hint
Redis commands use space-separated arguments without parentheses or symbols.
✗ Incorrect
The correct syntax for the SCARD command is SCARD key. Parentheses, colons, or equal signs are not used.
❓ optimization
advanced1:30remaining
Efficiently checking if a Redis set is empty
You want to check if the Redis set
users_online is empty without retrieving all members. Which command is the most efficient?Attempts:
2 left
💡 Hint
Think about which command returns only the count without fetching all data.
✗ Incorrect
SCARD returns the number of elements in the set efficiently. SMEMBERS returns all members, which is costly. SISMEMBER checks for a specific member, and GET is for strings, not sets.
🧠 Conceptual
expert2:00remaining
Understanding SCARD behavior with different data types
What happens if you run
SCARD on a Redis key that holds a string value instead of a set?Redis
SET mykey "hello"
SCARD mykeyAttempts:
2 left
💡 Hint
Redis commands are type-specific and will error if used on wrong data types.
✗ Incorrect
If SCARD is run on a key holding a string, Redis returns a WRONGTYPE error because the command expects a set.