Bird
Raised Fist0
Redisquery~20 mins

Range queries for scoring in Redis - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Range Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
Retrieve members with scores between 50 and 100
Given a sorted set players with player names as members and their scores as scores, which Redis command returns all players with scores between 50 and 100 inclusive?
Redis
ZADD players 30 "Alice" 60 "Bob" 90 "Charlie" 110 "Diana"
AZRANGEBYSCORE players 50 100
BZRANGE players 50 100
CZREVRANGEBYSCORE players 50 100
DZRANGEBYSCORE players (50 (100
Attempts:
2 left
💡 Hint
Use the command that filters by score range, not by rank.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this Redis range query
Which option contains a syntax error when trying to get members with scores between 20 and 80 from sorted set scores?
Redis
ZADD scores 10 "x" 30 "y" 70 "z"
AZRANGEBYSCORE scores 20 80
BZRANGEBYSCORE scores 20, 80
CZRANGEBYSCORE scores (20 80
DZRANGEBYSCORE scores 20 (80
Attempts:
2 left
💡 Hint
Check for invalid characters or separators in the command.
❓ optimization
advanced
2:00remaining
Efficiently retrieve top 5 players with scores above 90
You want to get the top 5 players with scores greater than 90 from sorted set leaderboard. Which command is the most efficient and correct?
Redis
ZADD leaderboard 85 "Anna" 92 "Ben" 95 "Cara" 99 "Dave" 100 "Eve" 88 "Fay"
AZRANGEBYSCORE leaderboard (90 +inf LIMIT 0 5
BZRANGEBYSCORE leaderboard 90 +inf LIMIT 0 5
CZREVRANGEBYSCORE leaderboard +inf (90 LIMIT 0 5
DZREVRANGEBYSCORE leaderboard +inf 90 LIMIT 0 5
Attempts:
2 left
💡 Hint
Remember that ZREVRANGEBYSCORE returns members in descending score order.
🔧 Debug
advanced
2:00remaining
Why does this range query return no results?
You run the command ZRANGEBYSCORE games 100 50 on a sorted set games with scores from 10 to 150, but get an empty list. Why?
Redis
ZADD games 10 "g1" 50 "g2" 100 "g3" 150 "g4"
AZRANGEBYSCORE only works with integer scores
BZRANGEBYSCORE requires the max score first, then min score
CThe sorted set is empty, so no results
DThe min score is greater than max score; range is invalid
Attempts:
2 left
💡 Hint
Check the order of min and max scores in the command.
🧠 Conceptual
expert
2:00remaining
Understanding exclusive and inclusive bounds in Redis range queries
Which option correctly describes the difference between ZRANGEBYSCORE key (50 100 and ZRANGEBYSCORE key 50 (100?
AThe first excludes 50 but includes 100; the second includes 50 but excludes 100
BBoth exclude 50 and 100
CThe first includes 50 and excludes 100; the second excludes 50 and includes 100
DBoth include 50 and 100
Attempts:
2 left
💡 Hint
Parentheses before a score mean exclusive bound for that score.

Practice

(1/5)
1. What does the Redis command ZRANGEBYSCORE do?
easy
A. It returns members in a sorted set within a specified score range.
B. It deletes members from a sorted set based on score.
C. It adds new members to a sorted set with scores.
D. It returns the total number of members in a sorted set.

Solution

  1. Step 1: Understand the command purpose

    ZRANGEBYSCORE is used to get members from a sorted set filtered by score range.
  2. Step 2: Compare options with command behavior

    Only "It returns members in a sorted set within a specified score range." correctly describes returning members within a score range.
  3. Final Answer:

    It returns members in a sorted set within a specified score range. -> Option A
  4. Quick Check:

    ZRANGEBYSCORE = returns members by score range [OK]
Hint: ZRANGEBYSCORE fetches members filtered by score range [OK]
Common Mistakes:
  • Confusing ZRANGEBYSCORE with commands that add or delete members
  • Thinking it returns count instead of members
  • Assuming it sorts members by name instead of score
2. Which of the following is the correct syntax to get members with scores between 10 and 20 from a sorted set named myzset?
easy
A. ZRANGEBYSCORE myzset [10 [20
B. ZRANGEBYSCORE myzset (10 (20
C. ZRANGEBYSCORE myzset 10 20
D. ZRANGEBYSCORE myzset "10" "20"

Solution

  1. Step 1: Recall basic syntax of ZRANGEBYSCORE

    The command format is ZRANGEBYSCORE key min max where min and max are numbers or special strings.
  2. Step 2: Analyze options for correct syntax

    ZRANGEBYSCORE myzset 10 20 uses plain numbers 10 and 20 correctly. Options A and B use parentheses or brackets which mean exclusive or inclusive but are not needed here. ZRANGEBYSCORE myzset "10" "20" uses quotes which are unnecessary.
  3. Final Answer:

    ZRANGEBYSCORE myzset 10 20 -> Option C
  4. Quick Check:

    Syntax = ZRANGEBYSCORE key min max [OK]
Hint: Use plain numbers for inclusive score range in ZRANGEBYSCORE [OK]
Common Mistakes:
  • Using parentheses or brackets incorrectly for inclusive ranges
  • Adding quotes around numeric scores
  • Mixing up min and max order
3. Given the sorted set myzset with members and scores: {"a":5, "b":10, "c":15, "d":20}, what is the result of ZRANGEBYSCORE myzset 10 20 WITHSCORES?
medium
A. ["b", "10", "c", "15", "d", "20"]
B. ["a", "5", "b", "10", "c", "15"]
C. ["c", "15", "d", "20"]
D. ["a", "5", "d", "20"]

Solution

  1. Step 1: Identify members with scores between 10 and 20 inclusive

    Members with scores 10, 15, and 20 are "b", "c", and "d" respectively.
  2. Step 2: Understand WITHSCORES option output

    WITHSCORES returns members and their scores as alternating elements in the list.
  3. Final Answer:

    ["b", "10", "c", "15", "d", "20"] -> Option A
  4. Quick Check:

    Members with scores 10-20 + WITHSCORES = ["b", "10", "c", "15", "d", "20"] [OK]
Hint: WITHSCORES returns member-score pairs in order [OK]
Common Mistakes:
  • Including members outside the score range
  • Returning only members without scores
  • Mixing order of members and scores
4. What is wrong with this command to get members with scores between 5 and 15 from myzset?
ZRANGEBYSCORE myzset 5 15 WITHSCORE
medium
A. The score range should be reversed as 15 5.
B. The option should be WITHSCORES, not WITHSCORE.
C. The command needs a LIMIT clause to work.
D. The key name must be quoted.

Solution

  1. Step 1: Check the option spelling

    The correct option to include scores is WITHSCORES (plural), not WITHSCORE.
  2. Step 2: Verify other parts of the command

    The score range 5 to 15 is correct, LIMIT is optional, and key names do not require quotes.
  3. Final Answer:

    The option should be WITHSCORES, not WITHSCORE. -> Option B
  4. Quick Check:

    Correct option spelling = WITHSCORES [OK]
Hint: Use WITHSCORES (plural) to get scores with members [OK]
Common Mistakes:
  • Misspelling WITHSCORES option
  • Reversing min and max scores
  • Adding unnecessary quotes around key
5. You have a sorted set players with player names and their scores. You want to find all players with scores greater than 50 but less than or equal to 100, including their scores. Which command correctly achieves this?
hard
A. ZRANGEBYSCORE players [50 100 WITHSCORES
B. ZRANGEBYSCORE players 50 100 WITHSCORES
C. ZRANGEBYSCORE players (50 (100 WITHSCORES
D. ZRANGEBYSCORE players (50 100 WITHSCORES

Solution

  1. Step 1: Understand score range requirements

    Scores must be greater than 50 (exclusive) and less than or equal to 100 (inclusive).
  2. Step 2: Use parentheses for exclusive and plain number for inclusive

    In Redis, (50 means greater than 50 (exclusive), and 100 means less than or equal to 100 (inclusive).
  3. Step 3: Check command syntax

    ZRANGEBYSCORE players (50 100 WITHSCORES correctly uses (50 and 100 with WITHSCORES option.
  4. Final Answer:

    ZRANGEBYSCORE players (50 100 WITHSCORES -> Option D
  5. Quick Check:

    Exclusive lower bound uses (number) syntax [OK]
Hint: Use (number for exclusive, number for inclusive in range [OK]
Common Mistakes:
  • Using brackets [] which Redis does not support for range
  • Not using parentheses for exclusive bounds
  • Confusing inclusive and exclusive range syntax
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard