0
0
Redisquery~5 mins

ZRANK and ZREVRANK for position in Redis - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the Redis command ZRANK do?
It returns the rank (position) of a member in a sorted set, ordered from the lowest to highest score, starting at 0.
Click to reveal answer
beginner
How does ZREVRANK differ from ZRANK?
ZREVRANK returns the rank of a member in a sorted set ordered from highest to lowest score, starting at 0.
Click to reveal answer
beginner
If a member is not found in the sorted set, what do ZRANK and ZREVRANK return?
Both commands return null (or nil) if the member does not exist in the sorted set.
Click to reveal answer
intermediate
Example: Given a sorted set with members and scores: {"apple": 10, "banana": 20, "cherry": 15}, what is the result of ZRANK myset "cherry"?
The rank of "cherry" is 1 because the sorted order by score ascending is: apple(10), cherry(15), banana(20).
Click to reveal answer
intermediate
Example: Using the same sorted set, what does ZREVRANK myset "cherry" return?
The rank of "cherry" is 1 because the descending order by score is: banana(20), cherry(15), apple(10).
Click to reveal answer
What does ZRANK return if the member is the lowest scored in the sorted set?
AThe highest rank number
B1
Cnull
D0
Which command gives the rank starting from the highest score?
AZRANGE
BZRANK
CZREVRANK
DZADD
If a member is not in the sorted set, what will ZREVRANK return?
Anull
B0
CThe last rank
DAn error
Given sorted set scores: {a:5, b:10, c:15}, what is ZRANK myset "b"?
A1
Bnull
C2
D0
What is the rank of the highest scored member using ZREVRANK?
A1
B0
CThe last rank
Dnull
Explain how ZRANK and ZREVRANK determine the position of a member in a Redis sorted set.
Think about the order of scores and what 0 means.
You got /3 concepts.
    Describe a real-life example where you might use ZRANK and ZREVRANK in an application.
    Consider games or scoring systems.
    You got /3 concepts.