@@ -50,6 +50,7 @@ command, specifying a key name. Alternatively, if you use [`TS.ADD`]({{< relref
5050to add data to a time series key that does not exist, it is automatically created (see
5151[ Adding data points] ( #adding-data-points ) below for more information about ` TS.ADD ` ).
5252
53+ <!-- < clients-example time_series_tutorial create >}}-->
5354``` bash
5455> TS.CREATE thermometer:1
5556OK
@@ -61,6 +62,7 @@ TSDB-TYPE
6162 .
6263 .
6364```
65+ <!-- < /clients-example >}}-->
6466
6567The timestamp for each data point is a 64-bit integer value. The value
6668represents a Unix timestamp, measured in milliseconds since the
@@ -69,6 +71,7 @@ When you create a time series, you can specify a maximum retention period for th
6971data, relative to the last reported timestamp. A retention period of zero means
7072the data does not expire.
7173
74+ <!-- < clients-example time_series_tutorial create_retention >}} -->
7275``` bash
7376# Create a new time series with a first value of 10.8 (Celsius),
7477# recorded at time 1, with a retention period of 100ms.
@@ -82,12 +85,14 @@ the data does not expire.
8285 .
8386 .
8487```
88+ <!-- < /clients-example >}}-->
8589
8690You can also add one or more * labels* to a time series when you create it. Labels
8791are name-value pairs where both the name and value are strings. You can use
8892the names and values to select subsets of all the available time series
8993for queries and aggregations.
9094
95+ <!-- < clients-example time_series_tutorial create_labels >}} -->
9196``` bash
9297> TS.ADD thermometer:3 1 10.4 LABELS location UK type Mercury
9398(integer) 1
@@ -106,6 +111,7 @@ for queries and aggregations.
106111 .
107112 .
108113```
114+ <!-- < /clients-example >}} -->
109115
110116## Add data points
111117
@@ -117,25 +123,29 @@ is an array containing the number of samples in each time series after the opera
117123If you use the ` * ` character as the timestamp, Redis will record the current
118124Unix time, as reported by the server's clock.
119125
126+ <!-- < clients-example time_series_tutorial madd >}} -->
120127``` bash
121128> TS.MADD thermometer:1 1 9.2 thermometer:1 2 9.9 thermometer:2 2 10.3
1221291) (integer) 1
1231302) (integer) 2
1241313) (integer) 2
125132```
133+ <!-- < /clients-example >}} -->
126134
127135## Query data points
128136
129137Use [ ` TS.GET ` ] ({{< relref "commands/ts.get/" >}}) to retrieve the data point
130138with the highest timestamp in a time series. This returns both the timestamp and the value.
131139
140+ <!-- < clients-example time_series_tutorial get >}} -->
132141``` bash
133142# The last recorded temperature for thermometer:2
134143# was 10.3 at time 2ms.
135144> TS.GET thermometer:2
1361451) (integer) 2
1371462) 10.3
138147```
148+ <!-- < /clients-example >}} -->
139149
140150Use [ ` TS.RANGE ` ] ({{< relref "commands/ts.range/" >}}) to retrieve data points
141151from a time series that fall within a given timestamp range. The range is inclusive,
@@ -145,6 +155,7 @@ indicate the minimum and maximum timestamps in the series. The response is
145155an array of timestamp-value pairs returned in ascending order by timestamp.
146156If you want the results in descending order, use [ ` TS.REVRANGE ` ] ({{< relref "commands/ts.revrange/" >}}) with the same parameters.
147157
158+ <!-- < clients-example time_series_tutorial range >}} -->
148159``` bash
149160# Add 5 data points to a time series named "rg:1".
150161> TS.CREATE rg:1
2042152) 1) (integer) 0
205216 2) 18
206217```
218+ <!-- < /clients-example >}} -->
207219
208220Both ` TS.RANGE ` and ` TS.REVRANGE ` also let you filter results. Specify
209221a list of timestamps to include only samples with those exact timestamps
@@ -212,6 +224,7 @@ use this option). Specify a minimum and maximum value to include only
212224samples within that range. The value range is inclusive and you can
213225use the same value for the minimum and maximum to filter for a single value.
214226
227+ <!-- < clients-example time_series_tutorial range_filter >}} -->
215228``` bash
216229> TS.RANGE rg:1 - + FILTER_BY_TS 0 2 4
2172301) 1) (integer) 0
@@ -229,6 +242,7 @@ use the same value for the minimum and maximum to filter for a single value.
2292421) 1) (integer) 2
230243 2) 22
231244```
245+ <!-- < /clients-example >}} -->
232246
233247### Query multiple time series
234248
@@ -252,8 +266,9 @@ the presence or value of a label. See the description in the
252266for details of the filter syntax. You can also request that
253267data points be returned with all their labels or with a selected subset of them.
254268
269+ <!-- < clients-example time_series_tutorial query_multi >}} -->
255270``` bash
256- # Create three new "rg: time series (two in the US
271+ # Create three new "rg:" time series (two in the US
257272# and one in the UK, with different units) and add some
258273# data points.
259274> TS.CREATE rg:2 LABELS location us unit cm
350365 3) 1) (integer) 1
351366 2) 18
352367```
368+ <!-- < /clients-example >}} -->
353369
354370## Aggregation
355371
@@ -382,6 +398,7 @@ For example, the example below shows an aggregation with the `avg` function over
382398five data points in the ` rg:2 ` time series. The bucket size is 2ms, so there are three
383399aggregated values with only one value used to calculate the average for the last bucket.
384400
401+ <!-- < clients-example time_series_tutorial agg >}} -->
385402``` bash
386403> TS.RANGE rg:2 - + AGGREGATION avg 2
3874041) 1) (integer) 0
@@ -391,6 +408,7 @@ aggregated values with only one value used to calculate the average for the last
3914083) 1) (integer) 4
392409 2) 1.78
393410```
411+ <!-- < /clients-example >}} -->
394412
395413### Bucket alignment
396414
@@ -399,6 +417,7 @@ the first bucket in the sequence starts. By default, the reference timestamp is
399417For example, the following commands create a time series and apply a ` min ` aggregation
400418with a bucket size of 25 milliseconds at the default zero alignment.
401419
420+ <!-- < clients-example time_series_tutorial agg_bucket >}} -->
402421``` bash
403422> TS.CREATE sensor3
404423OK
4184373) 1) (integer) 50
419438 2) 5000
420439```
440+ <!-- < /clients-example >}} -->
421441
422442The diagram below shows the aggregation buckets and their alignment to the reference timestamp
423443at time zero.
@@ -433,6 +453,7 @@ Bucket(25ms): |_________________________||_________________________||___________
433453
434454You can also align the buckets to the start or end of the query range. For example, the following command aligns the buckets to the start of the query range at time 10.
435455
456+ <!-- < clients-example time_series_tutorial agg_align >}} -->
436457``` bash
437458> TS.RANGE sensor3 10 70 AGGREGATION min 25 ALIGN start
4384591) 1) (integer) 10
@@ -442,6 +463,7 @@ You can also align the buckets to the start or end of the query range. For examp
4424633) 1) (integer) 60
443464 2) 6000
444465```
466+ <!-- < /clients-example >}} -->
445467
446468The diagram below shows this arrangement of buckets.
447469
@@ -463,6 +485,7 @@ that have the same timestamp and the same label value (this feature is available
463485
464486For example, the following commands create four time series, two for the UK and two for the US, and add some data points. The first ` TS.MRANGE ` command groups the results by country and applies a ` max ` aggregation to find the maximum sample value in each country at each timestamp. The second ` TS.MRANGE ` command uses the same grouping, but applies an ` avg ` aggregation.
465487
488+ <!-- < clients-example time_series_tutorial agg_multi >}} -->
466489``` bash
467490> TS.CREATE wind:1 LABELS country uk
468491OK
528551 3) 1) (integer) 3
529552 2) 13
530553```
554+ <!-- < /clients-example >}} -->
531555
532556## Compaction
533557
@@ -549,6 +573,7 @@ only process data that is added to the source series after you create the rule.
549573For example, you could use the commands below to create a time series along with a
550574compaction rule to find the minimum reading in each period of 3ms.
551575
576+ <!-- < clients-example time_series_tutorial create_compaction >}} -->
552577``` bash
553578# The source time series.
554579> TS.CREATE hyg:1
577602 .
578603 .
579604```
605+ <!-- < /clients-example >}} -->
580606
581607Adding data points within the first 3ms (the first bucket) doesn't
582608produce any data in the compacted series. However, when you add data for
583609time 4 (in the second bucket), the compaction rule computes the minimum
584610value for the first bucket and adds it to the compacted series.
585611
612+ <!-- < clients-example time_series_tutorial comp_add >}} -->
586613``` bash
587614> TS.MADD hyg:1 0 75 hyg:1 1 77 hyg:1 2 78
5886151) (integer) 0
@@ -596,6 +623,7 @@ value for the first bucket and adds it to the compacted series.
5966231) 1) (integer) 0
597624 2) 75
598625```
626+ <!-- < /clients-example >}} -->
599627
600628The general strategy is that the rule does not add data to the
601629compaction for the latest bucket in the source series, but will add and
@@ -614,6 +642,7 @@ that fall within a given timestamp range. The range is inclusive, meaning that
614642samples whose timestamp equals the start or end of the range are deleted.
615643If you want to delete a single timestamp, use it as both the start and end of the range.
616644
645+ <!-- < clients-example time_series_tutorial del >}} -->
617646``` bash
618647> TS.INFO thermometer:1
619648 1) totalSamples
@@ -660,6 +689,7 @@ If you want to delete a single timestamp, use it as both the start and end of th
660689 .
661690 .
662691```
692+ <!-- < /clients-example >}} -->
663693
664694## Use time series with other metrics tools
665695
0 commit comments