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

Function ExampleSliceCmd_Scan

example_test.go:383–412  ·  view source on GitHub ↗

ExampleSliceCmd_Scan shows how to scan the results of a multi key fetch into a struct.

()

Source from the content-addressed store, hash-verified

381// ExampleSliceCmd_Scan shows how to scan the results of a multi key fetch
382// into a struct.
383func 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
414func ExampleClient_Pipelined() {
415 var incr *redis.IntCmd

Callers

nothing calls this directly

Calls 5

FlushDBMethod · 0.65
ErrMethod · 0.65
MSetMethod · 0.65
MGetMethod · 0.65
ScanMethod · 0.65

Tested by

no test coverage detected