# TS.RANGE

> Return the samples of a time series between two timestamps.

URL: https://docs.hotkv.com/commands/ts-range/

```
TS.RANGE key from to [COUNT count]
```

- Group: Time series
- Complexity: O(log N + M), M being the samples returned
- HotKV Cloud: Performance and Scale plans
- On-Premise: requires the time-series license feature

`TS.RANGE` returns the samples of the time series `key` with timestamps from
`from` to `to`, both included, oldest first.

## Arguments and options

| Argument | Meaning |
| --- | --- |
| `from` | Start, in Unix milliseconds. `-` means the earliest. |
| `to` | End, in Unix milliseconds. `+` means the latest. |
| `COUNT count` | Return at most `count` samples, from the start of the range. `0` means no limit. |

Other arguments after `to` are ignored.

## Return value

An array of samples, each a two-element array: the timestamp (integer) and
the value (bulk string with six decimals). The shape is the same in RESP2 and
RESP3. A series that does not exist gives an empty array.

Error replies: `ERR invalid from timestamp`, `ERR invalid to timestamp`,
`ERR invalid COUNT`, and `NOLICENSE ...` without the `time-series` license
feature.

## Examples

```
127.0.0.1:6379> TS.CREATE temp:kitchen
OK
127.0.0.1:6379> TS.ADD temp:kitchen 1700000000000 21.5
(integer) 1700000000000
127.0.0.1:6379> TS.ADD temp:kitchen 1700000060000 21.75
(integer) 1700000060000
127.0.0.1:6379> TS.ADD temp:kitchen 1700000120000 22
(integer) 1700000120000
127.0.0.1:6379> TS.RANGE temp:kitchen - + COUNT 2
1) 1) (integer) 1700000000000
   2) "21.500000"
2) 1) (integer) 1700000060000
   2) "21.750000"
127.0.0.1:6379> TS.RANGE temp:kitchen 1700000100000 +
1) 1) (integer) 1700000120000
   2) "22.000000"
```

## Compatibility

HotKV's own time series API. `TS.RANGE` shares its name with the
RedisTimeSeries command but takes only `COUNT`; use [TS.AGG](https://docs.hotkv.com/commands/ts-agg/index.md)
for aggregation. Values are returned with six decimals.

## See also

[TS.AGG](https://docs.hotkv.com/commands/ts-agg/index.md), [TS.ADD](https://docs.hotkv.com/commands/ts-add/index.md), [TS.INFO](https://docs.hotkv.com/commands/ts-info/index.md)