ExampleSliceCmd_Scan shows how to scan the results of a multi key fetch into a struct.
()
| 381 | // ExampleSliceCmd_Scan shows how to scan the results of a multi key fetch |
| 382 | // into a struct. |
| 383 | func ExampleSliceCmd_Scan() { |
| 384 | rdb.FlushDB(ctx) |
| 385 | err := rdb.MSet(ctx, |
| 386 | "name", "hello", |
| 387 | "count", 123, |
| 388 | "correct", true).Err() |
| 389 | if err != nil { |
| 390 | panic(err) |
| 391 | } |
| 392 | |
| 393 | res := rdb.MGet(ctx, "name", "count", "empty", "correct") |
| 394 | if res.Err() != nil { |
| 395 | panic(res.Err()) |
| 396 | } |
| 397 | |
| 398 | type data struct { |
| 399 | Name string `redis:"name"` |
| 400 | Count int `redis:"count"` |
| 401 | Correct bool `redis:"correct"` |
| 402 | } |
| 403 | |
| 404 | // Scan the results into the struct. |
| 405 | var d data |
| 406 | if err := res.Scan(&d); err != nil { |
| 407 | panic(err) |
| 408 | } |
| 409 | |
| 410 | fmt.Println(d) |
| 411 | // Output: {hello 123 true} |
| 412 | } |
| 413 | |
| 414 | func ExampleClient_Pipelined() { |
| 415 | var incr *redis.IntCmd |