Challenge - 5 Problems
LREM Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the result of this LREM command?
Given a Redis list
mylist with elements ["apple", "banana", "apple", "cherry", "apple"], what will be the list after running LREM mylist 2 "apple"?Redis
LREM mylist 2 "apple"
Attempts:
2 left
💡 Hint
LREM removes elements equal to the value, starting from the head, up to the count specified.
✗ Incorrect
LREM with count 2 removes the first two occurrences of "apple" from the list. The original list has three "apple" elements. Removing the first two leaves one "apple" at the end.
❓ query_result
intermediate2:00remaining
What happens when LREM count is negative?
Given a Redis list
mylist with elements ["x", "y", "x", "z", "x"], what will be the list after running LREM mylist -1 "x"?Redis
LREM mylist -1 "x"
Attempts:
2 left
💡 Hint
Negative count removes elements from the tail of the list.
✗ Incorrect
LREM with count -1 removes one occurrence of "x" starting from the tail (right side). The last "x" is removed, leaving the rest intact.
📝 Syntax
advanced2:00remaining
Which LREM command syntax is correct?
Select the syntactically correct Redis LREM command to remove 3 occurrences of "orange" from list
fruits:Attempts:
2 left
💡 Hint
The count must be a number, and the value a string argument.
✗ Incorrect
The correct syntax requires the count as a number and the value as a string. Option C correctly quotes the string value and uses a numeric count.
❓ optimization
advanced2:00remaining
How to efficiently remove all occurrences of an element from a large Redis list?
You want to remove all occurrences of "blue" from a very large Redis list
colors. Which approach is most efficient?Attempts:
2 left
💡 Hint
LREM with count 0 removes all matching elements at once.
✗ Incorrect
LREM with count 0 removes all occurrences of the value in a single command, which is more efficient than multiple calls or popping and reinserting.
🔧 Debug
expert2:00remaining
Why does this LREM command not remove any elements?
Given a Redis list
pets with elements ["dog", "cat", "dog", "bird"], the command LREM pets 1 "Dog" returns 0 and the list remains unchanged. Why?Redis
LREM pets 1 "Dog"
Attempts:
2 left
💡 Hint
Check the exact spelling and case of the element to remove.
✗ Incorrect
Redis string matching is case-sensitive. "Dog" is different from "dog", so no elements are removed.