{
  "schema_version": 2,
  "id": "commands/ts.incrby",
  "title": "TS.INCRBY",
  "url": "https://redis.io/docs/latest/commands/ts.incrby/",
  "summary": "Increase 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 increment",
  "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": "a0eb3cc59c7a8760f0ca9f99951dade3080177af4d775a8be035803b8590d4bc",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Increase 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 increment\n\n[Examples](#examples)"
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary> \n\nis key name for the time series.\n</details>\n\n<details open><summary><code>addend</code></summary> \n\nis numeric value of the addend (double). An error is returned if the addend is NaN.\n</details>\n\n<note><b>Notes</b>\n- When specified key does not exist, a new time series is created.  \n- You can use this command as a counter or gauge that automatically gets history as a time series.\n- If a policy for handling duplicate samples (`IGNORE`) is defined for this time series - `TS.INCRBY` operations are affected as well (sample additions/modifications can be filtered).\n- Explicitly adding samples to a compacted time series (using [`TS.ADD`](https://redis.io/docs/latest/commands/ts.add), [`TS.MADD`](https://redis.io/docs/latest/commands/ts.madd), `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</note>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>TIMESTAMP 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\n`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 increased. 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 plus `addend`.\n\nIf the time series is empty, the value is set to `addend`.\n\nWhen not specified, the timestamp is set to the Unix time of the server's clock.\n\n<note><b>NaN Handling (Redis 8.6+):</b> An error is returned if the current value at the maximum existing timestamp is NaN.</note>\n</details>\n\n<details open><summary><code>RETENTION retentionPeriod</code></summmary> \n\nis maximum retention period, compared to the maximum existing timestamp, in milliseconds.\n\nUse 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`](https://redis.io/docs/latest/commands/ts.create).\n</details>\n\n<details open><summary><code>ENCODING enc</code></summary> \n\nspecifies the series sample encoding format.\n\nUse 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`](https://redis.io/docs/latest/commands/ts.create).\n</details>\n\n<details open><summary><code>CHUNK_SIZE size</code></summary> \n\nis memory size, in bytes, allocated for each data chunk.\n\nUse 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`](https://redis.io/docs/latest/commands/ts.create).\n</details>\n\n<details open><summary><code>DUPLICATE_POLICY policy</code></summary>\n\nis policy for handling insertion ([`TS.ADD`](https://redis.io/docs/latest/commands/ts.add) and [`TS.MADD`](https://redis.io/docs/latest/commands/ts.madd)) of multiple samples with identical timestamps.\n\nUse it only if you are creating a new time series. It is ignored if you are adding samples to an existing time series. See `DUPLICATE_POLICY` in [`TS.CREATE`](https://redis.io/docs/latest/commands/ts.create).\n</details>\n\n<details open><summary><code>IGNORE ignoreMaxTimediff ignoreMaxValDiff</code></summary> \n\nis the policy for handling duplicate samples. A new sample is considered a duplicate and is ignored if the following conditions are met:\n\n  - The time series is not a compaction;\n  - The time series' `DUPLICATE_POLICY` IS `LAST`;\n  - The sample is added in-order (`timestamp ≥ max_timestamp`);\n  - The difference of the current timestamp from the previous timestamp (`timestamp - max_timestamp`) is less than or equal to `IGNORE_MAX_TIME_DIFF`;\n  - The absolute value difference of the current value from the value at the previous maximum timestamp (`abs(value - value_at_max_timestamp`) is less than or equal to `IGNORE_MAX_VAL_DIFF`.\n\nwhere `max_timestamp` is the timestamp of the sample with the largest timestamp in the time series, and `value_at_max_timestamp` is the value at `max_timestamp`.\n\nWhen not specified: set to the global [IGNORE_MAX_TIME_DIFF](https://redis.io/docs/latest/develop/data-types/timeseries/configuration#ignore_max_time_diff-and-ignore_max_val_diff) and [IGNORE_MAX_VAL_DIFF](https://redis.io/docs/latest/develop/data-types/timeseries/configuration#ignore_max_time_diff-and-ignore_max_val_diff), which are, by default, both set to 0.\n\nThese parameters are used when creating a new time series to set the per-key parameters, and are ignored when called with an existing time series (the existing per-key configuration parameters are used).\n</details>\n\n<details open><summary><code>LABELS [{label value}...]</code></summary> \n\nis set of label-value pairs that represent metadata labels of the key and serve as a secondary index.\n\nUse 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`](https://redis.io/docs/latest/commands/ts.create).\n</details>\n\n<note><b>Notes</b>\n- You can use this command to create a new time series and add a sample to it in a single command.\n  `RETENTION`, `ENCODING`, `CHUNK_SIZE`, `DUPLICATE_POLICY`, `IGNORE`, and `LABELS` are used only when creating a new time series, and ignored when adding or modifying samples in an existing time series.\n- Setting `RETENTION` and `LABELS` introduces additional time complexity.\n</note>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "<details open><summary><b>Store sum of data from several sources</b></summary> \n\nSuppose you are getting number of orders or total income per minute from several points of sale, and you want to store only the combined value. Call TS.INCRBY for each point-of-sale report.\n\n\n127.0.0.1:6379> TS.INCRBY a 232 TIMESTAMP 1657811829000\t\t// point-of-sale #1\n(integer) 1657811829000\n127.0.0.1:6379> TS.INCRBY a 157 TIMESTAMP 1657811829000\t\t// point-of-sale #2\n(integer) 1657811829000\n127.0.0.1:6379> TS.INCRBY a 432 TIMESTAMP 1657811829000\t\t// point-of-sale #3\n(integer) 1657811829000\n\n\nNote that the timestamps must arrive in non-decreasing order.\n\n\n127.0.0.1:6379> ts.incrby a 100 TIMESTAMP 50\n(error) TSDB: timestamp must be equal to or higher than the maximum existing timestamp\n\n\nYou can achieve similar results without such protection using `TS.ADD key timestamp value ON_DUPLICATE sum`.\n</details>\n\n<details open><summary><b>Count sensor captures</b></summary>\n\nSuppose a sensor ticks whenever a car is passed on a road, and you want to count occurrences. Whenever you get a tick from the sensor you can simply call:\n\n\n127.0.0.1:6379> TS.INCRBY a 1\n(integer) 1658431553109\n\n\nThe timestamp is filled automatically.\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* [Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): the timestamp of the upserted sample. If the sample is ignored (see `IGNORE` in [`TS.CREATE`](https://redis.io/docs/latest/commands/ts.create)), the reply 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, or when `timestamp` is not equal to or higher than the maximum existing timestamp.\n\n**RESP3:**\n\nOne of the following:\n* [Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): the timestamp of the upserted sample. If the sample is ignored (see `IGNORE` in [`TS.CREATE`](https://redis.io/docs/latest/commands/ts.create)), the reply 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, or when `timestamp` is not equal to or higher than the maximum existing timestamp."
    },
    {
      "id": "see-also",
      "title": "See also",
      "role": "related",
      "text": "[`TS.DECRBY`](https://redis.io/docs/latest/commands/ts.decrby) | [`TS.CREATE`](https://redis.io/docs/latest/commands/ts.create)"
    },
    {
      "id": "related-topics",
      "title": "Related topics",
      "role": "related",
      "text": "[RedisTimeSeries](https://redis.io/docs/latest/develop/data-types/timeseries)"
    }
  ],
  "examples": []
}
