Available in: Redis Stack
Time complexity: O(1)
Create a new time series.
TS.CREATE key [RETENTION retentionPeriod] [ENCODING [UNCOMPRESSED|COMPRESSED]] [CHUNK_SIZE size] [DUPLICATE_POLICY policy] [LABELS {label value}...]
Optional args:
RETENTION
retentionPeriod - Maximum age for samples compared to last event time (in milliseconds)
When set to 0, the series is not trimmed.
When not specified: set to the global RETENTION_POLICY configuration of the database (which, by default, is 0).
ENCODING
enc - Specify the series samples encoding format. One of the following values:
COMPRESSED
: apply the DoubleDelta compression to the series samples, meaning compression of Delta of Deltas between timestamps and compression of values via XOR encoding.UNCOMPRESSED
: keep the raw samples in memory. Adding this flag will keep data in an uncompressed form. Compression not only saves
memory but usually improve performance due to lower number of memory accesses.When not specified: set to COMPRESSED
.
CHUNK_SIZE
size - memory size, in bytes, allocated for each data chunk. Must be a multiple of 8 in the range [128 .. 1048576].
When not specified: set to 4096.
DUPLICATE_POLICY
policy - Policy for handling multiple samples with identical timestamps. One of the following values:
BLOCK
- an error will occur for any out of order sampleFIRST
- ignore any newly reported valueLAST
- override with the newly reported valueMIN
- only override if the value is lower than the existing valueMAX
- only override if the value is higher than the existing valueSUM
- If a previous sample exists, add the new sample to it so that the updated value is equal to (previous + new). If no previous sample exists, set the updated value equal to the new value.When not specified: set to the global DUPLICATE_POLICY configuration of the database (which, by default, is BLOCK
).
LABELS
{label value}... - Set of label-value pairs that represent metadata labels of the key
TS.CREATE complexity is O(1).
TS.CREATE temperature:2:32 RETENTION 60000 DUPLICATE_POLICY MAX LABELS sensor_id 2 area_id 32
TSDB: key already exists
. You can check for the existence of a key with Redis EXISTS command.TS.ADD
can also create a new time-series if called with a key that does not exist.