Upstash Documentation

ZMPOP

Pop from the first non-empty sorted set.
2 min read

Use ZMPOP to pop members from the first of several sorted sets that is not empty.

<numkeys> states how many keys follow, MIN or MAX chooses whether the lowest or the highest scoring members are taken, and COUNT sets how many to pop. Keys are examined in the order given and only the first non-empty one is touched, so listing a high priority queue first drains it before the others are considered.

The reply names the key that was popped from along with the members and their scores, which matters when a worker watches several queues. When every key is empty the reply is null; use BZMPOP to wait instead of returning.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<numkeys>YesNoNumber of key arguments that follow.
<key>YesYesRedis key targeted by the command.
(MIN | MAX)YesNoWhich members to pop: MIN (lowest scores first) or MAX (highest scores first).
COUNT <count>NoNoMaximum number of members to pop.

Important points#

  • RESP2 represents floating-point reply values as bulk strings; RESP3 may use native double replies. Client libraries commonly decode either form to a language number.

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 member/score pairs
RESP3Null, or two-element array: key and array of member/score pairs
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
Note

This command is not supported yet in @upstash/redis.

upstash_redis
Note

This command is not supported yet in upstash_redis.

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