From 5d13acf1ae7a634a341947aed2537ef1b34f7814 Mon Sep 17 00:00:00 2001 From: Xiaolong Chen Date: Fri, 10 Oct 2025 14:00:03 +0800 Subject: [PATCH 1/2] add vrange command Signed-off-by: Xiaolong Chen --- vectorset_commands.go | 13 +++++++++++++ vectorset_commands_integration_test.go | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/vectorset_commands.go b/vectorset_commands.go index 96be1af110..6e1363ce39 100644 --- a/vectorset_commands.go +++ b/vectorset_commands.go @@ -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 { @@ -345,3 +346,15 @@ func (c cmdable) VSimWithArgsWithScores(ctx context.Context, key string, val Vec _ = c(ctx, cmd) return cmd } + +// `VRANGE key start end count` +// 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} + if count != 0 { + args = append(args, count) + } + cmd := NewStringSliceCmd(ctx, args...) + _ = c(ctx, cmd) + return cmd +} diff --git a/vectorset_commands_integration_test.go b/vectorset_commands_integration_test.go index 147fb84c5e..521b444029 100644 --- a/vectorset_commands_integration_test.go +++ b/vectorset_commands_integration_test.go @@ -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`, From bf30bd7df0f387110a758815438b2455f9969210 Mon Sep 17 00:00:00 2001 From: Xiaolong Chen Date: Fri, 10 Oct 2025 14:28:52 +0800 Subject: [PATCH 2/2] update Signed-off-by: Xiaolong Chen --- vectorset_commands.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/vectorset_commands.go b/vectorset_commands.go index 6e1363ce39..8f99de0730 100644 --- a/vectorset_commands.go +++ b/vectorset_commands.go @@ -348,12 +348,10 @@ func (c cmdable) VSimWithArgsWithScores(ctx context.Context, key string, val Vec } // `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} - if count != 0 { - args = append(args, count) - } + args := []any{"vrange", key, start, end, count} cmd := NewStringSliceCmd(ctx, args...) _ = c(ctx, cmd) return cmd