# LPOP

> Remove and return elements from the head of a list.

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

```
LPOP key [count]
```

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

`LPOP` removes and returns the first element of the list stored at `key`. With
`count`, it removes and returns up to `count` elements from the head, in order.
When the list becomes empty, the key is deleted.

`count` must be a non-negative integer. A `count` of `0` returns an empty
array for an existing list. To wait for an element instead of getting nil, use
[BLPOP](https://docs.hotkv.com/commands/blpop/index.md).

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| No `count`, list exists | Bulk string: the popped element | Same |
| No `count`, key does not exist | Nil bulk string | Null |
| With `count`, list exists | Array of the popped elements | Same |
| With `count`, key does not exist | Nil array | Null |

Errors:

- `WRONGTYPE` if `key` holds a value that is not a list.
- `ERR value is out of range, must be positive` if `count` is negative or not
  an integer.

## Examples

```
127.0.0.1:6379> RPUSH queue a b c d
(integer) 4
127.0.0.1:6379> LPOP queue
"a"
127.0.0.1:6379> LPOP queue 2
1) "b"
2) "c"
127.0.0.1:6379> LPOP nosuchkey 2
(nil)
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[RPOP](https://docs.hotkv.com/commands/rpop/index.md), [LMPOP](https://docs.hotkv.com/commands/lmpop/index.md), [BLPOP](https://docs.hotkv.com/commands/blpop/index.md),
[LPUSH](https://docs.hotkv.com/commands/lpush/index.md), [LMOVE](https://docs.hotkv.com/commands/lmove/index.md)