Upstash Documentation

BZMPOP

Pop from the first non-empty sorted set, blocking until one arrives.
2 min read

Use BZMPOP to pop members from the first non-empty sorted set among several, blocking until one has members or the timeout expires.

It is the blocking form of ZMPOP: keys are examined in the order given, so earlier keys act as higher priority queues, MIN or MAX chooses whether the lowest or highest scoring members are taken, and COUNT sets how many. The reply names the key that was popped from along with the members and their scores.

The timeout is in seconds, may be fractional, and 0 waits indefinitely; when it expires the reply is null. This is what a worker uses to wait on several priority queues at once without polling.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<timeout>YesNoSeconds to block; 0 blocks indefinitely.
<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#

  • A blocking form holds the request until data arrives or its timeout expires. Set the client/network timeout longer than the command timeout.

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