@@ -3862,30 +3862,48 @@ func (cmd *MapMapStringInterfaceCmd) Val() map[string]interface{} {
3862
3862
return cmd .val
3863
3863
}
3864
3864
3865
+ // readReply will try to parse the reply from the proto.Reader for both resp2 and resp3
3865
3866
func (cmd * MapMapStringInterfaceCmd ) readReply (rd * proto.Reader ) (err error ) {
3866
- n , err := rd .ReadArrayLen ()
3867
+ data , err := rd .ReadReply ()
3867
3868
if err != nil {
3868
3869
return err
3869
3870
}
3871
+ resultMap := map [string ]interface {}{}
3870
3872
3871
- data := make (map [string ]interface {}, n / 2 )
3872
- for i := 0 ; i < n ; i += 2 {
3873
- _ , err := rd .ReadArrayLen ()
3874
- if err != nil {
3875
- cmd .err = err
3876
- }
3877
- key , err := rd .ReadString ()
3878
- if err != nil {
3879
- cmd .err = err
3873
+ switch midResponse := data .(type ) {
3874
+ case map [interface {}]interface {}: // resp3 will return map
3875
+ for k , v := range midResponse {
3876
+ stringKey , ok := k .(string )
3877
+ if ! ok {
3878
+ return fmt .Errorf ("redis: invalid map key %#v" , k )
3879
+ }
3880
+ resultMap [stringKey ] = v
3880
3881
}
3881
- value , err := rd .ReadString ()
3882
- if err != nil {
3883
- cmd .err = err
3882
+ case []interface {}: // resp2 will return array of arrays
3883
+ n := len (midResponse )
3884
+ for i := 0 ; i < n ; i ++ {
3885
+ finalArr , ok := midResponse [i ].([]interface {}) // final array that we need to transform to map
3886
+ if ! ok {
3887
+ return fmt .Errorf ("redis: unexpected response %#v" , data )
3888
+ }
3889
+ m := len (finalArr )
3890
+ if m % 2 != 0 { // since this should be map, keys should be even number
3891
+ return fmt .Errorf ("redis: unexpected response %#v" , data )
3892
+ }
3893
+
3894
+ for j := 0 ; j < m ; j += 2 {
3895
+ stringKey , ok := finalArr [j ].(string ) // the first one
3896
+ if ! ok {
3897
+ return fmt .Errorf ("redis: invalid map key %#v" , finalArr [i ])
3898
+ }
3899
+ resultMap [stringKey ] = finalArr [j + 1 ] // second one is value
3900
+ }
3884
3901
}
3885
- data [key ] = value
3902
+ default :
3903
+ return fmt .Errorf ("redis: unexpected response %#v" , data )
3886
3904
}
3887
3905
3888
- cmd .val = data
3906
+ cmd .val = resultMap
3889
3907
return nil
3890
3908
}
3891
3909
@@ -5114,6 +5132,7 @@ type ClientInfo struct {
5114
5132
OutputListLength int // oll, output list length (replies are queued in this list when the buffer is full)
5115
5133
OutputMemory int // omem, output buffer memory usage
5116
5134
TotalMemory int // tot-mem, total memory consumed by this client in its various buffers
5135
+ IoThread int // io-thread id
5117
5136
Events string // file descriptor events (see below)
5118
5137
LastCmd string // cmd, last command played
5119
5138
User string // the authenticated username of the client
@@ -5292,6 +5311,8 @@ func parseClientInfo(txt string) (info *ClientInfo, err error) {
5292
5311
info .LibName = val
5293
5312
case "lib-ver" :
5294
5313
info .LibVer = val
5314
+ case "io-thread" :
5315
+ info .IoThread , err = strconv .Atoi (val )
5295
5316
default :
5296
5317
return nil , fmt .Errorf ("redis: unexpected client info key(%s)" , key )
5297
5318
}
0 commit comments