TS.CREATERULE
Since 1.1.0Time series
Syntax
TS.CREATERULE sourceKey destKey AGGREGATION agg bucketDuration [alignTimestamp]Creates a compaction rule: every sample added to sourceKey is aggregated, by agg over buckets of bucketDuration milliseconds, into the existing series destKey. alignTimestamp sets where buckets start.
A bucket is written to the destination once it has closed, when the first sample of a later bucket arrives, and written again if a sample is added to it after. The bucket still open is reported only with LATEST, on TS.GET, TS.RANGE and the other read commands. Each bucket is computed from the samples in the source, so samples already there count in the bucket open when the rule is made, and in an older bucket a sample is added to; older buckets are not written otherwise.
A series takes compacted samples from one source only, and TS.INFO of the destination names it as sourceKey.
A rule links two keys, and goes with them only where both go together: RENAME of either takes the link along, and an atomic slot migration keeps it, but DUMP, RESTORE and MIGRATE leave it out, as in RedisTimeSeries. A link left behind by DEL, RESTORE ... REPLACE, COPY ... REPLACE or MIGRATE of one of its series is dead: the source no longer feeds the destination, TS.INFO no longer shows it, and TS.CREATERULE gives the destination a new source. That is since 1.2.1. 1.2.0 carried the links by key name inside DUMP payloads, so a copy fed the original's compaction, and a series renamed kept its links under the old name. An atomic slot migration from a 1.2.0 node, as in a rolling upgrade, loses the moved series' rules: make them again with TS.CREATERULE.
Before 1.2, the destination got the open bucket written as samples arrived, and LATEST changed nothing. A snapshot with a compaction rule in it, written by 1.2, cannot be read by 1.1.2 and older.
Reply
OK.TSDB: the destination key already has a src ruleifdestKeyalready takes samples from a series.
Examples
> TS.CREATE src
OK
> TS.CREATE dst
OK
> TS.CREATERULE src dst AGGREGATION sum 10000
OK
> TS.ADD src 1000 1
(integer) 1000
> TS.ADD src 2000 1
(integer) 2000
> TS.RANGE dst - +
(empty array)
> TS.RANGE dst - + LATEST
1) 1) (integer) 0
2) 2
> TS.ADD src 12000 1
(integer) 12000
> TS.RANGE dst - +
1) 1) (integer) 0
2) 2