TS.CREATE

Since 1.1.0Time seriesDiffers from Redis

Syntax

TS.CREATE key [RETENTION ms] [ENCODING COMPRESSED|UNCOMPRESSED] [CHUNK_SIZE size] [DUPLICATE_POLICY BLOCK|FIRST|LAST|MIN|MAX|SUM] [LABELS label value ...]
  • Flags: write
  • ACL categories: @slow, @timeseries, @write
  • Arity: -2

Creates a time series at key: samples, each a timestamp in milliseconds and a floating-point value, kept in timestamp order.

Options

OptionEffect
RETENTION msDrop samples older than this, measured back from the newest; 0 keeps them all (the default).
LABELS label value ...Name-value pairs that TS.MGET, TS.MRANGE and TS.QUERYINDEX select series by.
DUPLICATE_POLICY policyWhat a sample at a timestamp that already has one does: BLOCK (an error), FIRST, LAST, MIN, MAX or SUM. Without it, the series takes the server's ts-duplicate-policy, last by default, and keeps it.
CHUNK_SIZE sizeA multiple of 8 from 48 to 1048576. Kept, and reported by TS.INFO. KiviDB's older spelling, CHUNK SIZE, is still taken.
ENCODING COMPRESSED | UNCOMPRESSEDAccepted; KiviDB stores every series one way. Another value is refused.

A word that is not an option is passed over, as RedisTimeSeries passes it over, and the options after it are read. IGNORE, which KiviDB does not support, is refused. The same holds for the options of TS.ALTER, TS.ADD, TS.INCRBY and TS.DECRBY.

These are since 1.2.1. In 1.2.0, CHUNK_SIZE was not taken, and a word that was not an option ended the options without an error, so it and everything after it, LABELS too, was dropped: TS.CREATE k CHUNK_SIZE 4096 LABELS a b made a series with no labels. An append-only file written by 1.2.0 is replayed under the new rules, so after the first restart such a series can differ from what 1.2.0 held in memory: TS.CREATE k FOO RETENTION 10 now has the retention.

DUMP, RESTORE and MIGRATE carry a series' samples, retention, chunk size, duplicate policy and labels, and no links to other keys: a series' compaction rules, and the series it is a compaction of, are left out, as in RedisTimeSeries. An atomic slot migration keeps them. That is since 1.2.1; see TS.CREATERULE.

Reply

  • OK.
  • TSDB: key already exists.
  • TSDB: CHUNK_SIZE value must be a multiple of 8 in the range [48 .. 1048576].
  • TSDB: unknown ENCODING parameter.

Differences from Redis

The default duplicate policy is LAST: a second sample at a timestamp replaces the first. In Redis it is BLOCK, an error. Set ts-duplicate-policy to block, with CONFIG SET or in the config file, to get Redis's default for every series made after, or give DUPLICATE_POLICY BLOCK to one series. Set it alike on a master and its replicas.

Examples

> TS.CREATE temp:1 LABELS room kitchen kind temp
OK
> TS.CREATE temp:1
(error) TSDB: key already exists
> TS.CREATE s CHUNK_SIZE 40
(error) TSDB: CHUNK_SIZE value must be a multiple of 8 in the range [48 .. 1048576]