content/commands/ts.get.md
Get the sample with the highest timestamp from a given time series. Starting from Redis 8.6, NaN values are included in the results.
is key name for the time series.
</details>is used when a time series is a compaction. With LATEST, TS.GET reports the compacted value of the latest (possibly partial) bucket. Without LATEST, TS.GET 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 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.
Create a time series to store the temperatures measured in Tel Aviv and add four measurements for Sun Jan 01 2023
{{< highlight bash >}} 127.0.0.1:6379> TS.CREATE temp:TLV LABELS type temp location TLV OK 127.0.0.1:6379> TS.MADD temp:TLV 1672534800 12 temp:TLV 1672556400 16 temp:TLV 1672578000 21 temp:TLV 1672599600 14 {{< / highlight >}}
Next, get the latest measured temperature (the temperature with the highest timestamp)
{{< highlight bash >}} 127.0.0.1:6379> TS.GET temp:TLV
Create a time series to store the temperatures measured in Jerusalem
{{< highlight bash >}} 127.0.0.1:6379> TS.CREATE temp:JLM LABELS type temp location JLM OK {{< / highlight >}}
Next, create a compacted time series named dailyAvgTemp:JLM containing one compacted sample per 24 hours: the maximum of all measurements taken from midnight to next midnight.
{{< highlight bash >}} 127.0.0.1:6379> TS.CREATE dailyMaxTemp:JLM LABELS type temp location JLM OK 127.0.0.1:6379> TS.CREATERULE temp:JLM dailyMaxTemp:JLM AGGREGATION max 86400000 OK {{< / highlight >}}
Add four measurements for Sun Jan 01 2023 and three measurements for Mon Jan 02 2023
{{< highlight bash >}} 127.0.0.1:6379> TS.MADD temp:JLM 1672534800000 12 temp:JLM 1672556400000 16 temp:JLM 1672578000000 21 temp:JLM 1672599600000 14
Next, get the latest maximum daily temperature; do not report the latest, possibly partial, bucket
{{< highlight bash >}} 127.0.0.1:6379> TS.GET dailyMaxTemp:JLM
Get the latest maximum daily temperature (the temperature with the highest timestamp); report the latest, possibly partial, bucket
{{< highlight bash >}} 127.0.0.1:6379> TS.GET dailyMaxTemp:JLM LATEST
| 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-get-return-info" tab1="RESP2" tab2="RESP3" >}}
One of the following:
-tab-sep-
One of the following:
{{< /multitabs >}}
[TS.MGET]({{< relref "commands/ts.mget/" >}})
[RedisTimeSeries]({{< relref "/develop/data-types/timeseries/" >}})