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

Function Scan

internal/hscan/hscan.go:76–104  ·  view source on GitHub ↗

Scan scans the results from a key-value Redis map result set to a destination struct. The Redis keys are matched to the struct's field with the `redis` tag.

(dst interface{}, keys []interface{}, vals []interface{})

Source from the content-addressed store, hash-verified

74// Scan scans the results from a key-value Redis map result set to a destination struct.
75// The Redis keys are matched to the struct's field with the `redis` tag.
76func Scan(dst interface{}, keys []interface{}, vals []interface{}) error {
77 if len(keys) != len(vals) {
78 return errors.New("args should have the same number of keys and vals")
79 }
80
81 strct, err := Struct(dst)
82 if err != nil {
83 return err
84 }
85
86 // Iterate through the (key, value) sequence.
87 for i := 0; i < len(vals); i++ {
88 key, ok := keys[i].(string)
89 if !ok {
90 continue
91 }
92
93 val, ok := vals[i].(string)
94 if !ok {
95 continue
96 }
97
98 if err := strct.Scan(key, val); err != nil {
99 return err
100 }
101 }
102
103 return nil
104}
105
106func decodeBool(f reflect.Value, s string) error {
107 b, err := strconv.ParseBool(s)

Callers 2

ScanMethod · 0.92
hscan_test.goFile · 0.70

Calls 2

StructFunction · 0.85
ScanMethod · 0.65

Tested by

no test coverage detected