0
0
Redisquery~20 mins

ZRANK and ZREVRANK for position in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sorted Set Rank Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Find the rank of a member using ZRANK
Given a sorted set with members and scores, what is the rank of member 'apple' using ZRANK?
Redis
ZADD fruits 10 apple 20 banana 15 cherry
ZRANK fruits apple
A1
B2
C0
Dnil
Attempts:
2 left
💡 Hint
ZRANK returns the zero-based rank of the member ordered from lowest to highest score.
query_result
intermediate
2:00remaining
Find the reverse rank of a member using ZREVRANK
Given a sorted set with members and scores, what is the reverse rank of member 'banana' using ZREVRANK?
Redis
ZADD fruits 10 apple 20 banana 15 cherry
ZREVRANK fruits banana
A0
B1
C2
Dnil
Attempts:
2 left
💡 Hint
ZREVRANK returns the zero-based rank of the member ordered from highest to lowest score.
📝 Syntax
advanced
2:00remaining
Identify the error in using ZRANK with a non-existing member
What is the output of the command ZRANK fruits orange if 'orange' is not a member of the sorted set?
Redis
ZADD fruits 10 apple 20 banana 15 cherry
ZRANK fruits orange
A-1
B0
CError: member not found
Dnil
Attempts:
2 left
💡 Hint
ZRANK returns nil if the member does not exist in the sorted set.
query_result
advanced
2:00remaining
Compare ZRANK and ZREVRANK outputs
Given the sorted set fruits with scores, what are the outputs of ZRANK fruits cherry and ZREVRANK fruits cherry?
Redis
ZADD fruits 10 apple 20 banana 15 cherry
ZRANK fruits cherry
ZREVRANK fruits cherry
AZRANK: 1, ZREVRANK: 1
BZRANK: 2, ZREVRANK: 0
CZRANK: 1, ZREVRANK: 0
DZRANK: 0, ZREVRANK: 2
Attempts:
2 left
💡 Hint
ZRANK orders from lowest to highest score, ZREVRANK from highest to lowest.
🧠 Conceptual
expert
3:00remaining
Understanding rank behavior with duplicate scores
If a sorted set has members with duplicate scores, how does ZRANK determine the rank of a member?
AZRANK returns the average rank of all members with the same score.
BZRANK orders members with the same score lexicographically and returns the zero-based rank accordingly.
CZRANK returns the highest rank among members with the same score.
DZRANK returns a random rank among members with the same score.
Attempts:
2 left
💡 Hint
Redis sorts members with the same score by their member name in alphabetical order.