@@ -67,6 +67,9 @@ func Struct(dst interface{}) (StructValue, error) {
6767
6868// Scan scans the results from a key-value Redis map result set to a destination struct.
6969// The Redis keys are matched to the struct's field with the `redis` tag.
70+ // This method will attempt to unmarshal each field and will return an error if any of the
71+ // fields cannot be unmarshalled. The destination struct will have the failed fields set to
72+ // their zero value.
7073func Scan (dst interface {}, keys []interface {}, vals []interface {}) error {
7174 if len (keys ) != len (vals ) {
7275 return errors .New ("args should have the same number of keys and vals" )
@@ -77,6 +80,8 @@ func Scan(dst interface{}, keys []interface{}, vals []interface{}) error {
7780 return err
7881 }
7982
83+ scanErrors := []error {}
84+
8085 // Iterate through the (key, value) sequence.
8186 for i := 0 ; i < len (vals ); i ++ {
8287 key , ok := keys [i ].(string )
@@ -90,10 +95,14 @@ func Scan(dst interface{}, keys []interface{}, vals []interface{}) error {
9095 }
9196
9297 if err := strct .Scan (key , val ); err != nil {
93- return err
98+ scanErrors = append ( scanErrors , err )
9499 }
95100 }
96101
102+ if len (scanErrors ) > 0 {
103+ return fmt .Errorf ("scan errors: %v" , scanErrors )
104+ }
105+
97106 return nil
98107}
99108
0 commit comments