0
0
Redisquery~5 mins

LREM for element removal in Redis - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the LREM command do in Redis?
LREM removes elements from a list that match a given value. You specify how many matching elements to remove and the value to remove.
Click to reveal answer
intermediate
How does the count parameter affect the LREM command?
The count parameter controls how many matching elements to remove: positive count removes from head to tail, negative count removes from tail to head, zero removes all matching elements.
Click to reveal answer
beginner
Syntax of the LREM command?
LREM key count value Example: LREM mylist 2 "apple" removes up to 2 occurrences of "apple" from the list named mylist.
Click to reveal answer
beginner
What happens if count is zero in LREM?
If count is zero, LREM removes all elements equal to the given value from the list.
Click to reveal answer
beginner
Can LREM remove elements that do not exist in the list?
No, LREM only removes elements that match the value. If no elements match, the list remains unchanged and the command returns 0.
Click to reveal answer
What does LREM mylist 3 "orange" do?
ARemoves up to 3 occurrences of "orange" from the head of mylist
BRemoves all occurrences of "orange" from mylist
CRemoves 3 elements from the tail of mylist regardless of value
DAdds 3 "orange" elements to mylist
What does LREM mylist -2 "banana" do?
ARemoves all "banana" elements from mylist
BRemoves 2 "banana" elements from the head of mylist
CRemoves 2 "banana" elements from the tail of mylist
DRemoves 2 elements from mylist regardless of value
If count is zero in LREM, what happens?
AThe list is cleared
BOnly the first matching element is removed
CNo elements are removed
DAll matching elements are removed
What does LREM return?
AThe removed elements themselves
BThe number of elements removed
CThe new length of the list
DAlways 0
If the value does not exist in the list, what does LREM do?
ADoes nothing and returns 0
BRemoves the first element anyway
CRemoves all elements
DThrows an error
Explain how the count parameter affects the behavior of the LREM command in Redis.
Think about direction and how many elements are removed.
You got /3 concepts.
    Describe a real-life example where you might use LREM to remove elements from a Redis list.
    Imagine a list of things you want to update by removing some items.
    You got /3 concepts.