0
0
Redisquery~20 mins

ZRANGE and ZREVRANGE for reading in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sorted Set Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this ZRANGE command?
Given a sorted set myzset with elements {"one":1, "two":2, "three":3, "four":4}, what does the command ZRANGE myzset 1 2 return?
Redis
ZRANGE myzset 1 2
A["four", "three"]
B["three", "four"]
C["two", "three"]
D["one", "two"]
Attempts:
2 left
💡 Hint
ZRANGE returns elements by rank starting at 0, inclusive.
query_result
intermediate
2:00remaining
What is the output of this ZREVRANGE command?
Given a sorted set myzset with elements {"one":1, "two":2, "three":3, "four":4}, what does the command ZREVRANGE myzset 0 1 return?
Redis
ZREVRANGE myzset 0 1
A["four", "three"]
B["one", "two"]
C["three", "two"]
D["two", "one"]
Attempts:
2 left
💡 Hint
ZREVRANGE returns elements by rank in descending order starting at 0.
📝 Syntax
advanced
2:00remaining
Which command correctly returns elements with scores included?
You want to get elements and their scores from myzset using ZRANGE. Which command is correct?
AZRANGE myzset 0 -1 WITHSCORE
BZRANGE myzset 0 -1 WITHSCORES
CZRANGE myzset 0 -1 WITH SCORES
DZRANGE myzset 0 -1 SCORES
Attempts:
2 left
💡 Hint
The option to include scores is a single word.
optimization
advanced
2:00remaining
How to efficiently get the top 3 highest scored elements with scores?
Which command is the most efficient to get the top 3 elements with highest scores and their scores from myzset?
AZREVRANGE myzset 0 2 WITHSCORES
BZRANGE myzset -3 -1 WITHSCORES
CZRANGE myzset 0 2 WITHSCORES
DZREVRANGE myzset -3 -1 WITHSCORES
Attempts:
2 left
💡 Hint
Top highest means descending order starting at 0.
🧠 Conceptual
expert
2:00remaining
What happens if you use negative indexes in ZRANGE?
Given myzset with 5 elements, what does ZRANGE myzset -3 -1 return?
Redis
ZRANGE myzset -3 -1
AReturns an empty list
BReturns the first 3 elements in ascending order
CRaises a syntax error
DReturns the last 3 elements in ascending order
Attempts:
2 left
💡 Hint
Negative indexes count from the end backwards.