How to make a RedisTimeSeries return a partial bucket for a destination key fed by a compaction rule

Viewed 85

This is an extension of this question which is almost 2 years old. In that question, @Danni said it was intended for the API to not return the results of a partial bucket.

My question is how do I return the results of a partial bucket if I wanted to?

Case in point, I want ts.get to return 100:

127.0.0.1:6379> flushdb 
OK
127.0.0.1:6379> ts.create src
OK
127.0.0.1:6379> ts.create dst
OK
127.0.0.1:6379> ts.createrule src dst aggregation first 3600000
OK
127.0.0.1:6379> ts.add src * 100
(integer) 1651515399055
127.0.0.1:6379> ts.add src * 200
(integer) 1651515402981
127.0.0.1:6379> ts.add src * 300
(integer) 1651515406787
127.0.0.1:6379> ts.add src * 400
(integer) 1651515410118
127.0.0.1:6379> ts.get dst
(empty array)
1 Answers

Currently, when key is a compaction, TS.GET, TS.RANGE, TS.REVRANGE, TS.MRANGE and TS.MREVRANGE won’t report the compacted value of the latest raw bucket.

The reason is that the data in the latest bucket is possibly partial. A bucket is ‘closed’ and compacted only upon arrival of data that ‘opens’ a new bucket.

You are definitely right - there are use cases when the compaction of the latest (the possibly partial) bucket should be retrieved as well.

In RedisTimeSeries 1.8, we are going to introduce an optional flag that allows receiving the latest (possibly partial) bucket as well:

Details:

Add optional LATEST to the above mentioned commands:

TS.GET key [LATEST]
TS.MGET key [LATEST] ...
TS.RANGE key fromTimeStamp toTimeStamp [LATEST] …
TS.REVRANGE key fromTimeStamp toTimeStamp [LATEST] …
TS.MRANGE key fromTimeStamp toTimeStamp [LATEST] …
TS.MREVRANGE key fromTimeStamp toTimeStamp [LATEST] …

[LATEST]

Valid only if key is a compaction. If specified - also retrieve the latest (possibly partial) compaction bucket.


What you can easily do right now (RedisTimeSeries v1.6) is to manually aggregate the raw samples in the latest bucket period - directly from the raw samples time series (not from the compacted one), using:

TS.RANGE key bucket_startTimestamp bucket_endTimestamp AGGREGATION aggregator bucketDuration

Related