{"id":"cd9bb8849f70c910","repo":"go-redis/redis","slug":"redis-got-d-elements-in-the-vlinks-array-wanted","errorCode":null,"errorMessage":"redis: got %d elements in the VLINKS array, wanted a multiple of 2","messagePattern":"redis: got (.+?) elements in the VLINKS array, wanted a multiple of 2","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command.go","lineNumber":8694,"sourceCode":"\t\t\t\tname, err := rd.ReadString()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tscore, err := rd.ReadFloat()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tcmd.val[i][j] = VectorScore{Name: name, Score: score}\n\t\t\t}\n\t\t} else {\n\t\t\t// RESP2 format: each level is an array of [element, score, element, score, ...] pairs\n\t\t\tinnerLen, err := rd.ReadArrayLen()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tif innerLen%2 != 0 {\n\t\t\t\treturn fmt.Errorf(\"redis: got %d elements in the VLINKS array, wanted a multiple of 2\", innerLen)\n\t\t\t}\n\n\t\t\tcmd.val[i] = make([]VectorScore, innerLen/2)\n\t\t\tfor j := 0; j < innerLen; j += 2 {\n\t\t\t\tname, err := rd.ReadString()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tscore, err := rd.ReadFloat()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tcmd.val[i][j/2] = VectorScore{Name: name, Score: score}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil","sourceCodeStart":8676,"sourceCodeEnd":8712,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/command.go#L8676-L8712","documentation":"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.","triggerScenarios":"Calling VLinksWithScores while using RESP2 (default) where a VLINKS inner array (one per graph level) has an odd number of elements.","commonSituations":"Incompatible VectorSet module version on the server; RESP2 protocol with a server that formats VLINKS inner arrays differently; proxy corrupting the nested array structure.","solutions":["Set Protocol: 3 in redis.Options so VLINKS returns map-structured levels per node","Upgrade Redis and the VectorSet module to a version compatible with this go-redis","Confirm the server supports VLINKS WITHSCORES"],"exampleFix":"// before\nrdb := redis.NewClient(&redis.Options{Addr: \":6379\"})\nres, err := rdb.VLinksWithScores(ctx, \"mykey\", \"elem\").Result()\n\n// after\nrdb := redis.NewClient(&redis.Options{\n    Addr:     \":6379\",\n    Protocol: 3,\n})","handlingStrategy":"validation","validationCode":"// RESP3 avoids flat-array pair parsing for VLINKS WITHSCORES\nopts := &redis.Options{Addr: \":6379\", Protocol: 3}","typeGuard":null,"tryCatchPattern":"res, err := rdb.VLinksWithScores(ctx, key, elem).Result()\nif err != nil && strings.Contains(err.Error(), \"wanted a multiple of 2\") {\n    log.Error(\"VLINKS RESP2 format mismatch; use Protocol:3\")\n}","preventionTips":["Use RESP3 for VLINKS WITHSCORES commands","Match the server VectorSet module version with the go-redis version"],"tags":["vectorset","vlinks","resp2","parsing","protocol"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}