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
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]]
-can be used to express the minimum possible timestamp (0).
+can be used to express the maximum possible timestamp.
FILTER_BY_TS ts... - a list of timestamps to filter the result by specific timestamps
FILTER_BY_VALUE min max - Filter result by value using minimum and maximum.
COUNT count - 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:
-: The reference timestamp will be the query start interval time (
fromTimestamp)which can't be
+: The reference timestamp will be the query end interval time (
toTimestamp) which can't be
AGGREGATION aggregator bucketDuration
Aggregate results into time buckets.
|arithmetic mean of all values|
|sum of all values|
|difference between the highest and the lowest value|
|number of values|
|the value with the lowest timestamp in the bucket|
|the value with the highest timestamp in the bucket|
|population standard deviation of the values|
|sample standard deviation of the values|
|population variance of the values|
|sample variance of the values|
|time-weighted average of all values|
The alignment of time buckets is 0.
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).
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"