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

Function ExampleClient_arr

doctests/json_tutorial_test.go:173–242  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

171}
172
173func ExampleClient_arr() {
174 ctx := context.Background()
175
176 rdb := redis.NewClient(&redis.Options{
177 Addr: "localhost:6379",
178 Password: "", // no password docs
179 DB: 0, // use default DB
180 })
181
182 // REMOVE_START
183 // start with fresh database
184 rdb.FlushDB(ctx)
185 rdb.Del(ctx, "newbike")
186 // REMOVE_END
187
188 // STEP_START arr
189 res11, err := rdb.JSONSet(ctx, "newbike", "$",
190 []interface{}{
191 "Deimos",
192 map[string]interface{}{"crashes": 0},
193 nil,
194 },
195 ).Result()
196
197 if err != nil {
198 panic(err)
199 }
200
201 fmt.Println(res11) // >>> OK
202
203 res12, err := rdb.JSONGet(ctx, "newbike", "$").Result()
204
205 if err != nil {
206 panic(err)
207 }
208
209 fmt.Println(res12) // >>> [["Deimos",{"crashes":0},null]]
210
211 res13, err := rdb.JSONGet(ctx, "newbike", "$[1].crashes").Result()
212
213 if err != nil {
214 panic(err)
215 }
216
217 fmt.Println(res13) // >>> [0]
218
219 res14, err := rdb.JSONDel(ctx, "newbike", "$.[-1]").Result()
220
221 if err != nil {
222 panic(err)
223 }
224
225 fmt.Println(res14) // >>> 1
226
227 res15, err := rdb.JSONGet(ctx, "newbike", "$").Result()
228
229 if err != nil {
230 panic(err)

Callers

nothing calls this directly

Calls 6

FlushDBMethod · 0.65
DelMethod · 0.65
ResultMethod · 0.65
JSONSetMethod · 0.65
JSONGetMethod · 0.65
JSONDelMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…