TS.RANGE
Since 1.1.0Time series
Syntax
TS.RANGE key fromTimestamp toTimestamp [LATEST] [FILTER_BY_TS ts ...] [FILTER_BY_VALUE min max] [COUNT count] [[ALIGN value] AGGREGATION agg[,agg ...] bucketDuration [BUCKETTIMESTAMP bt] [EMPTY]]Returns the samples of the time series at key from fromTimestamp to toTimestamp, both included, oldest first. - and + are the series' first and last samples.
Options
| Option | Effect |
|---|---|
FILTER_BY_TS ts ... | Only samples at these timestamps. |
FILTER_BY_VALUE min max | Only samples with values in this range. |
COUNT count | At most count samples, or buckets. |
AGGREGATION agg[,agg ...] bucketDuration | One row per bucket of this many milliseconds, with each aggregator's value; several aggregators, comma-separated, are Redis 8.8's. |
ALIGN value | Where buckets start: a timestamp, start for fromTimestamp or end for toTimestamp (which must then be explicit, not - or +); 0 by default. |
BUCKETTIMESTAMP -|+|~ | Label a bucket by its start, end or middle. |
EMPTY | Also report the empty buckets between the first and last samples: COUNT and SUM as 0. |
LATEST | On the destination of a compaction rule, also report the bucket still open, as it stands. Without it, only closed buckets. Before 1.2, the open bucket was written to the destination as samples arrived, so every range showed it, with or without LATEST. |
The aggregators are AVG, FIRST, LAST, MIN, MAX, SUM, RANGE (max minus min), COUNT, STD.P, STD.S, VAR.P, VAR.S, TWA (time-weighted average), COUNTNAN (the NaN samples) and COUNTALL (all samples). The numeric ones skip NaN samples.
Reply
- An array of
[timestamp, value]samples, or withAGGREGATION,[bucket, value, ...]rows.
Examples
> TS.ADD temp:1 1000 20.5
(integer) 1000
> TS.ADD temp:1 2000 21
(integer) 2000
> TS.ADD temp:1 3000 22.5
(integer) 3000
> TS.ADD temp:1 4000 23
(integer) 4000
> TS.RANGE temp:1 1500 3500
1) 1) (integer) 2000
2) 21
2) 1) (integer) 3000
2) 22.5
> TS.RANGE temp:1 - + AGGREGATION min,max 2000
1) 1) (integer) 0
2) 20.5
3) 20.5
2) 1) (integer) 2000
2) 21
3) 22.5
3) 1) (integer) 4000
2) 23
3) 23
> TS.RANGE temp:1 - + FILTER_BY_VALUE 21 23
1) 1) (integer) 2000
2) 21
2) 1) (integer) 3000
2) 22.5
3) 1) (integer) 4000
2) 23