TS.DECRBY

Syntax
TS.DECRBY key subtrahend 
  [TIMESTAMP timestamp] 
  [RETENTION retentionPeriod] 
  [UNCOMPRESSED] 
  [CHUNK_SIZE size] 
  [LABELS [label value ...]]
Available in:
Redis Stack / TimeSeries 1.0.0
Time complexity:
O(M) when M is the amount of compaction rules or O(1) with no compaction

Decrease the value of the sample with the maximum existing timestamp, or create a new sample with a value equal to the value of the sample with the maximum existing timestamp with a given decrement

Examples

Required arguments

key

is key name for the time series.

subtrahend

is numeric value of the subtrahend (double).

Notes

  • When specified key does not exist, a new time series is created.
  • You can use this command as a counter or gauge that automatically gets history as a time series.
  • Explicitly adding samples to a compacted time series (using TS.ADD, TS.MADD, TS.INCRBY, or TS.DECRBY) may result in inconsistencies between the raw and the compacted data. The compaction process may override such samples.

Optional arguments

TIMESTAMP timestamp

is Unix time (integer, in milliseconds) specifying the sample timestamp or * to set the sample timestamp to the Unix time of the server's clock.

Unix time is the number of milliseconds that have elapsed since 00:00:00 UTC on 1 January 1970, the Unix epoch, without adjustments made due to leap seconds.

timestamp must be equal to or higher than the maximum existing timestamp. When equal, the value of the sample with the maximum existing timestamp is decreased. If it is higher, a new sample with a timestamp set to timestamp is created, and its value is set to the value of the sample with the maximum existing timestamp minus subtrahend.

If the time series is empty, the value is set to subtrahend.

When not specified, the timestamp is set to the Unix time of the server's clock.

RETENTION retentionPeriod

is maximum retention period, compared to the maximum existing timestamp, in milliseconds. Use it only if you are creating a new time series. It is ignored if you are adding samples to an existing time series. See RETENTION in TS.CREATE.

UNCOMPRESSED

changes data storage from compressed (default) to uncompressed. Use it only if you are creating a new time series. It is ignored if you are adding samples to an existing time series. See ENCODING in TS.CREATE.

CHUNK_SIZE size

is memory size, in bytes, allocated for each data chunk. Use it only if you are creating a new time series. It is ignored if you are adding samples to an existing time series. See CHUNK_SIZE in TS.CREATE.

LABELS [{label value}...]

is set of label-value pairs that represent metadata labels of the key and serve as a secondary index. Use it only if you are creating a new time series. It is ignored if you are adding samples to an existing time series. See LABELS in TS.CREATE.

Notes

  • You can use this command to add data to a nonexisting time series in a single command. This is why RETENTION, UNCOMPRESSED, CHUNK_SIZE, and LABELS are optional arguments.
  • When specified and the key doesn't exist, a new time series is created. Setting the RETENTION and LABELS introduces additional time complexity.

Return value

Returns one of these replies:

  • Integer reply - the timestamp of the upserted sample
  • [] on error (invalid arguments, wrong key type, etc.), or when timestamp is not equal to or higher than the maximum existing timestamp

See also

TS.INCRBY | TS.CREATE

RedisTimeSeries


RATE THIS PAGE
Back to top ↑