But the output is empty. What is the most likely cause?
medium
A. ZREVRANGE returns ascending order by default
B. ZREVRANGE syntax is incorrect, it needs WITHSCORES
C. ZADD commands used wrong order of arguments
D. The leaderboard key was deleted before ZREVRANGE
Solution
Step 1: Check command correctness
ZADD commands have correct syntax and add members with scores.
Step 2: Analyze empty output from ZREVRANGE
Empty output means the key 'leaderboard' likely does not exist or was deleted before ZREVRANGE.
Final Answer:
The leaderboard key was deleted before ZREVRANGE -> Option D
Quick Check:
Empty output = missing key [OK]
Hint: Empty ZREVRANGE means key missing or deleted [OK]
Common Mistakes:
Thinking WITHSCORES is required for output (it's optional)
Assuming ZREVRANGE returns ascending order
Believing ZADD argument order was wrong (it was correct)
5. You want to implement a leaderboard that shows the top 3 users but excludes any user with a score below 50. Which Redis commands or approach should you use?
hard
A. Use ZRANGEBYSCORE leaderboard 50 +inf LIMIT 0 3
B. Use ZREVRANGE leaderboard 0 2 and filter scores < 50 in application
C. Use ZREVRANGEBYSCORE leaderboard +inf 50 LIMIT 0 3
D. Use ZRANGE leaderboard 0 2 WITHSCORES and exclude scores < 50
Solution
Step 1: Understand filtering by score
We want top 3 users with scores >= 50, sorted descending.
Step 2: Choose correct Redis command
ZREVRANGEBYSCORE leaderboard +inf 50 LIMIT 0 3 returns members with scores between +inf and 50 descending, limited to 3.
Final Answer:
Use ZREVRANGEBYSCORE leaderboard +inf 50 LIMIT 0 3 -> Option C
Quick Check:
Filter by score with ZREVRANGEBYSCORE [OK]
Hint: Use ZREVRANGEBYSCORE with score limits and LIMIT [OK]
Common Mistakes:
Using ZREVRANGE without score filtering
Using ZRANGEBYSCORE which sorts ascending, not descending
Filtering scores in app instead of Redis command
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.