--- acl_categories: - '@write' - '@list' - '@slow' arguments: - display_text: key key_spec_index: 0 name: key type: key - display_text: count name: count type: integer - display_text: element name: element type: string arity: 4 categories: - docs - develop - stack - oss - rs - rc - oss - kubernetes - clients command_flags: - write complexity: O(N+M) where N is the length of the list and M is the number of elements removed. description: Removes elements from a list. Deletes the list if the last element was removed. group: list hidden: false key_specs: - RW: true begin_search: spec: index: 1 type: index delete: true find_keys: spec: keystep: 1 lastkey: 0 limit: 0 type: range linkTitle: LREM railroad_diagram: /images/railroad/lrem.svg since: 1.0.0 summary: Removes elements from a list. Deletes the list if the last element was removed. syntax_fmt: LREM key count element title: LREM --- 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 to `element` moving from head to tail. * `count < 0`: Remove elements equal to `element` moving from tail to head. * `count = 0`: Remove all elements equal to `element`. For example, `LREM list -2 "hello"` will remove the last two occurrences of `"hello"` in the list stored at `list`. Note that non-existing keys are treated like empty lists, so when `key` does not exist, the command will always return `0`. ## Examples {{% redis-cli %}} RPUSH mylist "hello" RPUSH mylist "hello" RPUSH mylist "foo" RPUSH mylist "hello" LREM mylist -2 "hello" LRANGE mylist 0 -1 {{% /redis-cli %}} ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | |:----------------------|:-----------------|:------| | ✅ Standard
✅ Active-Active | ✅ Standard
✅ Active-Active | | ## Return information {{< multitabs id="lrem-return-info" tab1="RESP2" tab2="RESP3" >}} [Integer reply](../../develop/reference/protocol-spec#integers): the number of removed elements. -tab-sep- [Integer reply](../../develop/reference/protocol-spec#integers): the number of removed elements. {{< /multitabs >}}