@@ -57,8 +57,7 @@ command, specifying a key name. Alternatively, if you use [`TS.ADD`]({{< relref
57
57
to add data to a time series key that does not exist, it is automatically created (see
58
58
[ Adding data points] ( #adding-data-points ) below for more information about ` TS.ADD ` ).
59
59
60
- <!-- < clients-example time_series_tutorial create >}}-->
61
- ``` bash
60
+ {{< clients-example time_series_tutorial create >}}
62
61
> TS.CREATE thermometer:1
63
62
OK
64
63
> TYPE thermometer:1
@@ -68,8 +67,7 @@ TSDB-TYPE
68
67
2 ) (integer) 0
69
68
.
70
69
.
71
- ```
72
- <!-- < /clients-example >}}-->
70
+ {{< /clients-example >}}
73
71
74
72
The timestamp for each data point is a 64-bit integer value. The value
75
73
represents a Unix timestamp, measured in milliseconds since the
@@ -78,10 +76,8 @@ When you create a time series, you can specify a maximum retention period for th
78
76
data, relative to the last reported timestamp. A retention period of zero means
79
77
the data does not expire.
80
78
81
- <!-- < clients-example time_series_tutorial create_retention >}} -->
82
- ``` bash
83
- # Create a new time series with a first value of 10.8 (Celsius),
84
- # recorded at time 1, with a retention period of 100ms.
79
+ {{< clients-example time_series_tutorial create_retention >}}
80
+ # Create a new time series with a first value of 10.8 (Celsius), recorded at time 1, with a retention period of 100ms.
85
81
> TS.ADD thermometer:2 1 10.8 RETENTION 100
86
82
(integer) 1
87
83
> TS.INFO thermometer:2
@@ -91,15 +87,14 @@ the data does not expire.
91
87
10 ) (integer) 100
92
88
.
93
89
.
94
- ```
95
- <!-- < /clients-example >}}-->
90
+ {{< /clients-example >}}
96
91
97
92
You can also add one or more * labels* to a time series when you create it. Labels
98
93
are name-value pairs where both the name and value are strings. You can use
99
94
the names and values to select subsets of all the available time series
100
95
for queries and aggregations.
101
96
102
- <!-- < clients-example time_series_tutorial create_labels >}} -->
97
+ {{< clients-example time_series_tutorial create_labels >}}
103
98
``` bash
104
99
> TS.ADD thermometer:3 1 10.4 LABELS location UK type Mercury
105
100
(integer) 1
@@ -118,7 +113,7 @@ for queries and aggregations.
118
113
.
119
114
.
120
115
```
121
- <!-- < /clients-example >}} -->
116
+ {{< /clients-example >}}
122
117
123
118
## Add data points
124
119
@@ -130,29 +125,29 @@ is an array containing the number of samples in each time series after the opera
130
125
If you use the ` * ` character as the timestamp, Redis will record the current
131
126
Unix time, as reported by the server's clock.
132
127
133
- <!-- < clients-example time_series_tutorial madd >}} -->
128
+ {{< clients-example time_series_tutorial madd >}}
134
129
``` bash
135
130
> TS.MADD thermometer:1 1 9.2 thermometer:1 2 9.9 thermometer:2 2 10.3
136
131
1) (integer) 1
137
132
2) (integer) 2
138
133
3) (integer) 2
139
134
```
140
- <!-- < /clients-example >}} -->
135
+ {{< /clients-example >}}
141
136
142
137
## Query data points
143
138
144
139
Use [ ` TS.GET ` ] ({{< relref "commands/ts.get/" >}}) to retrieve the data point
145
140
with the highest timestamp in a time series. This returns both the timestamp and the value.
146
141
147
- <!-- < clients-example time_series_tutorial get >}} -->
142
+ {{< clients-example time_series_tutorial get >}}
148
143
``` bash
149
144
# The last recorded temperature for thermometer:2
150
145
# was 10.3 at time 2ms.
151
146
> TS.GET thermometer:2
152
147
1) (integer) 2
153
148
2) 10.3
154
149
```
155
- <!-- < /clients-example >}} -->
150
+ {{< /clients-example >}}
156
151
157
152
Use [ ` TS.RANGE ` ] ({{< relref "commands/ts.range/" >}}) to retrieve data points
158
153
from a time series that fall within a given timestamp range. The range is inclusive,
@@ -162,7 +157,7 @@ indicate the minimum and maximum timestamps in the series. The response is
162
157
an array of timestamp-value pairs returned in ascending order by timestamp.
163
158
If you want the results in descending order, use [ ` TS.REVRANGE ` ] ({{< relref "commands/ts.revrange/" >}}) with the same parameters.
164
159
165
- <!-- < clients-example time_series_tutorial range >}} -->
160
+ {{< clients-example time_series_tutorial range >}}
166
161
``` bash
167
162
# Add 5 data points to a time series named "rg:1".
168
163
> TS.CREATE rg:1
222
217
2) 1) (integer) 0
223
218
2) 18
224
219
```
225
- <!-- < /clients-example >}} -->
220
+ {{< /clients-example >}}
226
221
227
222
Both ` TS.RANGE ` and ` TS.REVRANGE ` also let you filter results. Specify
228
223
a list of timestamps to include only samples with those exact timestamps
@@ -231,7 +226,7 @@ use this option). Specify a minimum and maximum value to include only
231
226
samples within that range. The value range is inclusive and you can
232
227
use the same value for the minimum and maximum to filter for a single value.
233
228
234
- <!-- < clients-example time_series_tutorial range_filter >}} -->
229
+ {{< clients-example time_series_tutorial range_filter >}}
235
230
``` bash
236
231
> TS.RANGE rg:1 - + FILTER_BY_TS 0 2 4
237
232
1) 1) (integer) 0
@@ -249,7 +244,7 @@ use the same value for the minimum and maximum to filter for a single value.
249
244
1) 1) (integer) 2
250
245
2) 22
251
246
```
252
- <!-- < /clients-example >}} -->
247
+ {{< /clients-example >}}
253
248
254
249
### Query multiple time series
255
250
@@ -273,7 +268,7 @@ the presence or value of a label. See the description in the
273
268
for details of the filter syntax. You can also request that
274
269
data points be returned with all their labels or with a selected subset of them.
275
270
276
- <!-- < clients-example time_series_tutorial query_multi >}} -->
271
+ {{< clients-example time_series_tutorial query_multi >}}
277
272
``` bash
278
273
# Create three new "rg:" time series (two in the US
279
274
# and one in the UK, with different units) and add some
372
367
3) 1) (integer) 1
373
368
2) 18
374
369
```
375
- <!-- < /clients-example >}} -->
370
+ {{< /clients-example >}}
376
371
377
372
## Aggregation
378
373
@@ -405,7 +400,7 @@ For example, the example below shows an aggregation with the `avg` function over
405
400
five data points in the ` rg:2 ` time series. The bucket size is 2ms, so there are three
406
401
aggregated values with only one value used to calculate the average for the last bucket.
407
402
408
- <!-- < clients-example time_series_tutorial agg >}} -->
403
+ {{< clients-example time_series_tutorial agg >}}
409
404
``` bash
410
405
> TS.RANGE rg:2 - + AGGREGATION avg 2
411
406
1) 1) (integer) 0
@@ -415,7 +410,7 @@ aggregated values with only one value used to calculate the average for the last
415
410
3) 1) (integer) 4
416
411
2) 1.78
417
412
```
418
- <!-- < /clients-example >}} -->
413
+ {{< /clients-example >}}
419
414
420
415
### Bucket alignment
421
416
@@ -424,7 +419,7 @@ the first bucket in the sequence starts. By default, the reference timestamp is
424
419
For example, the following commands create a time series and apply a ` min ` aggregation
425
420
with a bucket size of 25 milliseconds at the default zero alignment.
426
421
427
- <!-- < clients-example time_series_tutorial agg_bucket >}} -->
422
+ {{< clients-example time_series_tutorial agg_bucket >}}
428
423
``` bash
429
424
> TS.CREATE sensor3
430
425
OK
444
439
3) 1) (integer) 50
445
440
2) 5000
446
441
```
447
- <!-- < /clients-example >}} -->
442
+ {{< /clients-example >}}
448
443
449
444
The diagram below shows the aggregation buckets and their alignment to the reference timestamp
450
445
at time zero.
@@ -460,7 +455,7 @@ Bucket(25ms): |_________________________||_________________________||___________
460
455
461
456
You 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.
462
457
463
- <!-- < clients-example time_series_tutorial agg_align >}} -->
458
+ {{< clients-example time_series_tutorial agg_align >}}
464
459
``` bash
465
460
> TS.RANGE sensor3 10 70 AGGREGATION min 25 ALIGN start
466
461
1) 1) (integer) 10
@@ -470,7 +465,7 @@ You can also align the buckets to the start or end of the query range. For examp
470
465
3) 1) (integer) 60
471
466
2) 6000
472
467
```
473
- <!-- < /clients-example >}} -->
468
+ {{< /clients-example >}}
474
469
475
470
The diagram below shows this arrangement of buckets.
476
471
@@ -492,7 +487,7 @@ that have the same timestamp and the same label value (this feature is available
492
487
493
488
For 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.
494
489
495
- <!-- < clients-example time_series_tutorial agg_multi >}} -->
490
+ {{< clients-example time_series_tutorial agg_multi >}}
496
491
``` bash
497
492
> TS.CREATE wind:1 LABELS country uk
498
493
OK
558
553
3) 1) (integer) 3
559
554
2) 13
560
555
```
561
- <!-- < /clients-example >}} -->
556
+ {{< /clients-example >}}
562
557
563
558
## Compaction
564
559
@@ -580,7 +575,7 @@ only process data that is added to the source series after you create the rule.
580
575
For example, you could use the commands below to create a time series along with a
581
576
compaction rule to find the minimum reading in each period of 3ms.
582
577
583
- <!-- < clients-example time_series_tutorial create_compaction >}} -->
578
+ {{< clients-example time_series_tutorial create_compaction >}}
584
579
``` bash
585
580
# The source time series.
586
581
> TS.CREATE hyg:1
609
604
.
610
605
.
611
606
```
612
- <!-- < /clients-example >}} -->
607
+ {{< /clients-example >}}
613
608
614
609
Adding data points within the first 3ms (the first bucket) doesn't
615
610
produce any data in the compacted series. However, when you add data for
616
611
time 4 (in the second bucket), the compaction rule computes the minimum
617
612
value for the first bucket and adds it to the compacted series.
618
613
619
- <!-- < clients-example time_series_tutorial comp_add >}} -->
614
+ {{< clients-example time_series_tutorial comp_add >}}
620
615
``` bash
621
616
> TS.MADD hyg:1 0 75 hyg:1 1 77 hyg:1 2 78
622
617
1) (integer) 0
@@ -630,7 +625,7 @@ value for the first bucket and adds it to the compacted series.
630
625
1) 1) (integer) 0
631
626
2) 75
632
627
```
633
- <!-- < /clients-example >}} -->
628
+ {{< /clients-example >}}
634
629
635
630
The general strategy is that the rule does not add data to the
636
631
compaction for the latest bucket in the source series, but will add and
@@ -649,7 +644,7 @@ that fall within a given timestamp range. The range is inclusive, meaning that
649
644
samples whose timestamp equals the start or end of the range are deleted.
650
645
If you want to delete a single timestamp, use it as both the start and end of the range.
651
646
652
- <!-- < clients-example time_series_tutorial del >}} -->
647
+ {{< clients-example time_series_tutorial del >}}
653
648
``` bash
654
649
> TS.INFO thermometer:1
655
650
1) totalSamples
@@ -696,7 +691,7 @@ If you want to delete a single timestamp, use it as both the start and end of th
696
691
.
697
692
.
698
693
```
699
- <!-- < /clients-example >}} -->
694
+ {{< /clients-example >}}
700
695
701
696
## Use time series with other metrics tools
702
697
0 commit comments