...
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_cmd_incr() {
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, "mykey")
27
28
29
30 incrResult1, err := rdb.Set(ctx, "mykey", "10", 0).Result()
31
32 if err != nil {
33 panic(err)
34 }
35
36 fmt.Println(incrResult1)
37
38 incrResult2, err := rdb.Incr(ctx, "mykey").Result()
39
40 if err != nil {
41 panic(err)
42 }
43
44 fmt.Println(incrResult2)
45
46 incrResult3, err := rdb.Get(ctx, "mykey").Result()
47
48 if err != nil {
49 panic(err)
50 }
51
52 fmt.Println(incrResult3)
53
54
55
56
57
58
59 }
60
View as plain text