# LMPOP

> Pop elements from the first non-empty list among several keys.

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

```
LMPOP 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

`LMPOP` checks the given keys in order and pops from the first one that holds
a non-empty list. It pops from the head (`LEFT`) or the tail (`RIGHT`), up to
`count` elements (default `1`), all from that one list. The list is deleted
when it becomes empty.

To wait when every list is empty, use [BLMPOP](https://docs.hotkv.com/commands/blmpop/index.md).

## Options

| Option | Effect |
| --- | --- |
| `numkeys` | How many keys follow. Must be greater than 0. |
| `LEFT` | Pop from the head. |
| `RIGHT` | Pop from the tail. |
| `COUNT count` | Pop up to `count` elements. Must be greater than 0. Can be given once. |

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Popped | Two-element array: the key, then an array of the popped elements | Same |
| All keys missing or empty | Nil array | Null |

Errors:

- `ERR numkeys should be greater than 0` if `numkeys` is not a positive
  integer.
- `ERR syntax error` if fewer keys follow than `numkeys` says, the direction
  is missing or not `LEFT`/`RIGHT`, or `COUNT` is repeated or unknown words
  follow.
- `ERR count should be greater than 0` if `count` is not a positive integer.
- `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:high h1
(integer) 1
127.0.0.1:6379> RPUSH q:low l1 l2 l3
(integer) 3
127.0.0.1:6379> LMPOP 2 q:high q:low LEFT COUNT 2
1) "q:high"
2) 1) "h1"
127.0.0.1:6379> LMPOP 2 q:high q:low LEFT COUNT 2
1) "q:low"
2) 1) "l1"
   2) "l2"
127.0.0.1:6379> LMPOP 1 nosuchkey RIGHT
(nil)
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[BLMPOP](https://docs.hotkv.com/commands/blmpop/index.md), [LPOP](https://docs.hotkv.com/commands/lpop/index.md), [RPOP](https://docs.hotkv.com/commands/rpop/index.md),
[ZMPOP](https://docs.hotkv.com/commands/zmpop/index.md)