# ZRANGEBYSCORE

> Get the members of a sorted set with scores in a range, lowest first.

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

```
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset 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 returned
- HotKV Cloud: all plans
- On-Premise: no license needed
- Deprecated: use ZRANGE instead

`ZRANGEBYSCORE` returns the members of the sorted set at `key` whose score is
between `min` and `max`, from the lowest score to the highest. It is the same
as `ZRANGE key min max BYSCORE`; new code can use [ZRANGE](https://docs.hotkv.com/commands/zrange/index.md).

Bounds are inclusive unless prefixed with `(`, and `-inf` / `+inf` are allowed.

## Options

| Option | Effect |
| --- | --- |
| `WITHSCORES` | Return each member with its score. |
| `LIMIT offset count` | Skip `offset` matching members, then return at most `count`. A negative `count` returns all remaining members. |

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Success | Array of members | Same |
| With `WITHSCORES` | Flat array: member, score, ... (scores as bulk strings) | Array of `[member, score]` pairs, the score a double |
| Key does not exist or nothing in range | Empty array | Same |

Errors:

- `ERR syntax error` for an unknown option.
- `ERR value is not an integer or out of range` for a non-integer `LIMIT`
  value.
- `ERR min or max is not a float` for a bad bound.
- `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> ZRANGEBYSCORE board (1 3
1) "b"
2) "c"
127.0.0.1:6379> ZRANGEBYSCORE board -inf +inf WITHSCORES LIMIT 1 1
1) "b"
2) "2"
```

## Compatibility

Same as Redis 7.4 and Valkey 8, where it is also deprecated in favour of
`ZRANGE ... BYSCORE`.

## See also

[ZRANGE](https://docs.hotkv.com/commands/zrange/index.md), [ZREVRANGEBYSCORE](https://docs.hotkv.com/commands/zrevrangebyscore/index.md),
[ZCOUNT](https://docs.hotkv.com/commands/zcount/index.md), [ZREMRANGEBYSCORE](https://docs.hotkv.com/commands/zremrangebyscore/index.md)