{
  "schema_version": 2,
  "id": "commands/ts.madd",
  "title": "TS.MADD",
  "url": "https://redis.io/docs/latest/commands/ts.madd/",
  "summary": "Append new samples to one or more time series",
  "since": "1.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:48:54+01:00",
  "page_type": "content",
  "content_hash": "17705e414616d195f8d252745aa65749aeb4dd2df19ffa206c53413663a7f8f0",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "> [!NOTE]\n> This command's behavior varies in clustered Redis environments. See the [multi-key operations](https://redis.io/docs/latest/develop/using-commands/multi-key-operations) page for more information.\n\n\n\nAppend new samples to one or more time series\n\n[Examples](#examples)"
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open>\n<summary><code>key</code></summary> \n\nis the key name for the time series.\n</details>\n\n<details open>\n<summary><code>timestamp</code></summary>\n\nis Unix time (integer, in milliseconds) specifying the sample timestamp or `*` to set the sample timestamp to the Unix time of the server's clock.\n\nUnix 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.\n</details>\n\n<details open>\n<summary><code>value</code></summary>\n\nis numeric data value of the sample (double). The double number should follow <a href=\"https://tools.ietf.org/html/rfc7159\">RFC 7159</a> (JSON standard). The parser rejects overly large values that would not fit in binary64. It does not accept infinite values. NaN (Not a Number) values are supported starting from Redis 8.6.\n</details>\n\n<note><b>Notes:</b>\n- If `timestamp` is older than the retention period compared to the maximum existing timestamp, the sample is discarded and an error is returned.\n- Explicitly adding samples to a compacted time series (using [`TS.ADD`](https://redis.io/docs/latest/commands/ts.add), `TS.MADD`, [`TS.INCRBY`](https://redis.io/docs/latest/commands/ts.incrby), or [`TS.DECRBY`](https://redis.io/docs/latest/commands/ts.decrby)) may result in inconsistencies between the raw and the compacted data. The compaction process may override such samples.\n- `ignoreMaxTimeDiff` and `ignoreMaxValDiff` cannot be specified as is the case with `TS.ADD`. However, the same logic still applies based on the values of the per-key configuration parameters. See the [`TS.ADD`](https://redis.io/docs/latest/commands/ts.add) command page for more information.\n</note>"
    },
    {
      "id": "complexity",
      "title": "Complexity",
      "role": "performance",
      "text": "If a compaction rule exits on a time series, TS.MADD performance might be reduced.\nThe complexity of TS.MADD is always `O(N*M)`, where `N` is the amount of series updated and `M` is the number of compaction rules or `O(N)` with no compaction."
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "<details open>\n<summary><b>Add stock prices at different timestamps</b></summary>\n\nCreate two stocks and add their prices at three different timestamps.\n\n\n127.0.0.1:6379> TS.CREATE stock:A LABELS type stock name A\nOK\n127.0.0.1:6379> TS.CREATE stock:B LABELS type stock name B\nOK\n127.0.0.1:6379> TS.MADD stock:A 1000 100 stock:A 1010 110 stock:A 1020 120 stock:B 1000 120 stock:B 1010 110 stock:B 1020 100\n1) (integer) 1000\n2) (integer) 1010\n3) (integer) 1020\n4) (integer) 1000\n5) (integer) 1010\n6) (integer) 1020\n\n</details>"
    },
    {
      "id": "redis-software-and-redis-cloud-compatibility",
      "title": "Redis Software and Redis Cloud compatibility",
      "role": "content",
      "text": "| Redis<br />Software | Redis<br />Cloud | <span style=\"min-width: 9em; display: table-cell\">Notes</span> |\n|:----------------------|:-----------------|:------|\n| <span title=\"Supported\">&#x2705; Supported</span><br /> | <span title=\"Supported\">&#x2705; Flexible & Annual</span><br /><span title=\"Supported\">&#x2705; Free & Fixed</nobr></span> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\nOne of the following:\n* [Array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays), where each element is an [Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers) representing the timestamp of a upserted sample. For each element that is ignored (see `IGNORE` in [`TS.CREATE`](https://redis.io/docs/latest/commands/ts.create)), the reply element value will be the largest timestamp in the time series.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors) in these cases: invalid arguments, wrong key type, duplication policy is `BLOCK`, or when `timestamp` is older than the retention period compared to the maximum existing timestamp.\n\n**RESP3:**\n\nOne of the following:\n* [Array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays), where each element is an [Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers) representing the timestamp of a upserted sample. For each element that is ignored (see `IGNORE` in [`TS.CREATE`](https://redis.io/docs/latest/commands/ts.create)), the reply element value will be the largest timestamp in the time series.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors) in these cases: invalid arguments, wrong key type, duplication policy is `BLOCK`, or when `timestamp` is older than the retention period compared to the maximum existing timestamp."
    },
    {
      "id": "see-also",
      "title": "See also",
      "role": "related",
      "text": "[`TS.MRANGE`](https://redis.io/docs/latest/commands/ts.mrange) | [`TS.RANGE`](https://redis.io/docs/latest/commands/ts.range) | [`TS.MREVRANGE`](https://redis.io/docs/latest/commands/ts.mrevrange) | [`TS.REVRANGE`](https://redis.io/docs/latest/commands/ts.revrange)"
    },
    {
      "id": "related-topics",
      "title": "Related topics",
      "role": "related",
      "text": "[RedisTimeSeries](https://redis.io/docs/latest/develop/data-types/timeseries)"
    }
  ],
  "examples": []
}
