Skip to content
Open
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
11 changes: 11 additions & 0 deletions vectorset_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type VectorSetCmdable interface {
VSimWithScores(ctx context.Context, key string, val Vector) *VectorScoreSliceCmd
VSimWithArgs(ctx context.Context, key string, val Vector, args *VSimArgs) *StringSliceCmd
VSimWithArgsWithScores(ctx context.Context, key string, val Vector, args *VSimArgs) *VectorScoreSliceCmd
VRange(ctx context.Context, key, start, end string, count int64) *StringSliceCmd
}

type Vector interface {
Expand Down Expand Up @@ -345,3 +346,13 @@ func (c cmdable) VSimWithArgsWithScores(ctx context.Context, key string, val Vec
_ = c(ctx, cmd)
return cmd
}

// `VRANGE key start end count`
// a negative count means to return all the elements in the vector set.
// note: the API is experimental and may be subject to change.
func (c cmdable) VRange(ctx context.Context, key, start, end string, count int64) *StringSliceCmd {
args := []any{"vrange", key, start, end, count}
cmd := NewStringSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
16 changes: 16 additions & 0 deletions vectorset_commands_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,22 @@ var _ = Describe("Redis VectorSet commands", Label("vectorset"), func() {
expectNil(err)
expectEqual(len(res), len(vals))

res, err = client.VRange(ctx, vecName, "[k1", "[k2", -1).Result()
expectNil(err)
expectEqual(len(res), 2)

res, err = client.VRange(ctx, vecName, "-", "[k2", -1).Result()
expectNil(err)
expectEqual(len(res), 3)

res, err = client.VRange(ctx, vecName, "(k1", "+", -1).Result()
expectNil(err)
expectEqual(len(res), 3)

res, err = client.VRange(ctx, vecName, "[k1", "+", 2).Result()
expectNil(err)
expectEqual(len(res), 2)

// test equality
sim, err := client.VSimWithArgs(ctx, vecName, &vals[0].v, &redis.VSimArgs{
Filter: `.age == 25`,
Expand Down
Loading