Upstash Documentation

LREM

Remove elements by value.
2 min read

Use LREM to remove elements equal to a given value from a list.

The count decides how many occurrences are removed and in which direction: a positive count removes that many starting from the head, a negative count removes that many starting from the tail, and 0 removes every occurrence. The reply is the number of elements actually removed, and the key is deleted when the list becomes empty.

Removing by value means scanning the list, so on long lists prefer a set or a sorted set when you frequently need to delete arbitrary items.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<key>YesNoRedis key targeted by the command.
<count>YesNoHow many matches to remove: positive scans head to tail, negative tail to head, 0 removes every match.
<element>YesNoElement value to remove.

Response#

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.

ProtocolReply
RESP2Integer
RESP3Integer
Note

Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.

Examples#

TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.

Redis CLI
@upstash/redis
upstash_redis
ioredis
node-redis
redis-py
go-redis
jedis
redis-rs