Skip to content

Commit 4e22885

Browse files
fukua95ndyakov
andauthored
feat: support vectorset (#3375)
* feat: support vectorset * fix: char encoding error * use `any` instread of `interface{}` * update vectorset API Signed-off-by: fukua95 <fukua95@gmail.com> * refact: MapStringFloat64Cmd -> VectorInfoSliceCmd Signed-off-by: fukua95 <fukua95@gmail.com> * update: * the type of vector attribute: string -> VectorAttributeMarshaller * Add a new API VRemAttr * mark the APIs are experimental Signed-off-by: fukua95 <fukua95@gmail.com> * trigger CI again Signed-off-by: fukua95 <fukua95@gmail.com> * rename a API: VRemAttr -> VClearAttributes Signed-off-by: fukua95 <fukua95@gmail.com> * add test Signed-off-by: fukua95 <fukua95@gmail.com> * feat(vectorset): improve VSetAttr API and add comprehensive test suite - Simplify VSetAttr to accept interface{} with automatic JSON marshalling - Remove VectorAttributeMarshaller interface for simpler API - Add comprehensive unit tests for all vectorset commands --------- Signed-off-by: fukua95 <fukua95@gmail.com> Co-authored-by: Nedyalko Dyakov <nedyalko.dyakov@gmail.com>
1 parent c609828 commit 4e22885

File tree

6 files changed

+1299
-0
lines changed

6 files changed

+1299
-0
lines changed

command.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5620,3 +5620,59 @@ func (cmd *MonitorCmd) Stop() {
56205620
defer cmd.mu.Unlock()
56215621
cmd.status = monitorStatusStop
56225622
}
5623+
5624+
type VectorScoreSliceCmd struct {
5625+
baseCmd
5626+
5627+
val []VectorScore
5628+
}
5629+
5630+
var _ Cmder = (*VectorScoreSliceCmd)(nil)
5631+
5632+
func NewVectorInfoSliceCmd(ctx context.Context, args ...any) *VectorScoreSliceCmd {
5633+
return &VectorScoreSliceCmd{
5634+
baseCmd: baseCmd{
5635+
ctx: ctx,
5636+
args: args,
5637+
},
5638+
}
5639+
}
5640+
5641+
func (cmd *VectorScoreSliceCmd) SetVal(val []VectorScore) {
5642+
cmd.val = val
5643+
}
5644+
5645+
func (cmd *VectorScoreSliceCmd) Val() []VectorScore {
5646+
return cmd.val
5647+
}
5648+
5649+
func (cmd *VectorScoreSliceCmd) Result() ([]VectorScore, error) {
5650+
return cmd.val, cmd.err
5651+
}
5652+
5653+
func (cmd *VectorScoreSliceCmd) String() string {
5654+
return cmdString(cmd, cmd.val)
5655+
}
5656+
5657+
func (cmd *VectorScoreSliceCmd) readReply(rd *proto.Reader) error {
5658+
n, err := rd.ReadMapLen()
5659+
if err != nil {
5660+
return err
5661+
}
5662+
5663+
cmd.val = make([]VectorScore, n)
5664+
for i := 0; i < n; i++ {
5665+
name, err := rd.ReadString()
5666+
if err != nil {
5667+
return err
5668+
}
5669+
cmd.val[i].Name = name
5670+
5671+
score, err := rd.ReadFloat()
5672+
if err != nil {
5673+
return err
5674+
}
5675+
cmd.val[i].Score = score
5676+
}
5677+
return nil
5678+
}

commands.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ type Cmdable interface {
234234
StreamCmdable
235235
TimeseriesCmdable
236236
JSONCmdable
237+
VectorSetCmdable
237238
}
238239

239240
type StatefulCmdable interface {

unit_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package redis
2+
3+
import (
4+
"context"
5+
)
6+
7+
// mockCmdable is a mock implementation of cmdable that records the last command.
8+
// This is used for unit testing command construction without requiring a Redis server.
9+
type mockCmdable struct {
10+
lastCmd Cmder
11+
returnErr error
12+
}
13+
14+
func (m *mockCmdable) call(ctx context.Context, cmd Cmder) error {
15+
m.lastCmd = cmd
16+
if m.returnErr != nil {
17+
cmd.SetErr(m.returnErr)
18+
}
19+
return m.returnErr
20+
}
21+
22+
func (m *mockCmdable) asCmdable() cmdable {
23+
return func(ctx context.Context, cmd Cmder) error {
24+
return m.call(ctx, cmd)
25+
}
26+
}

0 commit comments

Comments
 (0)