Available in: Redis Stack
Time complexity: O(1)
Create a compaction rule.
TS.CREATERULE sourceKey destKey AGGREGATION aggregator bucketDuration [alignTimestamp]
sourceKey - Key name for source time series
destKey - Key name for destination (compacted) time series
AGGREGATION
aggregator bucketDuration
Aggregate results into time buckets.
aggregator - Aggregation type: One of the following:
aggregator | description |
---|---|
avg | arithmetic mean of all values |
sum | sum of all values |
min | minimum value |
max | maximum value |
range | difference between the highest and the lowest value |
count | number of values |
first | the value with the lowest timestamp in the bucket |
last | the value with the highest timestamp in the bucket |
std.p | population standard deviation of the values |
std.s | sample standard deviation of the values |
var.p | population variance of the values |
var.s | sample variance of the values |
twa | time-weighted average of all values (since RedisTimeSeries v1.8) |
bucketDuration - Duration of each bucket, in milliseconds
alignTimestamp (since RedisTimeSeries v1.8)
Assure that there is a bucket that starts at exactly alignTimestamp and align all other buckets accordingly. Units: milliseconds. Default value: 0 (aligned with the epoch). Example: if bucketDuration is 24 hours (24 * 3600 * 1000), setting alignTimestamp to 6 hours after the epoch (6 * 3600 * 1000) will ensure that each bucket’s timeframe is [06:00 .. 06:00).
destKey should be of a timeseries
type, and should be created before TS.CREATERULE
is called.
Notes:
TS.CREATERULE
with a nonempty destKey can result in an undefined behavior