# BZMPOP

> Pop the lowest or highest scored members from the first non-empty sorted set, waiting until one is available.

URL: https://docs.hotkv.com/commands/bzmpop/

```
BZMPOP timeout numkeys key [key ...] MIN | MAX [COUNT count]
```

- Group: Sorted set
- Complexity: O(K)+O(M*log(N)) where K is the number of keys checked, N the size of the sorted set and M the number of members popped
- HotKV Cloud: all plans
- On-Premise: no license needed

`BZMPOP` is the blocking form of [ZMPOP](https://docs.hotkv.com/commands/zmpop/index.md). It checks the keys
in order and pops up to `count` members (default `1`) from the first non-empty
sorted set: the lowest scores with `MIN`, the highest with `MAX`. If every
sorted set is empty or missing, the connection waits until one of the keys
gets members or `timeout` passes, then pops from that key.

`timeout` is in seconds, can have a fractional part, and `0` waits forever.
Inside [MULTI](https://docs.hotkv.com/commands/multi/index.md) / [EXEC](https://docs.hotkv.com/commands/exec/index.md) and inside scripts,
`BZMPOP` never waits and replies at once as if the timeout had expired.

## Options

| Option | Effect |
| --- | --- |
| `timeout` | Seconds to wait; `0` waits forever. |
| `numkeys` | How many keys follow. Must be greater than 0. |
| `MIN` / `MAX` | Pop the lowest or the highest scores. |
| `COUNT count` | Pop up to `count` members. Must be greater than 0. |

The arguments after `timeout` are checked before `timeout` itself.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Popped | Two-element array: the key, then an array of `[member, score]` pairs (score as a bulk string) | Same shape, with each score a double |
| Timeout expired | Nil array | Null |

Errors:

- `ERR numkeys should be greater than 0`, `ERR count should be greater than 0`,
  or `ERR syntax error`, as for [ZMPOP](https://docs.hotkv.com/commands/zmpop/index.md).
- `ERR timeout is not a float or out of range`, `ERR timeout is negative`, or
  `ERR timeout is out of range` for a bad `timeout`.
- `WRONGTYPE` if a key reached before the first non-empty sorted set holds a
  value that is not a sorted set.

## Examples

```
127.0.0.1:6379> ZADD board 100 "alice" 90 "bob" 80 "carol"
(integer) 3
127.0.0.1:6379> BZMPOP 1 1 board MAX COUNT 2
1) "board"
2) 1) 1) "alice"
      2) "100"
   2) 1) "bob"
      2) "90"
127.0.0.1:6379> BZMPOP 0.3 1 empty MIN
(nil)
(0.30s)
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[ZMPOP](https://docs.hotkv.com/commands/zmpop/index.md), [BZPOPMIN](https://docs.hotkv.com/commands/bzpopmin/index.md), [BZPOPMAX](https://docs.hotkv.com/commands/bzpopmax/index.md),
[BLMPOP](https://docs.hotkv.com/commands/blmpop/index.md)