1
0
mirror of https://github.com/redis/go-redis.git synced 2025-06-12 14:21:52 +03:00

Add missing error checks and support for MGET in Scan()

This commit is contained in:
Kailash Nadh
2021-02-03 13:37:27 +05:30
parent e113512c18
commit 600f1665a0
2 changed files with 52 additions and 3 deletions

View File

@ -310,6 +310,39 @@ func ExampleStringStringMapCmd_Scan() {
// Output: {hello 123 true}
}
// ExampleSliceCmd_Scan shows how to scan the results of a multi key fetch
// into a struct.
func ExampleSliceCmd_Scan() {
rdb.FlushDB(ctx)
err := rdb.MSet(ctx,
"name", "hello",
"count", 123,
"correct", true).Err()
if err != nil {
panic(err)
}
res := rdb.MGet(ctx, "name", "count", "empty", "correct")
if res.Err() != nil {
panic(err)
}
type data struct {
Name string `redis:"name"`
Count int `redis:"count"`
Correct bool `redis:"correct"`
}
// Scan the results into the struct.
var d data
if err := res.Scan(&d); err != nil {
panic(err)
}
fmt.Println(d)
// Output: {hello 123 true}
}
func ExampleClient_Pipelined() {
var incr *redis.IntCmd
_, err := rdb.Pipelined(ctx, func(pipe redis.Pipeliner) error {