go-redis/redis · error

redis: got %d elements in COMMAND reply, wanted 6/7/10

Error message

redis: got %d elements in COMMAND reply, wanted 6/7/10

What it means

Thrown by CommandsInfoCmd.readReply (command.go:5389). The COMMAND reply lists each command as an array; the parser only knows how to handle the three documented shapes: 6 fields (Redis 5), 7 fields (Redis 6, added 'since' was already present; really the keyset changed), and 10 fields (Redis 7/8, added acl-categories etc.). Any other count aborts to keep the RESP stream aligned.

Source

Thrown at command.go:5389

	const numArgRedis7 = 10 // Also matches redis 8

	n, err := rd.ReadArrayLen()
	if err != nil {
		return err
	}
	cmd.val = make(map[string]*CommandInfo, n)

	for i := 0; i < n; i++ {
		nn, err := rd.ReadArrayLen()
		if err != nil {
			return err
		}

		switch nn {
		case numArgRedis5, numArgRedis6, numArgRedis7:
			// ok
		default:
			return fmt.Errorf("redis: got %d elements in COMMAND reply, wanted 6/7/10", nn)
		}

		cmdInfo := &CommandInfo{}
		if cmdInfo.Name, err = rd.ReadString(); err != nil {
			return err
		}

		arity, err := rd.ReadInt()
		if err != nil {
			return err
		}
		cmdInfo.Arity = int8(arity)

		flagLen, err := rd.ReadArrayLen()
		if err != nil {
			return err
		}
		cmdInfo.Flags = make([]string, flagLen)

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Upgrade go-redis to a release that supports your Redis version's COMMAND reply shape.
  2. Pin/downgrade Redis to a version compatible with your go-redis release.
  3. Avoid calling Command() directly if you only need it for introspection; cache known command metadata instead.
  4. Confirm with redis-cli COMMAND that each entry has 6/7/10 fields.
Defensive patterns

Strategy: validation

Validate before calling

// Gate COMMAND introspection by server version if you depend on its shape.
v, err := serverVersion(ctx, client)
if err != nil { return err }
if !versionOK(v, "7.0") { /* only expect 6/7 fields */ }

Try / catch

cmds, err := client.Command(ctx).Result()
if err != nil {
    // fall back to cached/known command metadata instead of failing the app
    return knownCommands, err
}

Prevention

When it happens

Trigger: client.Command(ctx) (or the cluster router's COMMAND introspection) against a Redis whose COMMAND reply uses a different per-command array length — e.g. a much newer Redis that added fields the linked go-redis does not know, or a non-conformant fork.

Common situations: Running an older go-redis against a much newer Redis server that extended the COMMAND reply; using a Redis-compatible service whose COMMAND output diverges.

Related errors


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