# ZPOPMIN

> Remove and return the members with the lowest scores from a sorted set.

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

```
ZPOPMIN key [count]
```

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

`ZPOPMIN` removes and returns the member with the lowest score from the sorted
set at `key`, together with its score. With `count`, it removes and returns up
to `count` members, lowest score first. When the sorted set becomes empty, the
key is deleted.

To wait for a member when the set is empty, use [BZPOPMIN](https://docs.hotkv.com/commands/bzpopmin/index.md).

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| No `count` | Two-element array: member, score (bulk string) | Two-element array: member, score (double) |
| With `count` | Flat array: member, score, member, score, ... | Array of two-element arrays: `[member, score]`, the score a double |
| Key does not exist, or `count` is `0` | Empty array | Empty array |

Errors:

- `ERR value is out of range, must be positive` if `count` is negative or not
  an integer. This is checked before the key is looked up.
- `ERR syntax error` if more than one `count` argument is given.
- `WRONGTYPE` if `key` holds a value that is not a sorted set.

## Examples

```
127.0.0.1:6379> ZADD board 1 "a" 2 "b" 3 "c"
(integer) 3
127.0.0.1:6379> ZPOPMIN board
1) "a"
2) "1"
127.0.0.1:6379> ZPOPMIN board 5
1) "b"
2) "2"
3) "c"
4) "3"
127.0.0.1:6379> ZPOPMIN board
(empty array)
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[ZPOPMAX](https://docs.hotkv.com/commands/zpopmax/index.md), [BZPOPMIN](https://docs.hotkv.com/commands/bzpopmin/index.md), [ZMPOP](https://docs.hotkv.com/commands/zmpop/index.md),
[ZRANGE](https://docs.hotkv.com/commands/zrange/index.md)