...
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_cms() {
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, "bikes:profit")
27
28
29
30 res1, err := rdb.CMSInitByProb(ctx, "bikes:profit", 0.001, 0.002).Result()
31
32 if err != nil {
33 panic(err)
34 }
35
36 fmt.Println(res1)
37
38 res2, err := rdb.CMSIncrBy(ctx, "bikes:profit",
39 "Smoky Mountain Striker", 100,
40 ).Result()
41
42 if err != nil {
43 panic(err)
44 }
45
46 fmt.Println(res2)
47
48 res3, err := rdb.CMSIncrBy(ctx, "bikes:profit",
49 "Rocky Mountain Racer", 200,
50 "Cloudy City Cruiser", 150,
51 ).Result()
52
53 if err != nil {
54 panic(err)
55 }
56
57 fmt.Println(res3)
58
59 res4, err := rdb.CMSQuery(ctx, "bikes:profit",
60 "Smoky Mountain Striker",
61 ).Result()
62
63 if err != nil {
64 panic(err)
65 }
66
67 fmt.Println(res4)
68
69 res5, err := rdb.CMSInfo(ctx, "bikes:profit").Result()
70
71 if err != nil {
72 panic(err)
73 }
74
75 fmt.Printf("Width: %v, Depth: %v, Count: %v",
76 res5.Width, res5.Depth, res5.Count)
77
78
79
80
81
82
83
84
85
86 }
87
View as plain text