mirror of
https://github.com/hanzokv/go.git
synced 2026-09-24 00:31:51 +00:00
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:
+25
-2
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user