go-redis/redis · error

redis: function list unexpected key %s

Error message

redis: function list unexpected key %s

What it means

Thrown by FunctionListCmd.readReply (command.go:6766) while parsing each library map from FUNCTION LIST. The parser only knows the keys library_name/engine/functions/library_code; any other key at the library level aborts parsing to avoid misaligning the map.

Source

Thrown at command.go:6766

		library := Library{}
		for f := 0; f < nn; f++ {
			key, err := rd.ReadString()
			if err != nil {
				return err
			}

			switch key {
			case "library_name":
				library.Name, err = rd.ReadString()
			case "engine":
				library.Engine, err = rd.ReadString()
			case "functions":
				library.Functions, err = cmd.readFunctions(rd)
			case "library_code":
				library.Code, err = rd.ReadString()
			default:
				return fmt.Errorf("redis: function list unexpected key %s", key)
			}

			if err != nil {
				return err
			}
		}

		libraries[i] = library
	}
	cmd.val = libraries
	return nil
}

func (cmd *FunctionListCmd) readFunctions(rd *proto.Reader) ([]Function, error) {
	n, err := rd.ReadArrayLen()
	if err != nil {
		return nil, err
	}

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Upgrade go-redis to a release that recognizes the new key.
  2. Pin Redis to a version whose FUNCTION LIST output your go-redis understands.
  3. Confirm the offending key with redis-cli (`FUNCTION LIST`).
  4. Avoid FunctionList if you only need a subset (use FunctionList with WITHCODE false and tolerate the failure by upgrading).
Defensive patterns

Strategy: validation

Validate before calling

// If you depend on FunctionList, gate by server version vs your go-redis.
// redis-cli FUNCTION LIST  -> confirm only known library-level keys are present.

Try / catch

libs, err := client.FunctionList(ctx, redis.FunctionListQuery{}).Result()
if err != nil {
    // forward-compat drift; upgrade go-redis, or degrade to no-op
    libs = nil
}

Prevention

When it happens

Trigger: client.FunctionList(ctx, q) against a Redis that added a new top-level library field the linked go-redis does not recognize (forward-compat drift), or a non-conformant fork.

Common situations: Running an older go-redis against a newer Redis that extended FUNCTION LIST's library map (e.g. added a field like 'description' or 'library_sha'); Redis fork with a different shape.

Related errors


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