go-redis/redis · error

redis: got %d elements in the VLINKS array, wanted a multipl

Error message

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

What it means

Returned by VectorScoreSliceSliceCmd.readReply (command.go:8694) when parsing a RESP2 reply from VLinksWithScores (VLINKS key element WITHSCORES). Each level in the nested array should contain [element, score] pairs; an inner array with an odd element count breaks the pairing. Only occurs under RESP2; RESP3 returns per-level maps.

Source

Thrown at command.go:8694

				name, err := rd.ReadString()
				if err != nil {
					return err
				}
				score, err := rd.ReadFloat()
				if err != nil {
					return err
				}
				cmd.val[i][j] = VectorScore{Name: name, Score: score}
			}
		} else {
			// RESP2 format: each level is an array of [element, score, element, score, ...] pairs
			innerLen, err := rd.ReadArrayLen()
			if err != nil {
				return err
			}

			if innerLen%2 != 0 {
				return fmt.Errorf("redis: got %d elements in the VLINKS array, wanted a multiple of 2", innerLen)
			}

			cmd.val[i] = make([]VectorScore, innerLen/2)
			for j := 0; j < innerLen; j += 2 {
				name, err := rd.ReadString()
				if err != nil {
					return err
				}
				score, err := rd.ReadFloat()
				if err != nil {
					return err
				}
				cmd.val[i][j/2] = VectorScore{Name: name, Score: score}
			}
		}
	}

	return nil

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Set Protocol: 3 in redis.Options so VLINKS returns map-structured levels per node
  2. Upgrade Redis and the VectorSet module to a version compatible with this go-redis
  3. Confirm the server supports VLINKS WITHSCORES

Example fix

// before
rdb := redis.NewClient(&redis.Options{Addr: ":6379"})
res, err := rdb.VLinksWithScores(ctx, "mykey", "elem").Result()

// after
rdb := redis.NewClient(&redis.Options{
    Addr:     ":6379",
    Protocol: 3,
})
Defensive patterns

Strategy: validation

Validate before calling

// RESP3 avoids flat-array pair parsing for VLINKS WITHSCORES
opts := &redis.Options{Addr: ":6379", Protocol: 3}

Try / catch

res, err := rdb.VLinksWithScores(ctx, key, elem).Result()
if err != nil && strings.Contains(err.Error(), "wanted a multiple of 2") {
    log.Error("VLINKS RESP2 format mismatch; use Protocol:3")
}

Prevention

When it happens

Trigger: Calling VLinksWithScores while using RESP2 (default) where a VLINKS inner array (one per graph level) has an odd number of elements.

Common situations: Incompatible VectorSet module version on the server; RESP2 protocol with a server that formats VLINKS inner arrays differently; proxy corrupting the nested array structure.

Related errors


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