MCPcopy
hub / github.com/redis/go-redis / ExampleClient_setget

Function ExampleClient_setget

doctests/json_tutorial_test.go:13–60  ·  view source on GitHub ↗

HIDE_END

()

Source from the content-addressed store, hash-verified

11
12// HIDE_END
13func ExampleClient_setget() {
14 ctx := context.Background()
15
16 rdb := redis.NewClient(&redis.Options{
17 Addr: "localhost:6379",
18 Password: "", // no password docs
19 DB: 0, // use default DB
20 })
21
22 // REMOVE_START
23 // make sure we are working with fresh database
24 rdb.FlushDB(ctx)
25 rdb.Del(ctx, "bike")
26 // REMOVE_END
27
28 // STEP_START set_get
29 res1, err := rdb.JSONSet(ctx, "bike", "$",
30 "\"Hyperion\"",
31 ).Result()
32
33 if err != nil {
34 panic(err)
35 }
36
37 fmt.Println(res1) // >>> OK
38
39 res2, err := rdb.JSONGet(ctx, "bike", "$").Result()
40
41 if err != nil {
42 panic(err)
43 }
44
45 fmt.Println(res2) // >>> ["Hyperion"]
46
47 res3, err := rdb.JSONType(ctx, "bike", "$").Result()
48
49 if err != nil {
50 panic(err)
51 }
52
53 fmt.Println(res3) // >>> [[string]]
54 // STEP_END
55
56 // Output:
57 // OK
58 // ["Hyperion"]
59 // [[string]]
60}
61
62func ExampleClient_str() {
63 ctx := context.Background()

Callers

nothing calls this directly

Calls 6

FlushDBMethod · 0.65
DelMethod · 0.65
ResultMethod · 0.65
JSONSetMethod · 0.65
JSONGetMethod · 0.65
JSONTypeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…