...
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_ping() {
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, "pings:2024-01-01-00:00")
27
28
29
30 res1, err := rdb.SetBit(ctx, "pings:2024-01-01-00:00", 123, 1).Result()
31
32 if err != nil {
33 panic(err)
34 }
35
36 fmt.Println(res1)
37
38 res2, err := rdb.GetBit(ctx, "pings:2024-01-01-00:00", 123).Result()
39
40 if err != nil {
41 panic(err)
42 }
43
44 fmt.Println(res2)
45
46 res3, err := rdb.GetBit(ctx, "pings:2024-01-01-00:00", 456).Result()
47
48 if err != nil {
49 panic(err)
50 }
51
52 fmt.Println(res3)
53
54
55
56
57
58
59 }
60
61 func ExampleClient_bitcount() {
62 ctx := context.Background()
63
64 rdb := redis.NewClient(&redis.Options{
65 Addr: "localhost:6379",
66 Password: "",
67 DB: 0,
68 })
69
70
71
72 rdb.FlushDB(ctx)
73 _, err := rdb.SetBit(ctx, "pings:2024-01-01-00:00", 123, 1).Result()
74
75 if err != nil {
76 panic(err)
77 }
78
79
80
81 res4, err := rdb.BitCount(ctx, "pings:2024-01-01-00:00",
82 &redis.BitCount{
83 Start: 0,
84 End: 456,
85 }).Result()
86
87 if err != nil {
88 panic(err)
89 }
90
91 fmt.Println(res4)
92
93
94
95
96 }
97
View as plain text