redis/go-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

VLINKS returns, for each element, a nested array of neighbor name/score pairs. Each inner array must have an even length; an odd innerLen means the server's nested reply is malformed relative to what the client expects, so parsing aborts.

Source

Thrown at command.go:8705

				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 c5cad058c7)

Solutions

  1. Upgrade both go-redis and the Redis server to current versions so VLINKS shapes match.
  2. Run the same VLINKS command via redis-cli to inspect the raw nested arrays.
  3. Ensure no proxy/middleware rewrites RESP arrays between client and server.
  4. If reproducible on latest versions, file an issue with the raw reply.

Example fix

// before: VLINKS inner array with 3 elements
links, err := rdb.VLinks(ctx, "pts", "elem", 3)
// redis: got 3 elements in the VLINKS array, wanted a multiple of 2

// after: verify server/client versions are in sync
// go get github.com/redis/go-redis/v9@latest
links, err := rdb.VLinks(ctx, "pts", "elem", 3)
Defensive patterns

Strategy: try-catch

Validate before calling

raw, _ := rdb.Do(ctx, "VLINKS", "pts", "elem", 3).Result()
_ = raw // confirm each nested array has even length

Try / catch

cmd := rdb.VLinks(ctx, "pts", "elem", 3)
if err := cmd.Err(); err != nil {
    if strings.Contains(err.Error(), "VLINKS array") {
        // fall back to raw Do() parsing
    }
    return err
}

Prevention

When it happens

Trigger: Calling VLinks() on a vector set when one of the nested neighbor arrays has an odd number of elements at command.go:~8705.

Common situations: Server/client version skew on the VLINKS reply format; a server bug or proxy rewriting the nested arrays; testing against pre-GA vector-set builds.

Related errors


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