LREM
LREM key count element
- Available since:
- Redis Open Source 1.0.0
- Time complexity:
- O(N+M) where N is the length of the list and M is the number of elements removed.
- ACL categories:
-
@write,@list,@slow, - Compatibility:
- Redis Software and Redis Cloud compatibility
Removes the first count occurrences of elements equal to element from the list
stored at key.
The count argument influences the operation in the following ways:
count > 0: Remove elements equal toelementmoving from head to tail.count < 0: Remove elements equal toelementmoving from tail to head.count = 0: Remove all elements equal toelement.
For example, LREM list -2 "hello" will remove the last two occurrences of
"hello" in the list stored at key.
Note that non-existing keys are treated like empty lists, so when key does not
exist, the command will always return 0.
Required arguments
key
The name of the key that holds the list.
count
The number of matching elements to remove and the direction: a positive value removes from the head, a negative value from the tail, and 0 removes all matches.
element
The value to remove.
Examples
Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Standard |
✅ Standard |
Return information
Integer reply: the number of removed elements.