TS.REVRANGE key fromTimestamp toTimestamp [FILTER_BY_TS Timestamp [Timestamp ...]] [ FILTER_BY_VALUE min max] [COUNT count] [ [ALIGN value] AGGREGATION AVG | FIRST | LAST | MIN | MAX | SUM | RANGE | COUNT | STD.P | STD.S | VAR.P | VAR.S | TWA bucketDuration [BUCKETTIMESTAMP] [EMPTY]]
Available in: Redis Stack
Time complexity: O(n/m+k) where n = Number of data points, m = Chunk size (data points per chunk), k = Number of data points that are in the requested range
TS.REVRANGE
Query a range in reverse direction.
TS.REVRANGE key fromTimestamp toTimestamp
[FILTER_BY_TS TS...]
[FILTER_BY_VALUE min max]
[COUNT count]
[[ALIGN value] AGGREGATION aggregator bucketDuration [BUCKETTIMESTAMP bt] [EMPTY]]
- key - Key name for timeseries
- fromTimestamp - Start timestamp for the range query.
-can be used to express the minimum possible timestamp (0). - toTimestamp - End timestamp for range query,
+can be used to express the maximum possible timestamp.
Optional parameters:
FILTER_BY_TSts... - a list of timestamps to filter the result by specific timestampsFILTER_BY_VALUEmin max - Filter result by value using minimum and maximum.COUNTcount - Maximum number of returned samples.
ALIGNvalue - Time bucket alignment control for AGGREGATION. This will control the time bucket timestamps by changing the reference timestamp on which a bucket is defined. Possible values:startor-: The reference timestamp will be the query start interval time (fromTimestamp)which can't be-endor+: The reference timestamp will be the query end interval time (toTimestamp) which can't be+- A specific timestamp: align the reference timestamp to a specific time
- Note: when not provided, alignment is set to
0
AGGREGATIONaggregator bucketDurationAggregate results into time buckets.
- aggregator - Aggregation type: One of the following:
aggregator description avgarithmetic mean of all values sumsum of all values minminimum value maxmaximum value rangedifference between the highest and the lowest value countnumber of values firstthe value with the lowest timestamp in the bucket lastthe value with the highest timestamp in the bucket std.ppopulation standard deviation of the values std.ssample standard deviation of the values var.ppopulation variance of the values var.ssample variance of the values twatime-weighted average of all values - bucketDuration - duration of each bucket, in milliseconds
The alignment of time buckets is 0.
- aggregator - Aggregation type: One of the following:
Complexity
TS.REVRANGE complexity is O(n/m+k).
n = Number of data points m = Chunk size (data points per chunk) k = Number of data points that are in the requested range
This can be improved in the future by using binary search to find the start of the range, which makes this O(Log(n/m)+k*m). But because m is pretty small, we can neglect it and look at the operation as O(Log(n) + k).
Aggregated Query Example
127.0.0.1:6379> TS.RANGE temperature:3:32 1548149180000 1548149210000 AGGREGATION avg 5000
1) 1) (integer) 1548149180000
2) "26.199999999999999"
2) 1) (integer) 1548149185000
2) "27.399999999999999"
3) 1) (integer) 1548149190000
2) "24.800000000000001"
4) 1) (integer) 1548149195000
2) "23.199999999999999"
5) 1) (integer) 1548149200000
2) "25.199999999999999"
6) 1) (integer) 1548149205000
2) "28"
7) 1) (integer) 1548149210000
2) "20"