go-redis/redis · error

redis: function stats unexpected running_script key %s

Error message

redis: function stats unexpected running_script key %s

What it means

Thrown by FunctionStatsCmd.readRunningScript (command.go:7000). The running_script map is expected to have exactly the keys name/duration_ms/command; any other key aborts. The map length is also fixed at 3 (ReadFixedMapLen(3)).

Source

Thrown at command.go:7000

		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 36d97525cd)

Solutions

  1. Upgrade go-redis to a release supporting the new running-script field.
  2. Pin Redis to a compatible version.
  3. Retry when no function is running (running_script becomes nil and this branch is skipped).
Defensive patterns

Strategy: validation

Validate before calling

// Confirm running_script keys via redis-cli while a function is executing.

Try / catch

stats, err := client.FunctionStats(ctx).Result()
if err != nil {
    // upgrade go-redis; retry when no function is running to skip this branch
    stats = redis.FunctionStats{}
}

Prevention

When it happens

Trigger: client.FunctionStats(ctx) when a function is running and the server's running_script map contains an unexpected key (or more than 3 entries) — typically a newer Redis adding running-script metadata that go-redis does not know.

Common situations: Forward-compat drift on newer Redis; Redis Enterprise/fork extending the running-script shape.

Related errors


AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06). Data as JSON: /data/errors/4e9df6ae173a4793.json. Report an issue: GitHub.