content/commands/ts.mget.md
{{< note >}} This command's behavior varies in clustered Redis environments. See the [multi-key operations]({{< relref "/develop/using-commands/multi-key-operations" >}}) page for more information. {{< /note >}}
Get 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.
{{< note >}} This command will reply only if the current user has read access to all keys that match the filter. Otherwise, it will reply with "(error): current user doesn't have read permission to one or more keys that match the specified filter". {{< /note >}}
filters time series based on their labels and label values. Each filter expression has one of the following syntaxes:
label!= - the time series has a label named labellabel=value - the time series has a label named label with a value equal to valuelabel=(value1,value2,...) - the time series has a label named label with a value equal to one of the values in the listlabel= - the time series does not have a label named labellabel!=value - the time series does not have a label named label with a value equal to valuelabel!=(value1,value2,...) - the time series does not have a label named label with a value equal to any of the values in the list<note><b>Notes:</b>
label=value or label=(value1,value2,...) is required.type=temperature room=study means that a time series is a temperature time series of a study room.x="y y" or x='(y y,z z)'.
</note>
is 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.
The 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.
includes in the reply all label-value pairs representing metadata labels of the time series.
If WITHLABELS or SELECTED_LABELS are not specified, by default, an empty list is reported as label-value pairs.
returns a subset of the label-value pairs that represent metadata labels of the time series.
Use when a large number of labels exists per series, but only the values of some of the labels are required.
If WITHLABELS or SELECTED_LABELS are not specified, by default, an empty list is reported as label-value pairs.
<note><b>Note:</b> The [MGET]({{< relref "/commands/mget" >}}) command cannot be part of a transaction when running on a Redis cluster.</note>
Create time series for temperature in Tel Aviv and Jerusalem, then add different temperature samples.
{{< highlight bash >}} 127.0.0.1:6379> TS.CREATE temp:TLV LABELS type temp location TLV OK 127.0.0.1:6379> TS.CREATE temp:JLM LABELS type temp location JLM OK 127.0.0.1:6379> TS.MADD temp:TLV 1000 30 temp:TLV 1010 35 temp:TLV 1020 9999 temp:TLV 1030 40
Get all the labels associated with the last sample.
{{< highlight bash >}} 127.0.0.1:6379> TS.MGET WITHLABELS FILTER type=temp
To get only the location label for each last sample, use SELECTED_LABELS.
{{< highlight bash >}} 127.0.0.1:6379> TS.MGET SELECTED_LABELS location FILTER type=temp
| 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> | |
{{< multitabs id="ts-mget-return-info" tab1="RESP2" tab2="RESP3" >}}
[Array reply]({{< relref "/develop/reference/protocol-spec#arrays" >}}): for each time series matching the specified filters, the following is reported:
WITHLABELS is specified, all labels associated with this time series are reportedSELECTED_LABELS label... is specified, the selected labels are reported (null value when no such label defined)-tab-sep-
[Map reply]({{< relref "/develop/reference/protocol-spec#maps" >}}): for each time series matching the specified filters, the following is reported:
WITHLABELS is specified, all labels associated with this time series are reported as a mapSELECTED_LABELS label... is specified, the selected labels are reported as a map (null value when no such label defined){{< /multitabs >}}
[TS.MRANGE]({{< relref "commands/ts.mrange/" >}}) | [TS.RANGE]({{< relref "commands/ts.range/" >}}) | [TS.MREVRANGE]({{< relref "commands/ts.mrevrange/" >}}) | [TS.REVRANGE]({{< relref "commands/ts.revrange/" >}})
[RedisTimeSeries]({{< relref "/develop/data-types/timeseries/" >}})