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

Function ExampleClient_str

doctests/json_tutorial_test.go:62–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60}
61
62func ExampleClient_str() {
63 ctx := context.Background()
64
65 rdb := redis.NewClient(&redis.Options{
66 Addr: "localhost:6379",
67 Password: "", // no password docs
68 DB: 0, // use default DB
69 })
70
71 // REMOVE_START
72 // start with fresh database
73 rdb.FlushDB(ctx)
74 rdb.Del(ctx, "bike")
75 // REMOVE_END
76
77 _, err := rdb.JSONSet(ctx, "bike", "$",
78 "\"Hyperion\"",
79 ).Result()
80
81 if err != nil {
82 panic(err)
83 }
84
85 // STEP_START str
86 res4, err := rdb.JSONStrLen(ctx, "bike", "$").Result()
87
88 if err != nil {
89 panic(err)
90 }
91
92 fmt.Println(*res4[0]) // >>> 8
93
94 res5, err := rdb.JSONStrAppend(ctx, "bike", "$", "\" (Enduro bikes)\"").Result()
95
96 if err != nil {
97 panic(err)
98 }
99
100 fmt.Println(*res5[0]) // >>> 23
101
102 res6, err := rdb.JSONGet(ctx, "bike", "$").Result()
103
104 if err != nil {
105 panic(err)
106 }
107
108 fmt.Println(res6) // >>> ["Hyperion (Enduro bikes)"]
109 // STEP_END
110
111 // Output:
112 // 8
113 // 23
114 // ["Hyperion (Enduro bikes)"]
115}
116
117func ExampleClient_num() {
118 ctx := context.Background()

Callers

nothing calls this directly

Calls 7

FlushDBMethod · 0.65
DelMethod · 0.65
ResultMethod · 0.65
JSONSetMethod · 0.65
JSONStrLenMethod · 0.65
JSONStrAppendMethod · 0.65
JSONGetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…