Hint: Use WITHSCORES exactly to get scores with members [OK]
Common Mistakes:
Misspelling WITHSCORES
Using WITHSCORE or SCORES instead
Omitting WITHSCORES when scores are needed
3. Given the sorted set myzset with members and scores: "a"=5, "b"=10, "c"=15, "d"=20, "e"=25 What is the result of ZRANGEBYSCORE myzset 10 20 LIMIT 1 2?
medium
A. ["c", "d"]
B. ["b", "c", "d"]
C. ["b", "c"]
D. ["a", "b"]
Solution
Step 1: Identify members in score range 10 to 20
Members with scores 10, 15, 20 are "b", "c", "d".
Step 2: Apply LIMIT 1 2
LIMIT 1 2 means skip 1 member, then return next 2 members. Skipping "b", next two are "c", "d".
Final Answer:
["c", "d"] -> Option A
Quick Check:
LIMIT skips then returns count [OK]
Hint: LIMIT offset count skips offset, returns count members [OK]
Common Mistakes:
Ignoring LIMIT offset and returning from start
Confusing score range with member count
Including members outside score range
4. You run the command ZRANGEBYSCORE myzset (10 20 but get an error. What is the likely cause?
medium
A. Syntax error due to missing closing parenthesis after 20.
B. Incorrect use of parentheses for exclusive range; missing closing parenthesis.
C. Command is missing the key name.
D. Missing closing parenthesis for exclusive range syntax.
Solution
Step 1: Analyze the command syntax
The command uses (10 to indicate exclusive minimum score 10, which is correct syntax.
Step 2: Identify the error
The command ends with 20 without closing parenthesis or space, causing syntax error.
Final Answer:
Syntax error due to missing closing parenthesis after 20. -> Option A
Quick Check:
Exclusive range needs parentheses on score values [OK]
Hint: Check parentheses carefully for exclusive score ranges [OK]
Common Mistakes:
Forgetting parentheses for exclusive ranges
Missing spaces between arguments
Using parentheses incorrectly around scores
5. You want to get the top 3 members with scores between 0 and 100 from sorted set myzset, including their scores, but only if their score is greater than 50. Which command achieves this?
hard
A. ZRANGEBYSCORE myzset 50 100 WITHSCORES LIMIT 0 3
B. ZRANGEBYSCORE myzset (50 100 WITHSCORES LIMIT 0 3
C. ZRANGEBYSCORE myzset [50 100 WITHSCORES LIMIT 0 3
D. ZRANGEBYSCORE myzset (50 100 LIMIT 3 WITHSCORES
Solution
Step 1: Define score range with exclusive lower bound
To get scores greater than 50, use (50 for exclusive minimum.
Step 2: Include scores and limit results
Use WITHSCORES to include scores and LIMIT 0 3 to get top 3 members.