Upstash Documentation

LMPOP

Pop from the first non-empty list.
2 min read

Use LMPOP to pop elements from the first of several lists that is not empty.

<numkeys> states how many keys follow, LEFT or RIGHT chooses the end to pop from, and COUNT sets how many elements to take, defaulting to one. Keys are examined in the order given and only the first non-empty one is touched, which is exactly what a priority queue needs: list the high priority queue first and it is drained before the others are looked at.

The reply names the key that was popped from together with the elements, so a caller working with several queues knows where the work came from. When every key is empty the reply is null; use BLMPOP to wait instead.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<numkeys>YesNoNumber of key arguments that follow.
<key>YesYesRedis key targeted by the command.
(LEFT | RIGHT)YesNoWhich end to pop from: LEFT (head) or RIGHT (tail).
COUNT <count>NoNoMaximum number of elements to pop.

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
RESP2Null bulk string or null array, or two-element array: key and array of values
RESP3Null, or two-element array: key and array of values
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
Note

This command is not supported yet in upstash_redis.

ioredis
node-redis
redis-py
go-redis
jedis
redis-rs