{
  "schema_version": 2,
  "id": "commands/ts.mget",
  "title": "TS.MGET",
  "url": "https://redis.io/docs/latest/commands/ts.mget/",
  "summary": "Get the sample with the highest timestamp from each time series matching a specific filter",
  "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": "8e58f93b706fcdc09b20bc01686fd02b8e1d9960c8f651d7e31576c111cbd68a",
  "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\nGet the sample with the highest timestamp from each time series matching a specific filter. Starting from Redis 8.6, NaN values are included in the results.\n\n> [!NOTE]\n> This command will reply only if the current user has read access to all keys that match the filter.\n> Otherwise, it will reply with \"*(error): current user doesn't have read permission to one or more keys that match the specified filter*\".\n\n[Examples](#examples)"
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open>\n<summary><code>FILTER filterExpr...</code></summary>\n\nfilters time series based on their labels and label values.\n\nEach filter expression has one of the following syntaxes:\n\n  - `label!=` - the time series has a label named `label`\n  - `label=value` - the time series has a label named `label` with a value equal to `value`\n  - `label=(value1,value2,...)` - the time series has a label named `label` with a value equal to one of the values in the list\n  - `label=` - the time series does not have a label named `label`\n  - `label!=value` - the time series does not have a label named `label` with a value equal to `value`\n  - `label!=(value1,value2,...)` - the time series does not have a label named `label` with a value equal to any of the values in the list\n\n  <note><b>Notes:</b>\n   - At least one filter expression with a syntax `label=value` or `label=(value1,value2,...)` is required.\n   - Filter expressions are conjunctive. For example, the filter `type=temperature room=study` means that `type=temperature` AND `room=study`.\n   - Whitespace is not allowed in a filter expression except between quotes or double quotes in values - for example, `x=\"y y\"` or `x='(y y,z z)'`.\n   </note>\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open>\n<summary><code>LATEST</code> (since RedisTimeSeries v1.8)</summary> \n\nis used when a time series is a compaction. With `LATEST`, TS.MGET also reports the compacted value of the latest (possibly partial) bucket, given that this bucket's start time falls within `[fromTimestamp, toTimestamp]`. Without `LATEST`, TS.MGET does not report the latest (possibly partial) bucket. When a time series is not a compaction, `LATEST` is ignored.\n  \nThe data in the latest bucket of a compaction is possibly partial. A bucket is _closed_ and compacted only upon the arrival of a new sample that _opens_ a new _latest_ bucket. There are cases, however, when the compacted value of the latest (possibly partial) bucket is also required. In such a case, use `LATEST`.\n</details>\n\n<details open>\n<summary><code>WITHLABELS</code></summary> \n\nincludes in the reply all label-value pairs representing metadata labels of the time series. \nIf `WITHLABELS` or `SELECTED_LABELS` are not specified, by default, an empty list is reported as label-value pairs.\n\n</details>\n\n<details open>\n<summary><code>SELECTED_LABELS label...</code> (since RedisTimeSeries v1.6)</summary> \n\nreturns a subset of the label-value pairs that represent metadata labels of the time series. \nUse when a large number of labels exists per series, but only the values of some of the labels are required. \nIf `WITHLABELS` or `SELECTED_LABELS` are not specified, by default, an empty list is reported as label-value pairs.\n\n</details>\n\n<note><b>Note:</b> The [`MGET`](https://redis.io/docs/latest/commands/mget) command cannot be part of a transaction when running on a Redis cluster.</note>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "<details open>\n<summary><b>Select labels to retrieve</b></summary>\n\nCreate time series for temperature in Tel Aviv and Jerusalem, then add different temperature samples.\n\n\nredis> TS.CREATE temp:TLV LABELS type temp location TLV\nOK\nredis> TS.CREATE temp:JLM LABELS type temp location JLM\nOK\nredis> TS.MADD temp:TLV 1000 30 temp:TLV 1010 35 temp:TLV 1020 9999 temp:TLV 1030 40\n1) (integer) 1000\n2) (integer) 1010\n3) (integer) 1020\n4) (integer) 1030\nredis> TS.MADD temp:JLM 1005 30 temp:JLM 1015 35 temp:JLM 1025 9999 temp:JLM 1035 40\n1) (integer) 1005\n2) (integer) 1015\n3) (integer) 1025\n4) (integer) 1035\n\n\nGet all the labels associated with the last sample.\n\n\nredis> TS.MGET WITHLABELS FILTER type=temp\n1) 1) \"temp:JLM\"\n   2) 1) 1) \"type\"\n         2) \"temp\"\n      2) 1) \"location\"\n         2) \"JLM\"\n   3) 1) (integer) 1035\n      2) 40\n2) 1) \"temp:TLV\"\n   2) 1) 1) \"type\"\n         2) \"temp\"\n      2) 1) \"location\"\n         2) \"TLV\"\n   3) 1) (integer) 1030\n      2) 40\n\n\nTo get only the `location` label for each last sample, use `SELECTED_LABELS`.\n\n\nredis> TS.MGET SELECTED_LABELS location FILTER type=temp\n1) 1) \"temp:JLM\"\n   2) 1) 1) \"location\"\n         2) \"JLM\"\n   3) 1) (integer) 1035\n      2) 40\n2) 1) \"temp:TLV\"\n   2) 1) 1) \"location\"\n         2) \"TLV\"\n   3) 1) (integer) 1030\n      2) 40\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\n[Array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays): for each time series matching the specified filters, the following is reported:\n- [Bulk string reply](https://redis.io/docs/latest/develop/reference/protocol-spec#bulk-strings): The time series key name\n- [Array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays): label-value pairs ([Bulk string reply](https://redis.io/docs/latest/develop/reference/protocol-spec#bulk-strings), [Bulk string reply](https://redis.io/docs/latest/develop/reference/protocol-spec#bulk-strings))\n  - By default, an empty array is reported\n  - If `WITHLABELS` is specified, all labels associated with this time series are reported\n  - If `SELECTED_LABELS label...` is specified, the selected labels are reported (null value when no such label defined)\n- [Array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays): a single timestamp-value pair ([Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers), [Simple string reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-strings))\n\n**RESP3:**\n\n[Map reply](https://redis.io/docs/latest/develop/reference/protocol-spec#maps): for each time series matching the specified filters, the following is reported:\n- [Bulk string reply](https://redis.io/docs/latest/develop/reference/protocol-spec#bulk-strings): The time series key name\n- [Map reply](https://redis.io/docs/latest/develop/reference/protocol-spec#maps) or [Array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays): label-value pairs\n  - By default, an empty array is reported\n  - If `WITHLABELS` is specified, all labels associated with this time series are reported as a map\n  - If `SELECTED_LABELS label...` is specified, the selected labels are reported as a map (null value when no such label defined)\n- [Array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays): a single timestamp-value pair ([Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers), [Double reply](https://redis.io/docs/latest/develop/reference/protocol-spec#doubles))"
    },
    {
      "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": []
}
