Skip to content

feat: support vectorset #3375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5620,3 +5620,59 @@ func (cmd *MonitorCmd) Stop() {
defer cmd.mu.Unlock()
cmd.status = monitorStatusStop
}

type VectorScoreSliceCmd struct {
baseCmd

val []VectorScore
}

var _ Cmder = (*VectorScoreSliceCmd)(nil)

func NewVectorInfoSliceCmd(ctx context.Context, args ...any) *VectorScoreSliceCmd {
return &VectorScoreSliceCmd{
baseCmd: baseCmd{
ctx: ctx,
args: args,
},
}
}

func (cmd *VectorScoreSliceCmd) SetVal(val []VectorScore) {
cmd.val = val
}

func (cmd *VectorScoreSliceCmd) Val() []VectorScore {
return cmd.val
}

func (cmd *VectorScoreSliceCmd) Result() ([]VectorScore, error) {
return cmd.val, cmd.err
}

func (cmd *VectorScoreSliceCmd) String() string {
return cmdString(cmd, cmd.val)
}

func (cmd *VectorScoreSliceCmd) readReply(rd *proto.Reader) error {
n, err := rd.ReadMapLen()
if err != nil {
return err
}

cmd.val = make([]VectorScore, n)
for i := 0; i < n; i++ {
name, err := rd.ReadString()
if err != nil {
return err
}
cmd.val[i].Name = name

score, err := rd.ReadFloat()
if err != nil {
return err
}
cmd.val[i].Score = score
}
return nil
}
1 change: 1 addition & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ type Cmdable interface {
StreamCmdable
TimeseriesCmdable
JSONCmdable
VectorSetCmdable
}

type StatefulCmdable interface {
Expand Down
26 changes: 26 additions & 0 deletions unit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package redis

import (
"context"
)

// mockCmdable is a mock implementation of cmdable that records the last command.
// This is used for unit testing command construction without requiring a Redis server.
type mockCmdable struct {
lastCmd Cmder
returnErr error
}

func (m *mockCmdable) call(ctx context.Context, cmd Cmder) error {
m.lastCmd = cmd
if m.returnErr != nil {
cmd.SetErr(m.returnErr)
}
return m.returnErr
}

func (m *mockCmdable) asCmdable() cmdable {
return func(ctx context.Context, cmd Cmder) error {
return m.call(ctx, cmd)
}
}
Loading
Loading