...
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 func ExampleClient_Set_and_get() {
13 ctx := context.Background()
14
15 rdb := redis.NewClient(&redis.Options{
16 Addr: "localhost:6379",
17 Password: "",
18 DB: 0,
19 })
20
21
22
23
24
25 rdb.FlushDB(ctx)
26 errFlush := rdb.FlushDB(ctx).Err()
27 if errFlush != nil {
28 panic(errFlush)
29 }
30
31
32 err := rdb.Set(ctx, "bike:1", "Process 134", 0).Err()
33 if err != nil {
34 panic(err)
35 }
36
37 fmt.Println("OK")
38
39 value, err := rdb.Get(ctx, "bike:1").Result()
40 if err != nil {
41 panic(err)
42 }
43 fmt.Printf("The name of the bike is %s", value)
44
45
46
47
48 }
49
50
51
View as plain text