Skip to content

Commit 5d13acf

Browse files
committed
add vrange command
Signed-off-by: Xiaolong Chen <[email protected]>
1 parent 3ad9f9c commit 5d13acf

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

vectorset_commands.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type VectorSetCmdable interface {
2626
VSimWithScores(ctx context.Context, key string, val Vector) *VectorScoreSliceCmd
2727
VSimWithArgs(ctx context.Context, key string, val Vector, args *VSimArgs) *StringSliceCmd
2828
VSimWithArgsWithScores(ctx context.Context, key string, val Vector, args *VSimArgs) *VectorScoreSliceCmd
29+
VRange(ctx context.Context, key, start, end string, count int64) *StringSliceCmd
2930
}
3031

3132
type Vector interface {
@@ -345,3 +346,15 @@ func (c cmdable) VSimWithArgsWithScores(ctx context.Context, key string, val Vec
345346
_ = c(ctx, cmd)
346347
return cmd
347348
}
349+
350+
// `VRANGE key start end count`
351+
// note: the API is experimental and may be subject to change.
352+
func (c cmdable) VRange(ctx context.Context, key, start, end string, count int64) *StringSliceCmd {
353+
args := []any{"vrange", key, start, end}
354+
if count != 0 {
355+
args = append(args, count)
356+
}
357+
cmd := NewStringSliceCmd(ctx, args...)
358+
_ = c(ctx, cmd)
359+
return cmd
360+
}

vectorset_commands_integration_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,22 @@ var _ = Describe("Redis VectorSet commands", Label("vectorset"), func() {
260260
expectNil(err)
261261
expectEqual(len(res), len(vals))
262262

263+
res, err = client.VRange(ctx, vecName, "[k1", "[k2", -1).Result()
264+
expectNil(err)
265+
expectEqual(len(res), 2)
266+
267+
res, err = client.VRange(ctx, vecName, "-", "[k2", -1).Result()
268+
expectNil(err)
269+
expectEqual(len(res), 3)
270+
271+
res, err = client.VRange(ctx, vecName, "(k1", "+", -1).Result()
272+
expectNil(err)
273+
expectEqual(len(res), 3)
274+
275+
res, err = client.VRange(ctx, vecName, "[k1", "+", 2).Result()
276+
expectNil(err)
277+
expectEqual(len(res), 2)
278+
263279
// test equality
264280
sim, err := client.VSimWithArgs(ctx, vecName, &vals[0].v, &redis.VSimArgs{
265281
Filter: `.age == 25`,

0 commit comments

Comments
 (0)