{"record":{"id":"bf4e6829d20ac533","repo":"redis/go-redis","slug":"redis-unexpected-response-v","errorCode":null,"errorMessage":"redis: unexpected response %#v","messagePattern":"redis: unexpected response %#v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command.go","lineNumber":6374,"sourceCode":"\t\treturn err\n\t}\n\tresultMap := map[string]interface{}{}\n\n\tswitch midResponse := data.(type) {\n\tcase map[interface{}]interface{}: // resp3 will return map\n\t\tfor k, v := range midResponse {\n\t\t\tstringKey, ok := k.(string)\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"redis: invalid map key %#v\", k)\n\t\t\t}\n\t\t\tresultMap[stringKey] = v\n\t\t}\n\tcase []interface{}: // resp2 will return array of arrays\n\t\tn := len(midResponse)\n\t\tfor i := 0; i < n; i++ {\n\t\t\tfinalArr, ok := midResponse[i].([]interface{}) // final array that we need to transform to map\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"redis: unexpected response %#v\", data)\n\t\t\t}\n\t\t\tm := len(finalArr)\n\t\t\tif m%2 != 0 { // since this should be map, keys should be even number\n\t\t\t\treturn fmt.Errorf(\"redis: unexpected response %#v\", data)\n\t\t\t}\n\n\t\t\tfor j := 0; j < m; j += 2 {\n\t\t\t\tstringKey, ok := finalArr[j].(string) // the first one\n\t\t\t\tif !ok {\n\t\t\t\t\treturn fmt.Errorf(\"redis: invalid map key %#v\", finalArr[i])\n\t\t\t\t}\n\t\t\t\tresultMap[stringKey] = finalArr[j+1] // second one is value\n\t\t\t}\n\t\t}\n\tdefault:\n\t\treturn fmt.Errorf(\"redis: unexpected response %#v\", data)\n\t}\n","sourceCodeStart":6356,"sourceCodeEnd":6392,"githubUrl":"https://github.com/redis/go-redis/blob/c5cad058c72f58370553b48566302303cf8a2e89/command.go#L6356-L6392","documentation":"In the same reply transformer as error 61, the RESP2 branch expects the reply to be a []interface{} of []interface{} pairs (array of [key, value] arrays). If an element is not a []interface{}, it cannot be turned into a map, so the parser returns `redis: unexpected response` with the whole reply printed via %#v.","triggerScenarios":"Calling a command routed through this map transformer under RESP2 when the server/proxy returns a flat array, a scalar, or nested structures instead of an array of 2-element arrays — typically with FUNCTION LIST-like replies from a non-Redis server or a version whose shape changed.","commonSituations":"Redis-compatible servers (Dragonfly, KeyDB) or proxies reshaping replies; server version newer than the client expects; RESP2 vs RESP3 mismatches (Protocol: 2 vs 3) selecting the other code path.","solutions":["Read the %#v dump in the error — it shows the exact reply shape the server sent; compare with what your Redis version should return.","Try `Protocol: 3` (RESP3) so the map-native branch of the transformer is used instead of the array-of-arrays path.","Upgrade go-redis and/or the server so both agree on the reply format.","If a proxy is in the path, inspect and fix its reply translation, or bypass it for this command."],"exampleFix":"// before: RESP2 reply flattened by a proxy\ncfg := &redis.Options{Addr: addr, Protocol: 2}\n\n// after: use RESP3 so maps arrive as maps\ncfg := &redis.Options{Addr: addr, Protocol: 3}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isArrayOfPairArrays(v interface{}) bool {\n    arr, ok := v.([]interface{})\n    if !ok {\n        return false\n    }\n    for _, e := range arr {\n        if _, ok := e.([]interface{}); !ok {\n            return false\n        }\n    }\n    return true\n}","tryCatchPattern":"res, err := cmd.Result()\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected response\") {\n        // log raw reply shape captured via ProcessHook, then fall back\n        log.Printf(\"unexpected reply shape: %v\", err)\n        return nil, errReplyShape\n    }\n    return err\n}","preventionTips":["Set `Protocol: 3` to use RESP3 maps and avoid the RESP2 array-of-arrays path.","Test against the exact server/proxy stack used in production.","Bypass reply-rewriting proxies for map-shaped commands.","Upgrade go-redis when you upgrade the Redis server."],"tags":["redis","protocol-parse","resp2","reply-transform"],"backgroundTag":"unexpected-reply-shape","analyzedSha":"c5cad058c72f58370553b48566302303cf8a2e89","analyzedAt":"2026-09-01T06:50:53.388Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}