0
0
Redisquery~30 mins

ZRANK and ZREVRANK for position in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Using ZRANK and ZREVRANK to Find Member Positions in Redis Sorted Sets
📖 Scenario: You are managing a leaderboard for a gaming app. Players earn points and are ranked in a Redis sorted set. You want to find the position of specific players in the leaderboard, both from the top (lowest score rank) and from the bottom (highest score rank).
🎯 Goal: Build a Redis sorted set with player scores, then use ZRANK and ZREVRANK commands to find the position of players in the leaderboard.
📋 What You'll Learn
Create a sorted set called game_leaderboard with exact score-player pairs.
Set a variable for the player name to check the rank.
Use ZRANK to find the player's rank from lowest to highest score.
Use ZREVRANK to find the player's rank from highest to lowest score.
💡 Why This Matters
🌍 Real World
Leaderboards in games, ranking users by points, or sorting items by score in real-time applications.
💼 Career
Understanding sorted sets and rank commands is essential for backend developers working with Redis to implement efficient ranking and scoring systems.
Progress0 / 4 steps
1
DATA SETUP: Create the sorted set with player scores
Use the Redis command ZADD to create a sorted set called game_leaderboard with these exact score-member pairs: 1500 "Alice", 3000 "Bob", 2250 "Charlie", 1800 "Diana", and 2700 "Eve".
Redis
Need a hint?

Use ZADD followed by the sorted set name, then pairs of score and member.

2
CONFIGURATION: Set the player name to check rank
Create a variable called player and set it to the string "Charlie" to specify the player whose rank you want to find.
Redis
Need a hint?

Assign the string "Charlie" to the variable player using Redis commands.

3
CORE LOGIC: Use ZRANK to find the player's rank from lowest to highest score
Use the Redis command ZRANK with game_leaderboard and Charlie to find the rank of "Charlie" from the lowest to highest score.
Redis
Need a hint?

ZRANK returns the zero-based rank of the member in the sorted set ordered from lowest to highest score.

4
COMPLETION: Use ZREVRANK to find the player's rank from highest to lowest score
Use the Redis command ZREVRANK with game_leaderboard and Charlie to find the rank of "Charlie" from the highest to lowest score.
Redis
Need a hint?

ZREVRANK returns the zero-based rank of the member in the sorted set ordered from highest to lowest score.