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

Function ExampleClient_arr2

doctests/json_tutorial_test.go:244–347  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

242}
243
244func ExampleClient_arr2() {
245 ctx := context.Background()
246
247 rdb := redis.NewClient(&redis.Options{
248 Addr: "localhost:6379",
249 Password: "", // no password docs
250 DB: 0, // use default DB
251 })
252
253 // REMOVE_START
254 rdb.Del(ctx, "riders")
255 // REMOVE_END
256
257 // STEP_START arr2
258 res16, err := rdb.JSONSet(ctx, "riders", "$", []interface{}{}).Result()
259
260 if err != nil {
261 panic(err)
262 }
263
264 fmt.Println(res16) // >>> OK
265
266 res17, err := rdb.JSONArrAppend(ctx, "riders", "$", "\"Norem\"").Result()
267
268 if err != nil {
269 panic(err)
270 }
271
272 fmt.Println(res17) // >>> [1]
273
274 res18, err := rdb.JSONGet(ctx, "riders", "$").Result()
275
276 if err != nil {
277 panic(err)
278 }
279
280 fmt.Println(res18) // >>> [["Norem"]]
281
282 res19, err := rdb.JSONArrInsert(ctx, "riders", "$", 1,
283 "\"Prickett\"", "\"Royce\"", "\"Castilla\"",
284 ).Result()
285
286 if err != nil {
287 panic(err)
288 }
289
290 fmt.Println(res19) // [3]
291
292 res20, err := rdb.JSONGet(ctx, "riders", "$").Result()
293
294 if err != nil {
295 panic(err)
296 }
297
298 fmt.Println(res20) // >>> [["Norem", "Prickett", "Royce", "Castilla"]]
299
300 rangeStop := 1
301

Callers

nothing calls this directly

Calls 8

DelMethod · 0.65
ResultMethod · 0.65
JSONSetMethod · 0.65
JSONArrAppendMethod · 0.65
JSONGetMethod · 0.65
JSONArrInsertMethod · 0.65
JSONArrTrimWithArgsMethod · 0.65
JSONArrPopMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…