1
2
3 package example_commands_test
4
5 import (
6 "context"
7 "fmt"
8
9 "github.com/redis/go-redis/v9"
10 )
11
12
13
14 func ExampleClient_tdigstart() {
15 ctx := context.Background()
16
17 rdb := redis.NewClient(&redis.Options{
18 Addr: "localhost:6379",
19 Password: "",
20 DB: 0,
21 })
22
23
24
25 rdb.FlushDB(ctx)
26 rdb.Del(ctx, "racer_ages", "bikes:sales")
27
28
29
30 res1, err := rdb.TDigestCreate(ctx, "bikes:sales").Result()
31
32 if err != nil {
33 panic(err)
34 }
35
36 fmt.Println(res1)
37
38 res2, err := rdb.TDigestAdd(ctx, "bikes:sales", 21).Result()
39
40 if err != nil {
41 panic(err)
42 }
43
44 fmt.Println(res2)
45
46 res3, err := rdb.TDigestAdd(ctx, "bikes:sales",
47 150, 95, 75, 34,
48 ).Result()
49
50 if err != nil {
51 panic(err)
52 }
53
54 fmt.Println(res3)
55
56
57
58
59
60
61
62 }
63
64 func ExampleClient_tdigcdf() {
65 ctx := context.Background()
66
67 rdb := redis.NewClient(&redis.Options{
68 Addr: "localhost:6379",
69 Password: "",
70 DB: 0,
71 })
72
73
74
75 rdb.FlushDB(ctx)
76 rdb.Del(ctx, "racer_ages", "bikes:sales")
77
78
79
80 res4, err := rdb.TDigestCreate(ctx, "racer_ages").Result()
81
82 if err != nil {
83 panic(err)
84 }
85
86 fmt.Println(res4)
87
88 res5, err := rdb.TDigestAdd(ctx, "racer_ages",
89 45.88, 44.2, 58.03, 19.76, 39.84, 69.28,
90 50.97, 25.41, 19.27, 85.71, 42.63,
91 ).Result()
92
93 if err != nil {
94 panic(err)
95 }
96
97 fmt.Println(res5)
98
99 res6, err := rdb.TDigestRank(ctx, "racer_ages", 50).Result()
100
101 if err != nil {
102 panic(err)
103 }
104
105 fmt.Println(res6)
106
107 res7, err := rdb.TDigestRank(ctx, "racer_ages", 50, 40).Result()
108
109 if err != nil {
110 panic(err)
111 }
112
113 fmt.Println(res7)
114
115
116
117
118
119
120
121 }
122
123 func ExampleClient_tdigquant() {
124 ctx := context.Background()
125
126 rdb := redis.NewClient(&redis.Options{
127 Addr: "localhost:6379",
128 Password: "",
129 DB: 0,
130 })
131
132
133
134 rdb.FlushDB(ctx)
135 rdb.Del(ctx, "racer_ages")
136
137
138 _, err := rdb.TDigestCreate(ctx, "racer_ages").Result()
139
140 if err != nil {
141 panic(err)
142 }
143
144 _, err = rdb.TDigestAdd(ctx, "racer_ages",
145 45.88, 44.2, 58.03, 19.76, 39.84, 69.28,
146 50.97, 25.41, 19.27, 85.71, 42.63,
147 ).Result()
148
149 if err != nil {
150 panic(err)
151 }
152
153
154 res8, err := rdb.TDigestQuantile(ctx, "racer_ages", 0.5).Result()
155
156 if err != nil {
157 panic(err)
158 }
159
160 fmt.Println(res8)
161
162 res9, err := rdb.TDigestByRank(ctx, "racer_ages", 4).Result()
163
164 if err != nil {
165 panic(err)
166 }
167
168 fmt.Println(res9)
169
170
171
172
173
174 }
175
176 func ExampleClient_tdigmin() {
177 ctx := context.Background()
178
179 rdb := redis.NewClient(&redis.Options{
180 Addr: "localhost:6379",
181 Password: "",
182 DB: 0,
183 })
184
185
186
187 rdb.FlushDB(ctx)
188 rdb.Del(ctx, "racer_ages")
189
190
191 _, err := rdb.TDigestCreate(ctx, "racer_ages").Result()
192
193 if err != nil {
194 panic(err)
195 }
196
197 _, err = rdb.TDigestAdd(ctx, "racer_ages",
198 45.88, 44.2, 58.03, 19.76, 39.84, 69.28,
199 50.97, 25.41, 19.27, 85.71, 42.63,
200 ).Result()
201
202 if err != nil {
203 panic(err)
204 }
205
206
207 res10, err := rdb.TDigestMin(ctx, "racer_ages").Result()
208
209 if err != nil {
210 panic(err)
211 }
212
213 fmt.Println(res10)
214
215 res11, err := rdb.TDigestMax(ctx, "racer_ages").Result()
216
217 if err != nil {
218 panic(err)
219 }
220
221 fmt.Println(res11)
222
223
224
225
226
227 }
228
229 func ExampleClient_tdigreset() {
230 ctx := context.Background()
231
232 rdb := redis.NewClient(&redis.Options{
233 Addr: "localhost:6379",
234 Password: "",
235 DB: 0,
236 })
237
238
239
240 rdb.FlushDB(ctx)
241 rdb.Del(ctx, "racer_ages")
242
243 _, err := rdb.TDigestCreate(ctx, "racer_ages").Result()
244
245 if err != nil {
246 panic(err)
247 }
248
249
250 res12, err := rdb.TDigestReset(ctx, "racer_ages").Result()
251
252 if err != nil {
253 panic(err)
254 }
255
256 fmt.Println(res12)
257
258
259
260
261 }
262
View as plain text