...
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_topk() {
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:keywords")
27
28
29
30 res1, err := rdb.TopKReserve(ctx, "bikes:keywords", 5).Result()
31
32 if err != nil {
33 panic(err)
34 }
35
36 fmt.Println(res1)
37
38 res2, err := rdb.TopKAdd(ctx, "bikes:keywords",
39 "store",
40 "seat",
41 "handlebars",
42 "handles",
43 "pedals",
44 "tires",
45 "store",
46 "seat",
47 ).Result()
48
49 if err != nil {
50 panic(err)
51 }
52
53 fmt.Println(res2)
54
55 res3, err := rdb.TopKList(ctx, "bikes:keywords").Result()
56
57 if err != nil {
58 panic(err)
59 }
60
61 fmt.Println(res3)
62
63 res4, err := rdb.TopKQuery(ctx, "bikes:keywords", "store", "handlebars").Result()
64
65 if err != nil {
66 panic(err)
67 }
68
69 fmt.Println(res4)
70
71
72
73
74
75
76
77 }
78
View as plain text