fix(vector): VectorScoreSliceCmd to handle RESP2 flat array responses (#3767)

* Initial plan

* Fix VectorScoreSliceCmd to handle RESP2 flat array responses

Agent-Logs-Url: https://github.com/redis/go-redis/sessions/98c71a51-26cc-46ab-b9a0-25bd9c1f3295

Co-authored-by: ndyakov <[email protected]>

* Add NewVectorScoreSliceCmd constructor; fix test to use proper constructor

Agent-Logs-Url: https://github.com/redis/go-redis/sessions/98c71a51-26cc-46ab-b9a0-25bd9c1f3295

Co-authored-by: ndyakov <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: ndyakov <[email protected]>
This commit is contained in:
Copilot
2026-04-09 15:29:57 +03:00
committed by GitHub
co-authored by copilot-swe-agent[bot] <198982749+[email protected]> ndyakov
parent c4770cde7c
commit a6741de03e
2 changed files with 91 additions and 2 deletions
+25 -2
View File
@@ -7591,7 +7591,7 @@ type VectorScoreSliceCmd struct {
var _ Cmder = (*VectorScoreSliceCmd)(nil)
func NewVectorInfoSliceCmd(ctx context.Context, args ...any) *VectorScoreSliceCmd {
func NewVectorScoreSliceCmd(ctx context.Context, args ...any) *VectorScoreSliceCmd {
return &VectorScoreSliceCmd{
baseCmd: baseCmd{
ctx: ctx,
@@ -7600,6 +7600,11 @@ func NewVectorInfoSliceCmd(ctx context.Context, args ...any) *VectorScoreSliceCm
}
}
// NewVectorInfoSliceCmd is an alias for NewVectorScoreSliceCmd kept for backwards compatibility.
func NewVectorInfoSliceCmd(ctx context.Context, args ...any) *VectorScoreSliceCmd {
return NewVectorScoreSliceCmd(ctx, args...)
}
func (cmd *VectorScoreSliceCmd) SetVal(val []VectorScore) {
cmd.val = val
}
@@ -7617,11 +7622,29 @@ func (cmd *VectorScoreSliceCmd) String() string {
}
func (cmd *VectorScoreSliceCmd) readReply(rd *proto.Reader) error {
n, err := rd.ReadMapLen()
typ, err := rd.PeekReplyType()
if err != nil {
return err
}
var n int
if typ == proto.RespMap {
n, err = rd.ReadMapLen()
if err != nil {
return err
}
} else {
// RESP2 returns a flat array [name, score, name, score, ...]
n, err = rd.ReadArrayLen()
if err != nil {
return err
}
if n%2 != 0 {
return fmt.Errorf("redis: VectorScoreSliceCmd expects even number of elements, got %d", n)
}
n /= 2
}
cmd.val = make([]VectorScore, n)
for i := 0; i < n; i++ {
name, err := rd.ReadString()