mirror of
https://github.com/redis/go-redis.git
synced 2025-07-16 13:21:51 +03:00
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>
This commit is contained in:
56
command.go
56
command.go
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user