# BLMPOP

> Pop elements from the first non-empty list among several keys, waiting until one is available.

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

```
BLMPOP timeout numkeys key [key ...] LEFT | RIGHT [COUNT count]
```

- Group: List
- Complexity: O(N+M) where N is the number of keys checked and M is the number of elements returned
- HotKV Cloud: all plans
- On-Premise: no license needed

`BLMPOP` is the blocking form of [LMPOP](https://docs.hotkv.com/commands/lmpop/index.md). It checks the keys
in order and pops up to `count` elements (default `1`) from the head (`LEFT`)
or tail (`RIGHT`) of the first non-empty list. If every list is empty or
missing, the connection waits until one of the keys receives elements 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,
`BLMPOP` 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. |
| `LEFT` / `RIGHT` | Pop from the head or the tail. |
| `COUNT count` | Pop up to `count` elements. 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 the popped elements | Same |
| 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 [LMPOP](https://docs.hotkv.com/commands/lmpop/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 list holds a value
  that is not a list.

## Examples

```
127.0.0.1:6379> RPUSH q:low l1 l2 l3
(integer) 3
127.0.0.1:6379> BLMPOP 5 2 q:high q:low RIGHT COUNT 2
1) "q:low"
2) 1) "l3"
   2) "l2"
127.0.0.1:6379> BLMPOP 0.2 1 q:high LEFT
(nil)
(0.20s)
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[LMPOP](https://docs.hotkv.com/commands/lmpop/index.md), [BLPOP](https://docs.hotkv.com/commands/blpop/index.md), [BRPOP](https://docs.hotkv.com/commands/brpop/index.md),
[BZMPOP](https://docs.hotkv.com/commands/bzmpop/index.md)