Recall & Review
beginner
What does the Redis command
ZRANGE do?It returns a range of members in a sorted set, ordered from the lowest to the highest score.
Click to reveal answer
beginner
How does
ZREVRANGE differ from ZRANGE?ZREVRANGE returns members in a sorted set ordered from the highest to the lowest score, reversing the order of ZRANGE.Click to reveal answer
beginner
What do the start and stop parameters in
ZRANGE key start stop represent?They specify the index range of elements to return, where 0 is the first element, 1 the second, and so on. Negative numbers count from the end (-1 is last).
Click to reveal answer
intermediate
How can you include the scores of members when using
ZRANGE or ZREVRANGE?Add the
WITHSCORES option to the command to get each member's score along with the member.Click to reveal answer
beginner
If you want to get the top 3 highest scored members from a sorted set, which command would you use?
Use
ZREVRANGE key 0 2 to get the first 3 members with the highest scores.Click to reveal answer
What order does
ZRANGE return members from a sorted set?✗ Incorrect
ZRANGE returns members ordered by increasing score, from lowest to highest.
Which command returns members from highest to lowest score?
✗ Incorrect
ZREVRANGE returns members ordered from highest to lowest score.
What does the
WITHSCORES option do when used with ZRANGE or ZREVRANGE?✗ Incorrect
WITHSCORES returns each member along with its score.
If you want the last 2 members in a sorted set using
ZRANGE, what start and stop values do you use?✗ Incorrect
Negative indexes count from the end, so -2 -1 gets the last two members.
Which command would you use to get the top 5 lowest scored members?
✗ Incorrect
ZRANGE key 0 4 returns the first 5 members with the lowest scores.
Explain how
ZRANGE and ZREVRANGE commands work in Redis sorted sets.Think about the order and how you specify which members to get.
You got /4 concepts.
Describe how to retrieve the top 3 highest scored members from a Redis sorted set including their scores.
Remember ZREVRANGE reverses the order to highest first.
You got /3 concepts.