{"record":{"id":"31763848b1152740","repo":"redis/go-redis","slug":"redis-got-d-elements-in-the-vsim-array-wanted-a","errorCode":null,"errorMessage":"redis: got %d elements in the VSIM array, wanted a multiple of 2","messagePattern":"redis: got (.+?) elements in the VSIM array, wanted a multiple of 2","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command.go","lineNumber":8825,"sourceCode":"\t\t\tname, err := rd.ReadString()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tattrib, err := readVectorAttribStringOrNil(rd)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tcmd.val[i] = VectorAttrib{Name: name, Attribs: attrib}\n\t\t}\n\t\treturn nil\n\t}\n\n\tn, err := rd.ReadArrayLen()\n\tif err != nil {\n\t\treturn err\n\t}\n\tif n%2 != 0 {\n\t\treturn fmt.Errorf(\"redis: got %d elements in the VSIM array, wanted a multiple of 2\", n)\n\t}\n\tcmd.val = make([]VectorAttrib, n/2)\n\tfor i := range cmd.val {\n\t\tname, err := rd.ReadString()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tattrib, err := readVectorAttribStringOrNil(rd)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tcmd.val[i] = VectorAttrib{Name: name, Attribs: attrib}\n\t}\n\treturn nil\n}\n\nfunc (cmd *VectorAttribSliceCmd) Clone() Cmder {\n\treturn &VectorAttribSliceCmd{","sourceCodeStart":8807,"sourceCodeEnd":8843,"githubUrl":"https://github.com/redis/go-redis/blob/c5cad058c72f58370553b48566302303cf8a2e89/command.go#L8807-L8843","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure you use the command variant whose option flags match the parser (WITHATTRIBS only, not mixed WITHSCORES).","Use RESP3 (Protocol: 3) for well-structured vector replies.","Upgrade go-redis and Redis to current matching versions.","Compare with redis-cli VSIM output to inspect the raw array."],"exampleFix":"// before: mixed flags yield odd field counts\nres, err := rdb.VSimWithAttrib(ctx, \"pts\", vector)\n\n// after: keep option flags consistent with the parser\n// and use RESP3\nrdb := redis.NewClient(&redis.Options{Protocol: 3})\nres, err := rdb.VSimWithAttrib(ctx, \"pts\", vector)","handlingStrategy":"try-catch","validationCode":"// ensure flags match the parser\n// VSIM key vector WITHATTRIBS -> use VSimWithAttrib, 2 fields per element","typeGuard":null,"tryCatchPattern":"cmd := rdb.VSimWithAttrib(ctx, \"pts\", vec)\nif err := cmd.Err(); err != nil {\n    if strings.Contains(err.Error(), \"VSIM array, wanted a multiple of 2\") {\n        // fall back to raw Do() or the score-only variant\n    }\n    return err\n}","preventionTips":["Use the command variant matching your option flags exactly","Prefer RESP3 for vector-set commands","Verify the reply via redis-cli when adding new options","Keep client/server versions aligned"],"tags":["redis","vectorset","vsim","reply-parsing"],"backgroundTag":"unexpected-reply-shape","analyzedSha":"c5cad058c72f58370553b48566302303cf8a2e89","analyzedAt":"2026-09-01T06:50:53.388Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}