Skip to content

Commit d511984

Browse files
Merge branch 'master' into DOC-5472-time-series-doc-examples
2 parents f138803 + 9cfefa6 commit d511984

File tree

7 files changed

+149
-14
lines changed

7 files changed

+149
-14
lines changed

commands_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6169,6 +6169,34 @@ var _ = Describe("Commands", func() {
61696169
Expect(n).To(Equal(int64(3)))
61706170
})
61716171

6172+
It("should XTrimMaxLenMode", func() {
6173+
SkipBeforeRedisVersion(8.2, "doesn't work with older redis stack images")
6174+
n, err := client.XTrimMaxLenMode(ctx, "stream", 0, "KEEPREF").Result()
6175+
Expect(err).NotTo(HaveOccurred())
6176+
Expect(n).To(BeNumerically(">=", 0))
6177+
})
6178+
6179+
It("should XTrimMaxLenApproxMode", func() {
6180+
SkipBeforeRedisVersion(8.2, "doesn't work with older redis stack images")
6181+
n, err := client.XTrimMaxLenApproxMode(ctx, "stream", 0, 0, "KEEPREF").Result()
6182+
Expect(err).NotTo(HaveOccurred())
6183+
Expect(n).To(BeNumerically(">=", 0))
6184+
})
6185+
6186+
It("should XTrimMinIDMode", func() {
6187+
SkipBeforeRedisVersion(8.2, "doesn't work with older redis stack images")
6188+
n, err := client.XTrimMinIDMode(ctx, "stream", "4-0", "KEEPREF").Result()
6189+
Expect(err).NotTo(HaveOccurred())
6190+
Expect(n).To(BeNumerically(">=", 0))
6191+
})
6192+
6193+
It("should XTrimMinIDApproxMode", func() {
6194+
SkipBeforeRedisVersion(8.2, "doesn't work with older redis stack images")
6195+
n, err := client.XTrimMinIDApproxMode(ctx, "stream", "4-0", 0, "KEEPREF").Result()
6196+
Expect(err).NotTo(HaveOccurred())
6197+
Expect(n).To(BeNumerically(">=", 0))
6198+
})
6199+
61726200
It("should XAdd", func() {
61736201
id, err := client.XAdd(ctx, &redis.XAddArgs{
61746202
Stream: "stream",
@@ -6222,6 +6250,37 @@ var _ = Describe("Commands", func() {
62226250
Expect(n).To(Equal(int64(3)))
62236251
})
62246252

6253+
It("should XAckDel", func() {
6254+
SkipBeforeRedisVersion(8.2, "doesn't work with older redis stack images")
6255+
// First, create a consumer group
6256+
err := client.XGroupCreate(ctx, "stream", "testgroup", "0").Err()
6257+
Expect(err).NotTo(HaveOccurred())
6258+
6259+
// Read messages to create pending entries
6260+
_, err = client.XReadGroup(ctx, &redis.XReadGroupArgs{
6261+
Group: "testgroup",
6262+
Consumer: "testconsumer",
6263+
Streams: []string{"stream", ">"},
6264+
}).Result()
6265+
Expect(err).NotTo(HaveOccurred())
6266+
6267+
// Test XAckDel with KEEPREF mode
6268+
n, err := client.XAckDel(ctx, "stream", "testgroup", "KEEPREF", "1-0", "2-0").Result()
6269+
Expect(err).NotTo(HaveOccurred())
6270+
Expect(n).To(HaveLen(2))
6271+
6272+
// Clean up
6273+
client.XGroupDestroy(ctx, "stream", "testgroup")
6274+
})
6275+
6276+
It("should XDelEx", func() {
6277+
SkipBeforeRedisVersion(8.2, "doesn't work with older redis stack images")
6278+
// Test XDelEx with KEEPREF mode
6279+
n, err := client.XDelEx(ctx, "stream", "KEEPREF", "1-0", "2-0").Result()
6280+
Expect(err).NotTo(HaveOccurred())
6281+
Expect(n).To(HaveLen(2))
6282+
})
6283+
62256284
It("should XLen", func() {
62266285
n, err := client.XLen(ctx, "stream").Result()
62276286
Expect(err).NotTo(HaveOccurred())

doctests/geo_index_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ func ExampleClient_geoindex() {
199199
// OK
200200
// OK
201201
// OK
202-
// {1 [{product:46885 <nil> <nil> <nil> map[$:{"city":"Denver","description":"Navy Blue Slippers","location":"-104.991531, 39.742043","price":45.99}]}]}
202+
// {1 [{product:46885 <nil> <nil> <nil> map[$:{"city":"Denver","description":"Navy Blue Slippers","location":"-104.991531, 39.742043","price":45.99}] <nil>}]}
203203
// OK
204204
// OK
205205
// OK
206206
// OK
207207
// OK
208-
// {1 [{shape:4 <nil> <nil> <nil> map[$:[{"geom":"POINT (2 2)","name":"Purple Point"}]]}]}
208+
// {1 [{shape:4 <nil> <nil> <nil> map[$:[{"geom":"POINT (2 2)","name":"Purple Point"}]] <nil>}]}
209209
}

doctests/home_json_example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func ExampleClient_search_json() {
219219
// STEP_END
220220

221221
// Output:
222-
// {1 [{user:3 <nil> <nil> <nil> map[$:{"age":35,"city":"Tel Aviv","email":"[email protected]","name":"Paul Zamir"}]}]}
222+
// {1 [{user:3 <nil> <nil> <nil> map[$:{"age":35,"city":"Tel Aviv","email":"[email protected]","name":"Paul Zamir"}] <nil>}]}
223223
// London
224224
// Tel Aviv
225225
// 0
@@ -329,5 +329,5 @@ func ExampleClient_search_hash() {
329329
// STEP_END
330330

331331
// Output:
332-
// {1 [{huser:3 <nil> <nil> <nil> map[age:35 city:Tel Aviv email:[email protected] name:Paul Zamir]}]}
332+
// {1 [{huser:3 <nil> <nil> <nil> map[age:35 city:Tel Aviv email:[email protected] name:Paul Zamir] <nil>}]}
333333
}

doctests/search_quickstart_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,6 @@ func ExampleClient_search_qs() {
257257

258258
// Output:
259259
// Documents found: 10
260-
// {1 [{bicycle:0 <nil> <nil> <nil> map[$:{"brand":"Velorim","condition":"new","description":"Small and powerful, the Jigger is the best ride for the smallest of tikes! This is the tiniest kids’ pedal bike on the market available without a coaster brake, the Jigger is the vehicle of choice for the rare tenacious little rider raring to go.","model":"Jigger","price":270}]}]}
261-
// {1 [{bicycle:4 <nil> <nil> <nil> map[$:{"brand":"Noka Bikes","condition":"used","description":"Whether you want to try your hand at XC racing or are looking for a lively trail bike that's just as inspiring on the climbs as it is over rougher ground, the Wilder is one heck of a bike built specifically for short women. Both the frames and components have been tweaked to include a women’s saddle, different bars and unique colourway.","model":"Kahuna","price":3200}]}]}
260+
// {1 [{bicycle:0 <nil> <nil> <nil> map[$:{"brand":"Velorim","condition":"new","description":"Small and powerful, the Jigger is the best ride for the smallest of tikes! This is the tiniest kids’ pedal bike on the market available without a coaster brake, the Jigger is the vehicle of choice for the rare tenacious little rider raring to go.","model":"Jigger","price":270}] <nil>}]}
261+
// {1 [{bicycle:4 <nil> <nil> <nil> map[$:{"brand":"Noka Bikes","condition":"used","description":"Whether you want to try your hand at XC racing or are looking for a lively trail bike that's just as inspiring on the climbs as it is over rougher ground, the Wilder is one heck of a bike built specifically for short women. Both the frames and components have been tweaked to include a women’s saddle, different bars and unique colourway.","model":"Kahuna","price":3200}] <nil>}]}
262262
}

search_commands.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ type Document struct {
474474
Payload *string
475475
SortKey *string
476476
Fields map[string]string
477+
Error error
477478
}
478479

479480
type AggregateQuery []interface{}
@@ -1654,7 +1655,13 @@ func parseFTSearch(data []interface{}, noContent, withScores, withPayloads, with
16541655
if i < len(data) {
16551656
fields, ok := data[i].([]interface{})
16561657
if !ok {
1657-
return FTSearchResult{}, fmt.Errorf("invalid document fields format")
1658+
if data[i] == proto.Nil || data[i] == nil {
1659+
doc.Error = proto.Nil
1660+
doc.Fields = map[string]string{}
1661+
fields = []interface{}{}
1662+
} else {
1663+
return FTSearchResult{}, fmt.Errorf("invalid document fields format")
1664+
}
16581665
}
16591666

16601667
for j := 0; j < len(fields); j += 2 {

stream_commands.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77

88
type StreamCmdable interface {
99
XAdd(ctx context.Context, a *XAddArgs) *StringCmd
10+
XAckDel(ctx context.Context, stream string, group string, mode string, ids ...string) *SliceCmd
1011
XDel(ctx context.Context, stream string, ids ...string) *IntCmd
12+
XDelEx(ctx context.Context, stream string, mode string, ids ...string) *SliceCmd
1113
XLen(ctx context.Context, stream string) *IntCmd
1214
XRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd
1315
XRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd
@@ -31,8 +33,12 @@ type StreamCmdable interface {
3133
XAutoClaimJustID(ctx context.Context, a *XAutoClaimArgs) *XAutoClaimJustIDCmd
3234
XTrimMaxLen(ctx context.Context, key string, maxLen int64) *IntCmd
3335
XTrimMaxLenApprox(ctx context.Context, key string, maxLen, limit int64) *IntCmd
36+
XTrimMaxLenMode(ctx context.Context, key string, maxLen int64, mode string) *IntCmd
37+
XTrimMaxLenApproxMode(ctx context.Context, key string, maxLen, limit int64, mode string) *IntCmd
3438
XTrimMinID(ctx context.Context, key string, minID string) *IntCmd
3539
XTrimMinIDApprox(ctx context.Context, key string, minID string, limit int64) *IntCmd
40+
XTrimMinIDMode(ctx context.Context, key string, minID string, mode string) *IntCmd
41+
XTrimMinIDApproxMode(ctx context.Context, key string, minID string, limit int64, mode string) *IntCmd
3642
XInfoGroups(ctx context.Context, key string) *XInfoGroupsCmd
3743
XInfoStream(ctx context.Context, key string) *XInfoStreamCmd
3844
XInfoStreamFull(ctx context.Context, key string, count int) *XInfoStreamFullCmd
@@ -54,6 +60,7 @@ type XAddArgs struct {
5460
// Approx causes MaxLen and MinID to use "~" matcher (instead of "=").
5561
Approx bool
5662
Limit int64
63+
Mode string
5764
ID string
5865
Values interface{}
5966
}
@@ -81,6 +88,11 @@ func (c cmdable) XAdd(ctx context.Context, a *XAddArgs) *StringCmd {
8188
if a.Limit > 0 {
8289
args = append(args, "limit", a.Limit)
8390
}
91+
92+
if a.Mode != "" {
93+
args = append(args, a.Mode)
94+
}
95+
8496
if a.ID != "" {
8597
args = append(args, a.ID)
8698
} else {
@@ -93,6 +105,16 @@ func (c cmdable) XAdd(ctx context.Context, a *XAddArgs) *StringCmd {
93105
return cmd
94106
}
95107

108+
func (c cmdable) XAckDel(ctx context.Context, stream string, group string, mode string, ids ...string) *SliceCmd {
109+
args := []interface{}{"xackdel", stream, group, mode, "ids", len(ids)}
110+
for _, id := range ids {
111+
args = append(args, id)
112+
}
113+
cmd := NewSliceCmd(ctx, args...)
114+
_ = c(ctx, cmd)
115+
return cmd
116+
}
117+
96118
func (c cmdable) XDel(ctx context.Context, stream string, ids ...string) *IntCmd {
97119
args := []interface{}{"xdel", stream}
98120
for _, id := range ids {
@@ -103,6 +125,16 @@ func (c cmdable) XDel(ctx context.Context, stream string, ids ...string) *IntCmd
103125
return cmd
104126
}
105127

128+
func (c cmdable) XDelEx(ctx context.Context, stream string, mode string, ids ...string) *SliceCmd {
129+
args := []interface{}{"xdelex", stream, mode, "ids", len(ids)}
130+
for _, id := range ids {
131+
args = append(args, id)
132+
}
133+
cmd := NewSliceCmd(ctx, args...)
134+
_ = c(ctx, cmd)
135+
return cmd
136+
}
137+
106138
func (c cmdable) XLen(ctx context.Context, stream string) *IntCmd {
107139
cmd := NewIntCmd(ctx, "xlen", stream)
108140
_ = c(ctx, cmd)
@@ -375,6 +407,8 @@ func xClaimArgs(a *XClaimArgs) []interface{} {
375407
return args
376408
}
377409

410+
// TODO: refactor xTrim, xTrimMode and the wrappers over the functions
411+
378412
// xTrim If approx is true, add the "~" parameter, otherwise it is the default "=" (redis default).
379413
// example:
380414
//
@@ -418,6 +452,42 @@ func (c cmdable) XTrimMinIDApprox(ctx context.Context, key string, minID string,
418452
return c.xTrim(ctx, key, "minid", true, minID, limit)
419453
}
420454

455+
func (c cmdable) xTrimMode(
456+
ctx context.Context, key, strategy string,
457+
approx bool, threshold interface{}, limit int64,
458+
mode string,
459+
) *IntCmd {
460+
args := make([]interface{}, 0, 7)
461+
args = append(args, "xtrim", key, strategy)
462+
if approx {
463+
args = append(args, "~")
464+
}
465+
args = append(args, threshold)
466+
if limit > 0 {
467+
args = append(args, "limit", limit)
468+
}
469+
args = append(args, mode)
470+
cmd := NewIntCmd(ctx, args...)
471+
_ = c(ctx, cmd)
472+
return cmd
473+
}
474+
475+
func (c cmdable) XTrimMaxLenMode(ctx context.Context, key string, maxLen int64, mode string) *IntCmd {
476+
return c.xTrimMode(ctx, key, "maxlen", false, maxLen, 0, mode)
477+
}
478+
479+
func (c cmdable) XTrimMaxLenApproxMode(ctx context.Context, key string, maxLen, limit int64, mode string) *IntCmd {
480+
return c.xTrimMode(ctx, key, "maxlen", true, maxLen, limit, mode)
481+
}
482+
483+
func (c cmdable) XTrimMinIDMode(ctx context.Context, key string, minID string, mode string) *IntCmd {
484+
return c.xTrimMode(ctx, key, "minid", false, minID, 0, mode)
485+
}
486+
487+
func (c cmdable) XTrimMinIDApproxMode(ctx context.Context, key string, minID string, limit int64, mode string) *IntCmd {
488+
return c.xTrimMode(ctx, key, "minid", true, minID, limit, mode)
489+
}
490+
421491
func (c cmdable) XInfoConsumers(ctx context.Context, key string, group string) *XInfoConsumersCmd {
422492
cmd := NewXInfoConsumersCmd(ctx, key, group)
423493
_ = c(ctx, cmd)

vectorset_commands.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ type VSimArgs struct {
287287
FilterEF int64
288288
Truth bool
289289
NoThread bool
290-
// The `VSim` command in Redis has the option, by the doc in Redis.io don't have.
291-
// Epsilon float64
290+
Epsilon float64
292291
}
293292

294293
func (v VSimArgs) appendArgs(args []any) []any {
@@ -310,13 +309,13 @@ func (v VSimArgs) appendArgs(args []any) []any {
310309
if v.NoThread {
311310
args = append(args, "nothread")
312311
}
313-
// if v.Epsilon > 0 {
314-
// args = append(args, "Epsilon", v.Epsilon)
315-
// }
312+
if v.Epsilon > 0 {
313+
args = append(args, "Epsilon", v.Epsilon)
314+
}
316315
return args
317316
}
318317

319-
// `VSIM key (ELE | FP32 | VALUES num) (vector | element) [COUNT num]
318+
// `VSIM key (ELE | FP32 | VALUES num) (vector | element) [COUNT num] [EPSILON delta]
320319
// [EF search-exploration-factor] [FILTER expression] [FILTER-EF max-filtering-effort] [TRUTH] [NOTHREAD]`
321320
// note: the API is experimental and may be subject to change.
322321
func (c cmdable) VSimWithArgs(ctx context.Context, key string, val Vector, simArgs *VSimArgs) *StringSliceCmd {
@@ -331,7 +330,7 @@ func (c cmdable) VSimWithArgs(ctx context.Context, key string, val Vector, simAr
331330
return cmd
332331
}
333332

334-
// `VSIM key (ELE | FP32 | VALUES num) (vector | element) [WITHSCORES] [COUNT num]
333+
// `VSIM key (ELE | FP32 | VALUES num) (vector | element) [WITHSCORES] [COUNT num] [EPSILON delta]
335334
// [EF search-exploration-factor] [FILTER expression] [FILTER-EF max-filtering-effort] [TRUTH] [NOTHREAD]`
336335
// note: the API is experimental and may be subject to change.
337336
func (c cmdable) VSimWithArgsWithScores(ctx context.Context, key string, val Vector, simArgs *VSimArgs) *VectorScoreSliceCmd {

0 commit comments

Comments
 (0)