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?✗ Incorrect
ZRANK ranks from lowest to highest score starting at 0, so the lowest scored member has rank 0.Which command gives the rank starting from the highest score?
✗ Incorrect
ZREVRANK ranks members from highest to lowest score.If a member is not in the sorted set, what will
ZREVRANK return?✗ Incorrect
Both
ZRANK and ZREVRANK return null if the member is missing.Given sorted set scores: {a:5, b:10, c:15}, what is
ZRANK myset "b"?✗ Incorrect
Sorted ascending: a(5), b(10), c(15). "b" is at position 1.
What is the rank of the highest scored member using
ZREVRANK?✗ Incorrect
ZREVRANK starts ranking from highest score at 0.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.