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 nilView on GitHub (pinned to c5cad058c7)
Solutions
- Upgrade both go-redis and the Redis server to current versions so VLINKS shapes match.
- Run the same VLINKS command via redis-cli to inspect the raw nested arrays.
- Ensure no proxy/middleware rewrites RESP arrays between client and server.
- 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
- Keep server and client on compatible vector-set versions
- Bypass proxies that might rewrite nested arrays
- Use RESP3 for structured replies
- Verify against redis-cli before coding around the error
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
- redis: VectorScoreSliceCmd expects even number of elements,
- redis: can't parse reply=%T reading string
- redis: got %d elements in the VSIM array, wanted a multiple
- redis: got %d elements in the VSIM array, wanted a multiple
- redis: function stats unexpected running_script key %s
AI-assisted analysis of redis/go-redis@c5cad058c7 (2026-09-01).
Data as JSON: /api/errors/fb242ec27cdb3bfe.
Report an issue: GitHub.