go-redis/redis · error
redis: function stats unexpected key %s
Error message
redis: function stats unexpected key %s
What it means
Thrown by FunctionStatsCmd.readReply (command.go:6964) while parsing FUNCTION STATS. The top-level map accepts running_script/engines/all_running_scripts (Redis Enterprise); any other top-level key aborts parsing.
Source
Thrown at command.go:6964
}
var key string
var result FunctionStats
for f := 0; f < n; f++ {
key, err = rd.ReadString()
if err != nil {
return err
}
switch key {
case "running_script":
result.rs, result.isRunning, err = cmd.readRunningScript(rd)
case "engines":
result.Engines, err = cmd.readEngines(rd)
case "all_running_scripts": // Redis Enterprise only
result.allrs, result.isRunning, err = cmd.readRunningScripts(rd)
default:
return fmt.Errorf("redis: function stats unexpected key %s", key)
}
if err != nil {
return err
}
}
cmd.val = result
return nil
}
func (cmd *FunctionStatsCmd) readRunningScript(rd *proto.Reader) (RunningScript, bool, error) {
err := rd.ReadFixedMapLen(3)
if err != nil {
if err == Nil {
return RunningScript{}, false, nil
}
return RunningScript{}, false, errView on GitHub (pinned to 36d97525cd)
Solutions
- Upgrade go-redis to a release that recognizes the new key.
- Pin Redis to a version compatible with your go-redis.
- Confirm the unknown key with redis-cli (`FUNCTION STATS`) and report/upgrade.
Defensive patterns
Strategy: validation
Validate before calling
// redis-cli FUNCTION STATS -> confirm top-level keys are running_script/engines[/all_running_scripts].
Try / catch
stats, err := client.FunctionStats(ctx).Result()
if err != nil {
// forward-compat drift; upgrade go-redis; degrade to empty stats
stats = redis.FunctionStats{}
} Prevention
- Keep go-redis and Redis versions compatible.
- Treat FunctionStats as observability metadata.
When it happens
Trigger: client.FunctionStats(ctx) against a Redis that returns a new top-level FUNCTION STATS field the linked go-redis does not recognize (forward-compat drift), or a non-conformant fork.
Common situations: Newer Redis version extending FUNCTION STATS; Redis Enterprise with extra fields beyond all_running_scripts; older go-redis against a newer server.
Related errors
- redis: function stats unexpected running_script key %s
- redis: function stats unexpected %s engine map length
- redis: function list unexpected key %s
- redis: got %d elements in COMMAND reply, wanted 6/7/10
- redis: unexpected key %q in CLUSTER LINKS reply
AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06).
Data as JSON: /data/errors/bca4a7ed4d5f6956.json.
Report an issue: GitHub.