Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

TS.DOWNSAMPLE

Last updated
TS.DOWNSAMPLE source destination aggregation bucket
Group
Time series
Complexity
O(1)
Arity
5 (exactly, counting the command name)
Flags
write, slow
Keys
first 1, last 2, step 1
HotKV Cloud
Performance and Scale
On-Premise
requires the time-series license feature

TS.DOWNSAMPLE adds a rule to the time series source: from now on, every sample added to source with TS.ADD is also added, as is, to the time series destination. Both series must already exist. Samples that were in source before the rule are not copied.

The rule is recorded with the aggregation and bucket you give. The destination holds the raw samples, not aggregated values. To read the downsampled view, run TS.AGG on the destination with the same aggregation and bucket. A typical use is to give the destination a longer retention than the source, or to collect several sources in one series. The destination’s own retention is applied when a sample is added to it directly, or by TS.RETENTION.

aggregation is one of the names TS.AGG accepts, and bucket a width in milliseconds of at least 1. In cluster mode, both series must hash to the same slot.

Case RESP2 RESP3
Rule added Simple string OK Simple string OK

Error replies:

  • ERR source or destination series not found
  • ERR unknown aggregation type and ERR invalid bucket size
  • NOLICENSE ... without the time-series license feature.
127.0.0.1:6379> TS.CREATE cpu RETENTION 3600000
OK
127.0.0.1:6379> TS.CREATE cpu:history
OK
127.0.0.1:6379> TS.DOWNSAMPLE cpu cpu:history avg 60000
OK
127.0.0.1:6379> TS.ADD cpu * 10
(integer) 1759400000000
127.0.0.1:6379> TS.ADD cpu * 20
(integer) 1759400030000
127.0.0.1:6379> TS.AGG cpu:history - + 60000 avg
1) 1) (integer) 1759399980000
2) "15.000000"

The timestamps come from the server clock and will differ.

HotKV-only command. It is not the same as RedisTimeSeries TS.CREATERULE: the destination receives raw samples, and you aggregate when you read.

TS.AGG, TS.CREATE, TS.INFO