Given a Redis sorted set game_leaderboard where player scores are stored, which command returns the top 3 players with the highest scores?
ZADD game_leaderboard 1500 player1 1800 player2 1200 player3 2000 player4 1700 player5
Remember that higher scores mean higher rank, and ZREVRANGE returns elements from highest to lowest score.
ZREVRANGE returns elements in descending order of score. Using 0 2 gets the top 3 players. WITHSCORES includes their scores in the output.
Which Redis command correctly increases the score of player3 by 300 points in the game_leaderboard sorted set?
Look for the command that increments a member's score by a given amount.
ZINCRBY increments the score of a member in a sorted set by the specified amount. The syntax is ZINCRBY key increment member.
Which option contains a syntax error when trying to get the rank of player2 in game_leaderboard?
Check the order of arguments for the rank commands.
ZRANK and ZREVRANK require the sorted set key first, then the member. Option C reverses this order, causing a syntax error.
Which Redis command efficiently retrieves players ranked from 5 to 10 (inclusive) with their scores from game_leaderboard, sorted from highest to lowest score?
Remember that ranks start at 0 and ZREVRANGE returns highest scores first.
Ranks start at 0, so rank 5 is index 4. ZREVRANGE returns members from highest to lowest score. Using 4 9 gets ranks 5 to 10.
Consider this Redis command intended to update player6's score to 2500 in game_leaderboard:
ZINCRBY game_leaderboard 2500 player6
Why might this command not set player6's score to exactly 2500?
Think about what ZINCRBY does to the score value.
ZINCRBY increases the current score by the given increment. It does not set the score to that value. To set a score directly, use ZADD with the new score.