Back to Redis

TS.ALTER

content/commands/ts.alter.md

latest3.4 KB
Original Source

Update the retention, chunk size, duplicate policy, and labels of an existing time series

Examples

Required arguments

<details open><summary><code>key</code></summary>

is key name for the time series.

</details>

<note><b>Note:</b> This command alters only the specified element. For example, if you specify only RETENTION and LABELS, the chunk size and the duplicate policy are not altered. </note>

Optional arguments

<details open><summary><code>RETENTION retentionPeriod</code></summary>

is maximum retention period, compared to the maximum existing timestamp, in milliseconds. See RETENTION in [TS.CREATE]({{< relref "commands/ts.create/" >}}).

</details> <details open><summary><code>CHUNK_SIZE size</code></summary>

is the initial allocation size, in bytes, for the data part of each new chunk. Actual chunks may consume more memory. See CHUNK_SIZE in [TS.CREATE]({{< relref "commands/ts.create/" >}}). Changing this value does not affect existing chunks.

</details> <details open><summary><code>DUPLICATE_POLICY policy</code></summary>

is policy for handling multiple samples with identical timestamps. See DUPLICATE_POLICY in [TS.CREATE]({{< relref "commands/ts.create/" >}}).

</details> <details open><summary><code>LABELS [{label value}...]</code></summary>

is set of label-value pairs that represent metadata labels of the key and serve as a secondary index.

If LABELS is specified, the given label list is applied. Labels that are not present in the given list are removed implicitly. Specifying LABELS with no label-value pairs removes all existing labels. See LABELS in [TS.CREATE]({{< relref "commands/ts.create/" >}}).

</details>

Examples

<details open><summary><b>Alter a temperature time series</b></summary>

Create a temperature time series.

{{< highlight bash >}} 127.0.0.1:6379> TS.CREATE temperature:2:32 RETENTION 60000 DUPLICATE_POLICY MAX LABELS sensor_id 2 area_id 32 OK {{< / highlight >}}

Alter the labels in the time series.

{{< highlight bash >}} 127.0.0.1:6379> TS.ALTER temperature:2:32 LABELS sensor_id 2 area_id 32 sub_area_id 15 OK {{< / highlight >}}

</details>

Redis Software and Redis Cloud compatibility

| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Supported</span> | <span title="Supported">✅ Flexible & Annual</span> <span title="Supported">✅ Free & Fixed</nobr></span> | |

Return information

{{< multitabs id="ts-alter-return-info" tab1="RESP2" tab2="RESP3" >}}

One of the following:

  • [Simple string reply]({{< relref "/develop/reference/protocol-spec#simple-strings" >}}): OK when the time series is altered successfully.
  • [Simple error reply]({{< relref "/develop/reference/protocol-spec#simple-errors" >}}) in these cases: invalid arguments, wrong key type, key does not exist, etc.

-tab-sep-

One of the following:

  • [Simple string reply]({{< relref "/develop/reference/protocol-spec#simple-strings" >}}): OK when the time series is altered successfully.
  • [Simple error reply]({{< relref "/develop/reference/protocol-spec#simple-errors" >}}) in these cases: invalid arguments, wrong key type, key does not exist, etc.

{{< /multitabs >}}

See also

[TS.CREATE]({{< relref "commands/ts.create/" >}})

[RedisTimeSeries]({{< relref "/develop/data-types/timeseries/" >}})