Challenge - 5 Problems
Sorted Set Ranking Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Retrieve top 3 players by score using sorted sets
Given a Redis sorted set named
game_scores where the score is the player's points, which command returns the top 3 players with the highest scores?Redis
ZADD game_scores 1500 player1 1800 player2 1200 player3 2000 player4 1700 player5
Attempts:
2 left
💡 Hint
Remember that sorted sets are ordered by score ascending by default.
✗ Incorrect
ZRANGE returns elements with lowest scores first. To get highest scores first, use ZREVRANGE.
🧠 Conceptual
intermediate1:30remaining
Why use sorted sets for ranking?
Why are Redis sorted sets ideal for implementing ranking systems?
Attempts:
2 left
💡 Hint
Think about how rankings depend on scores and order.
✗ Incorrect
Sorted sets keep elements unique and sorted by numeric scores, enabling efficient rank queries.
📝 Syntax
advanced1:30remaining
Identify the correct syntax to increment a player's score
Which Redis command correctly increments the score of
player3 by 250 in the sorted set game_scores?Attempts:
2 left
💡 Hint
Look for the command that increments scores in sorted sets.
✗ Incorrect
ZINCRBY increments the score of a member by a given amount.
❓ optimization
advanced2:00remaining
Efficiently retrieving ranks of multiple players
You want to get the ranks of
player1, player2, and player3 in game_scores. Which approach is most efficient?Attempts:
2 left
💡 Hint
Minimize round-trip calls to Redis.
✗ Incorrect
Batching with Lua script reduces network overhead and improves performance.
🔧 Debug
expert2:30remaining
Why does this ranking query return unexpected results?
You run
ZREVRANGE game_scores 0 4 but the top player is missing. The sorted set contains players with scores 1000, 1500, 2000, 2500, and 3000. What is the most likely cause?Attempts:
2 left
💡 Hint
Check how Redis treats scores internally.
✗ Incorrect
Redis sorted set scores must be numeric doubles. Non-numeric strings passed as scores cause ZADD to fail (error: invalid double), preventing the top player from being added.