mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
feat(tests): validate that ConfigSet and ConfigGet work with Modules (#3258)
* Add tests for unified config in Redis 8 * WIP: fix reading FT.CONFIG with RESP3 * add more tests * use search-timeout * move deprecated warnings on the bottom
This commit is contained in:
48
command.go
48
command.go
@ -3862,30 +3862,48 @@ func (cmd *MapMapStringInterfaceCmd) Val() map[string]interface{} {
|
||||
return cmd.val
|
||||
}
|
||||
|
||||
// readReply will try to parse the reply from the proto.Reader for both resp2 and resp3
|
||||
func (cmd *MapMapStringInterfaceCmd) readReply(rd *proto.Reader) (err error) {
|
||||
n, err := rd.ReadArrayLen()
|
||||
data, err := rd.ReadReply()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resultMap := map[string]interface{}{}
|
||||
|
||||
data := make(map[string]interface{}, n/2)
|
||||
for i := 0; i < n; i += 2 {
|
||||
_, err := rd.ReadArrayLen()
|
||||
if err != nil {
|
||||
cmd.err = err
|
||||
switch midResponse := data.(type) {
|
||||
case map[interface{}]interface{}: // resp3 will return map
|
||||
for k, v := range midResponse {
|
||||
stringKey, ok := k.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("redis: invalid map key %#v", k)
|
||||
}
|
||||
resultMap[stringKey] = v
|
||||
}
|
||||
key, err := rd.ReadString()
|
||||
if err != nil {
|
||||
cmd.err = err
|
||||
case []interface{}: // resp2 will return array of arrays
|
||||
n := len(midResponse)
|
||||
for i := 0; i < n; i++ {
|
||||
finalArr, ok := midResponse[i].([]interface{}) // final array that we need to transform to map
|
||||
if !ok {
|
||||
return fmt.Errorf("redis: unexpected response %#v", data)
|
||||
}
|
||||
m := len(finalArr)
|
||||
if m%2 != 0 { // since this should be map, keys should be even number
|
||||
return fmt.Errorf("redis: unexpected response %#v", data)
|
||||
}
|
||||
|
||||
for j := 0; j < m; j += 2 {
|
||||
stringKey, ok := finalArr[j].(string) // the first one
|
||||
if !ok {
|
||||
return fmt.Errorf("redis: invalid map key %#v", finalArr[i])
|
||||
}
|
||||
resultMap[stringKey] = finalArr[j+1] // second one is value
|
||||
}
|
||||
}
|
||||
value, err := rd.ReadString()
|
||||
if err != nil {
|
||||
cmd.err = err
|
||||
}
|
||||
data[key] = value
|
||||
default:
|
||||
return fmt.Errorf("redis: unexpected response %#v", data)
|
||||
}
|
||||
|
||||
cmd.val = data
|
||||
cmd.val = resultMap
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user