redis/go-redis · error
redis: function stats unexpected %s engine map length
Error message
redis: function stats unexpected %s engine map length
What it means
While parsing FUNCTION STATS, each engine entry is expected to be a map of exactly 2 fields. If the engine map length is not 2, the client rejects the reply with this error. It guards against protocol changes in the FUNCTION STATS reply shape (e.g. new fields per engine) that the parser does not handle.
Source
Thrown at command.go:7033
}
func (cmd *FunctionStatsCmd) readEngines(rd *proto.Reader) ([]Engine, error) {
n, err := rd.ReadMapLen()
if err != nil {
return nil, err
}
engines := make([]Engine, 0, n)
for i := 0; i < n; i++ {
engine := Engine{}
engine.Language, err = rd.ReadString()
if err != nil {
return nil, err
}
err = rd.ReadFixedMapLen(2)
if err != nil {
return nil, fmt.Errorf("redis: function stats unexpected %s engine map length", engine.Language)
}
for i := 0; i < 2; i++ {
key, err := rd.ReadString()
if err != nil {
return nil, err
}
switch key {
case "libraries_count":
engine.LibrariesCount, err = rd.ReadInt()
case "functions_count":
engine.FunctionsCount, err = rd.ReadInt()
default:
// Unknown field: drain its value so the reader stays aligned
// with the rest of the reply.
err = rd.DiscardNext()
}
if err != nil {View on GitHub (pinned to c5cad058c7)
Solutions
- Upgrade go-redis to the latest release; newer parsers accept the extended engine map.
- Verify REDIS_VERSION matches what your client supports (pin the server or the client accordingly).
- If using a proxy that modifies FUNCTION STATS output, configure it to pass the reply through unchanged.
- Report the discrepancy to redis/go-redis with the server version and reply if it persists.
Example fix
// before: Redis 8.x engine map with 3 fields vs old client stats, err := rdb.FunctionStats(ctx) // redis: function stats unexpected lua engine map length // after: upgrade go-redis // go get github.com/redis/go-redis/v9@latest stats, err := rdb.FunctionStats(ctx)
Defensive patterns
Strategy: try-catch
Validate before calling
// confirm reply shape first
out, _ := rdb.Do(ctx, "FUNCTION", "STATS").Result()
fmt.Printf("%#v\n", out) // inspect engine map arity Try / catch
stats, err := rdb.FunctionStats(ctx)
if err != nil {
if strings.Contains(err.Error(), "engine map length") {
// use rdb.Do(ctx, "FUNCTION", "STATS") raw reply instead
}
return err
} Prevention
- Upgrade go-redis before upgrading the Redis server
- Avoid proxies that reshape module replies
- Test FUNCTION STATS against your exact REDIS_VERSION in CI
- Keep RESP3 enabled for richer reply structure
When it happens
Trigger: Calling FunctionStats() when the server returns an engine object with more or fewer than 2 key/value pairs, at the ReadFixedMapLen(2) call in command.go:~7033.
Common situations: Redis server upgrade that added fields per engine in FUNCTION STATS; testing against Redis Edge/unstable builds; a RESP proxy that reshapes the reply.
Related errors
- redis: function stats unexpected running_script key %s
- redis: function stats unexpected key %s
- redis: unexpected key %q in CLUSTER LINKS reply
- redis: VectorScoreSliceCmd expects even number of elements,
- redis: got %d elements in the VLINKS array, wanted a multipl
AI-assisted analysis of redis/go-redis@c5cad058c7 (2026-09-01).
Data as JSON: /api/errors/1a8904c6019799bf.
Report an issue: GitHub.