0
0
Redisquery~20 mins

SCARD for set size in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Set Size Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1: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
A3
B1
CError: key does not exist
D0
Attempts:
2 left
💡 Hint
SCARD returns the number of elements in the set stored at the given key.
query_result
intermediate
1: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
AError: key does not exist
B0
Cnull
D-1
Attempts:
2 left
💡 Hint
SCARD returns zero if the key does not exist or is empty.
📝 Syntax
advanced
1:00remaining
Which SCARD command syntax is correct?
Identify the correct syntax to get the size of a set named fruits in Redis.
ASCARD:fruits
BSCARD(fruits)
CSCARD fruits
DSCARD = fruits
Attempts:
2 left
💡 Hint
Redis commands use space-separated arguments without parentheses or symbols.
optimization
advanced
1: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?
ASCARD users_online
BSMEMBERS users_online
CSISMEMBER users_online ""
DGET users_online
Attempts:
2 left
💡 Hint

Think about which command returns only the count without fetching all data.

🧠 Conceptual
expert
2: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 mykey
A0
Bnull
C1
DError: WRONGTYPE Operation against a key holding the wrong kind of value
Attempts:
2 left
💡 Hint
Redis commands are type-specific and will error if used on wrong data types.