redis/go-redis · error

redis: got elements in the VSIM array, wanted a multiple of…

Error message

redis: got %d elements in the VSIM array, wanted a multiple of 2

What it means

VSIM replies parsed into VectorAttrib values must be name/attribute pairs, so the top-level array length must be a multiple of 2. An odd count means the reply does not contain the expected pairs and parsing stops before allocating the result slice.

Solutions

  1. Ensure you use the command variant whose option flags match the parser (WITHATTRIBS only, not mixed WITHSCORES).
  2. Use RESP3 (Protocol: 3) for well-structured vector replies.
  3. Upgrade go-redis and Redis to current matching versions.
  4. Compare with redis-cli VSIM output to inspect the raw array.

Example fix

// before: mixed flags yield odd field counts
res, err := rdb.VSimWithAttrib(ctx, "pts", vector)

// after: keep option flags consistent with the parser
// and use RESP3
rdb := redis.NewClient(&redis.Options{Protocol: 3})
res, err := rdb.VSimWithAttrib(ctx, "pts", vector)
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure flags match the parser
// VSIM key vector WITHATTRIBS -> use VSimWithAttrib, 2 fields per element

Try / catch

cmd := rdb.VSimWithAttrib(ctx, "pts", vec)
if err := cmd.Err(); err != nil {
    if strings.Contains(err.Error(), "VSIM array, wanted a multiple of 2") {
        // fall back to raw Do() or the score-only variant
    }
    return err
}

Prevention

When it happens

Trigger: Calling VSIM with the WITHATTRIBS option (via the attrib-parsing command at command.go:~8825) and receiving an array whose length is not divisible by 2.

Common situations: Server/client version skew on VSIM reply format; requesting the wrong combination of WITHSCORES/WITHATTRIBS flags so fields per element mismatch; proxies rewriting the reply.

Related errors


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

Appendix: source

Thrown at command.go:8825

			name, err := rd.ReadString()
			if err != nil {
				return err
			}
			attrib, err := readVectorAttribStringOrNil(rd)
			if err != nil {
				return err
			}
			cmd.val[i] = VectorAttrib{Name: name, Attribs: attrib}
		}
		return nil
	}

	n, err := rd.ReadArrayLen()
	if err != nil {
		return err
	}
	if n%2 != 0 {
		return fmt.Errorf("redis: got %d elements in the VSIM array, wanted a multiple of 2", n)
	}
	cmd.val = make([]VectorAttrib, n/2)
	for i := range cmd.val {
		name, err := rd.ReadString()
		if err != nil {
			return err
		}
		attrib, err := readVectorAttribStringOrNil(rd)
		if err != nil {
			return err
		}
		cmd.val[i] = VectorAttrib{Name: name, Attribs: attrib}
	}
	return nil
}

func (cmd *VectorAttribSliceCmd) Clone() Cmder {
	return &VectorAttribSliceCmd{

View on GitHub (pinned to c5cad058c7)