redis/go-redis · error

redis: function stats unexpected running_script key %s

Error message

redis: function stats unexpected running_script key %s

What it means

This error is thrown while parsing the reply to FUNCTION STATS when the running_script map contains a key the client does not recognize. go-redis expects a fixed set of keys (e.g. name, duration_ms, command) inside the running_script object and fails fast on anything else to avoid silently dropping data. It usually indicates a Redis server version emitting a newer FUNCTION STATS format than the client supports.

Source

Thrown at command.go:7006

		return RunningScript{}, false, err
	}

	var runningScript RunningScript
	for i := 0; i < 3; i++ {
		key, err := rd.ReadString()
		if err != nil {
			return RunningScript{}, false, err
		}

		switch key {
		case "name":
			runningScript.Name, err = rd.ReadString()
		case "duration_ms":
			runningScript.Duration, err = cmd.readDuration(rd)
		case "command":
			runningScript.Command, err = cmd.readCommand(rd)
		default:
			return RunningScript{}, false, fmt.Errorf("redis: function stats unexpected running_script key %s", key)
		}

		if err != nil {
			return RunningScript{}, false, err
		}
	}

	return runningScript, true, nil
}

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++ {

View on GitHub (pinned to c5cad058c7)

Solutions

  1. Upgrade go-redis to the latest version so the FUNCTION STATS parser knows the new keys.
  2. Check the Redis server version and whether it is stock Redis (proxies/forks can alter the reply).
  3. If on the latest client and the key is genuinely new, file an issue at redis/go-redis with the raw reply.
  4. As a workaround, avoid calling FunctionStats() on the mismatched server version.

Example fix

// before: older client fails on new key
stats, err := rdb.FunctionStats(ctx)
// redis: function stats unexpected running_script key new_field

// after: upgrade module
// go get github.com/redis/go-redis/v9@latest
stats, err := rdb.FunctionStats(ctx)
Defensive patterns

Strategy: try-catch

Validate before calling

// check server/client compatibility before parsing
info, err := rdb.Info(ctx, "server").Result()
// verify redis_version is one your go-redis release supports

Try / catch

stats, err := rdb.FunctionStats(ctx)
if err != nil {
    if strings.Contains(err.Error(), "unexpected running_script key") {
        // fall back to raw FUNCTION STATS via redis.Do and parse manually
    }
    return err
}

Prevention

When it happens

Trigger: Calling FunctionStats() (or FCALL-based stats flows) against a Redis server whose FUNCTION STATS reply includes a new running_script field not in the parser's known-key switch at command.go:~7006.

Common situations: Upgrading the Redis server (e.g. Redis 8.x function engine changes) while using an older go-redis version; running against a proxy or fork that adds fields to the FUNCTION STATS reply.

Related errors


AI-assisted analysis of redis/go-redis@c5cad058c7 (2026-09-01). Data as JSON: /api/errors/045a606d2f95a582. Report an issue: GitHub.