MCPcopy
hub / github.com/redis/go-redis / ExampleClient_timeseries_create

Function ExampleClient_timeseries_create

doctests/timeseries_tut_test.go:18–116  ·  view source on GitHub ↗

HIDE_END

()

Source from the content-addressed store, hash-verified

16// HIDE_END
17
18func ExampleClient_timeseries_create() {
19 ctx := context.Background()
20
21 rdb := redis.NewClient(&redis.Options{
22 Addr: "localhost:6379",
23 Password: "", // no password set
24 DB: 0, // use default DB
25 })
26
27 // REMOVE_START
28 // make sure we are working with fresh database
29 rdb.FlushDB(ctx)
30 rdb.Del(ctx, "thermometer:1", "thermometer:2", "thermometer:3")
31 // REMOVE_END
32
33 // STEP_START create
34 res1, err := rdb.TSCreate(ctx, "thermometer:1").Result()
35 if err != nil {
36 panic(err)
37 }
38
39 fmt.Println(res1) // >>> OK
40
41 res2, err := rdb.Type(ctx, "thermometer:1").Result()
42 if err != nil {
43 panic(err)
44 }
45
46 fmt.Println(res2) // >>> TSDB-TYPE
47
48 res3, err := rdb.TSInfo(ctx, "thermometer:1").Result()
49 if err != nil {
50 panic(err)
51 }
52
53 fmt.Println(res3["totalSamples"]) // >>> 0
54 // STEP_END
55
56 // STEP_START create_retention
57 res4, err := rdb.TSAddWithArgs(
58 ctx,
59 "thermometer:2",
60 1,
61 10.8,
62 &redis.TSOptions{
63 Retention: 100,
64 },
65 ).Result()
66 if err != nil {
67 panic(err)
68 }
69
70 fmt.Println(res4) // >>> 1
71
72 res5, err := rdb.TSInfo(ctx, "thermometer:2").Result()
73 if err != nil {
74 panic(err)
75 }

Callers

nothing calls this directly

Calls 7

FlushDBMethod · 0.65
DelMethod · 0.65
ResultMethod · 0.65
TSCreateMethod · 0.65
TypeMethod · 0.65
TSInfoMethod · 0.65
TSAddWithArgsMethod · 0.65

Tested by

no test coverage detected