Skip to content

Commit 9c425cb

Browse files
authored
feat(vectorset): add vrange command (#3543)
1 parent 5fdc947 commit 9c425cb

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

vectorset_commands.go

Lines changed: 11 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,13 @@ 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+
// a negative count means to return all the elements in the vector set.
352+
// note: the API is experimental and may be subject to change.
353+
func (c cmdable) VRange(ctx context.Context, key, start, end string, count int64) *StringSliceCmd {
354+
args := []any{"vrange", key, start, end, count}
355+
cmd := NewStringSliceCmd(ctx, args...)
356+
_ = c(ctx, cmd)
357+
return cmd
358+
}

vectorset_commands_integration_test.go

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

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

0 commit comments

Comments
 (0)