Hint: Count indexes starting at 0 to pick correct slice [OK]
Common Mistakes:
Including index 0 when start is 1
Using stop index as exclusive instead of inclusive
Confusing element order
4. You run LRANGE mylist 2 0 on a Redis list. What is the problem with this command?
medium
A. The start index is greater than the stop index, so it returns an empty list.
B. Syntax error because indexes must be positive.
C. It returns the entire list ignoring indexes.
D. It deletes elements from index 0 to 2.
Solution
Step 1: Check index order in LRANGE
LRANGE expects start index less than or equal to stop index to return elements.
Step 2: Analyze given indexes
Start is 2, stop is 0, so start > stop, which returns an empty list.
Final Answer:
The start index is greater than the stop index, so it returns an empty list. -> Option A
Quick Check:
Start > stop means empty result [OK]
Hint: Start index must be ≤ stop index to get results [OK]
Common Mistakes:
Assuming negative indexes are invalid syntax
Expecting reversed range to return elements
Confusing LRANGE with deletion commands
5. You have a Redis list logs with 11 elements. You want to get the last 5 elements using LRANGE. Which command is correct?
hard
A. LRANGE logs -5 -1
B. LRANGE logs 4 8
C. LRANGE logs 5 9
D. LRANGE logs -4 0
Solution
Step 1: Understand negative indexes in LRANGE
Negative indexes count from the end: -1 is last element, -5 is fifth from last.
Step 2: Select last 5 elements using negative indexes
LRANGE logs -5 -1 returns elements from fifth last to last, i.e., last 5 elements.
Step 3: Check other options
LRANGE logs 5 9 uses positive indexes 5 to 9 which gets elements 5-9, but for 11 elements the last 5 are indexes 6-10, so incorrect. Negative indexes are safer if length changes.
Final Answer:
LRANGE logs -5 -1 -> Option A
Quick Check:
Negative indexes -5 to -1 = last 5 elements [OK]
Hint: Use negative indexes -5 to -1 for last 5 elements safely [OK]
Common Mistakes:
Using wrong negative indexes like -4 to 0
Confusing zero-based positive indexes with negative
Assuming LRANGE excludes stop index
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.