{"record":{"id":"1aa070d70d035bee","repo":"redis/go-redis","slug":"redis-function-stats-unexpected-key-s","errorCode":null,"errorMessage":"redis: function stats unexpected key %s","messagePattern":"redis: function stats unexpected key (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command.go","lineNumber":6970,"sourceCode":"\t}\n\n\tvar key string\n\tvar result FunctionStats\n\tfor f := 0; f < n; f++ {\n\t\tkey, err = rd.ReadString()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tswitch key {\n\t\tcase \"running_script\":\n\t\t\tresult.rs, result.isRunning, err = cmd.readRunningScript(rd)\n\t\tcase \"engines\":\n\t\t\tresult.Engines, err = cmd.readEngines(rd)\n\t\tcase \"all_running_scripts\": // Redis Enterprise only\n\t\t\tresult.allrs, result.isRunning, err = cmd.readRunningScripts(rd)\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"redis: function stats unexpected key %s\", key)\n\t\t}\n\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tcmd.val = result\n\treturn nil\n}\n\nfunc (cmd *FunctionStatsCmd) readRunningScript(rd *proto.Reader) (RunningScript, bool, error) {\n\terr := rd.ReadFixedMapLen(3)\n\tif err != nil {\n\t\tif err == Nil {\n\t\t\treturn RunningScript{}, false, nil\n\t\t}\n\t\treturn RunningScript{}, false, err","sourceCodeStart":6952,"sourceCodeEnd":6988,"githubUrl":"https://github.com/redis/go-redis/blob/c5cad058c72f58370553b48566302303cf8a2e89/command.go#L6952-L6988","documentation":"Thrown by the FUNCTION STATS reply parser when the stats map contains a key other than `running_script`, `engines`, or `all_running_scripts` (command.go, FunctionStats readReply). An unrecognized top-level key — from a newer server or Redis Enterprise — fails the parse rather than being silently dropped.","triggerScenarios":"Calling `client.FunctionStats(ctx)` against a server whose FUNCTION STATS reply includes extra top-level fields (e.g. Redis Enterprise forks, newer Redis versions adding stats metadata) that this go-redis version doesn't know.","commonSituations":"Server/client version drift; Redis Enterprise with extra stats fields; preview Redis builds with evolving FUNCTION STATS format.","solutions":["Upgrade go-redis to the latest v9 release so FUNCTION STATS parsing recognizes all keys your server emits.","Compare the reported key with `redis-cli --raw FUNCTION STATS` output to identify the new field.","Avoid or downgrade FUNCTION STATS on the offending server version until the client is updated.","File a go-redis issue with the raw reply if the key is from a supported Redis version."],"exampleFix":"// before: server emits new FUNCTION STATS key, client unaware\nstats, err := client.FunctionStats(ctx) // err: function stats unexpected key foo\n\n// after: upgrade client to parse the extended reply\ngo get github.com/redis/go-redis/v9@latest","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"stats, err := rdb.FunctionStats(ctx)\nif err != nil {\n    if strings.Contains(err.Error(), \"function stats unexpected key\") {\n        // newer/extended server reply: skip stats or upgrade client\n        log.Printf(\"FUNCTION STATS format unsupported: %v\", err)\n        return nil, errStatsFormat\n    }\n    return err\n}","preventionTips":["Upgrade go-redis before or together with Redis server upgrades.","Gate FUNCTION STATS calls behind a server-version check (Redis 7.0+).","Verify raw output with `redis-cli FUNCTION STATS` when the error mentions a new key.","Add FUNCTION STATS to CI integration tests to catch format drift early."],"tags":["redis","function-stats","protocol-parse","version-drift"],"backgroundTag":"unexpected-reply-shape","analyzedSha":"c5cad058c72f58370553b48566302303cf8a2e89","analyzedAt":"2026-09-01T06:50:53.388Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}