@@ -3862,30 +3862,48 @@ func (cmd *MapMapStringInterfaceCmd) Val() map[string]interface{} {
38623862 return cmd .val
38633863}
38643864
3865+ // readReply will try to parse the reply from the proto.Reader for both resp2 and resp3
38653866func (cmd * MapMapStringInterfaceCmd ) readReply (rd * proto.Reader ) (err error ) {
3866- n , err := rd .ReadArrayLen ()
3867+ data , err := rd .ReadReply ()
38673868 if err != nil {
38683869 return err
38693870 }
3871+ resultMap := map [string ]interface {}{}
38703872
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
38803881 }
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+ }
38843901 }
3885- data [key ] = value
3902+ default :
3903+ return fmt .Errorf ("redis: unexpected response %#v" , data )
38863904 }
38873905
3888- cmd .val = data
3906+ cmd .val = resultMap
38893907 return nil
38903908}
38913909
@@ -5114,6 +5132,7 @@ type ClientInfo struct {
51145132 OutputListLength int // oll, output list length (replies are queued in this list when the buffer is full)
51155133 OutputMemory int // omem, output buffer memory usage
51165134 TotalMemory int // tot-mem, total memory consumed by this client in its various buffers
5135+ IoThread int // io-thread id
51175136 Events string // file descriptor events (see below)
51185137 LastCmd string // cmd, last command played
51195138 User string // the authenticated username of the client
@@ -5292,6 +5311,8 @@ func parseClientInfo(txt string) (info *ClientInfo, err error) {
52925311 info .LibName = val
52935312 case "lib-ver" :
52945313 info .LibVer = val
5314+ case "io-thread" :
5315+ info .IoThread , err = strconv .Atoi (val )
52955316 default :
52965317 return nil , fmt .Errorf ("redis: unexpected client info key(%s)" , key )
52975318 }
0 commit comments