7
7
8
8
type StreamCmdable interface {
9
9
XAdd (ctx context.Context , a * XAddArgs ) * StringCmd
10
+ XAckDel (ctx context.Context , stream string , group string , mode string , ids ... string ) * SliceCmd
10
11
XDel (ctx context.Context , stream string , ids ... string ) * IntCmd
12
+ XDelEx (ctx context.Context , stream string , mode string , ids ... string ) * SliceCmd
11
13
XLen (ctx context.Context , stream string ) * IntCmd
12
14
XRange (ctx context.Context , stream , start , stop string ) * XMessageSliceCmd
13
15
XRangeN (ctx context.Context , stream , start , stop string , count int64 ) * XMessageSliceCmd
@@ -31,8 +33,12 @@ type StreamCmdable interface {
31
33
XAutoClaimJustID (ctx context.Context , a * XAutoClaimArgs ) * XAutoClaimJustIDCmd
32
34
XTrimMaxLen (ctx context.Context , key string , maxLen int64 ) * IntCmd
33
35
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
34
38
XTrimMinID (ctx context.Context , key string , minID string ) * IntCmd
35
39
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
36
42
XInfoGroups (ctx context.Context , key string ) * XInfoGroupsCmd
37
43
XInfoStream (ctx context.Context , key string ) * XInfoStreamCmd
38
44
XInfoStreamFull (ctx context.Context , key string , count int ) * XInfoStreamFullCmd
@@ -54,6 +60,7 @@ type XAddArgs struct {
54
60
// Approx causes MaxLen and MinID to use "~" matcher (instead of "=").
55
61
Approx bool
56
62
Limit int64
63
+ Mode string
57
64
ID string
58
65
Values interface {}
59
66
}
@@ -81,6 +88,11 @@ func (c cmdable) XAdd(ctx context.Context, a *XAddArgs) *StringCmd {
81
88
if a .Limit > 0 {
82
89
args = append (args , "limit" , a .Limit )
83
90
}
91
+
92
+ if a .Mode != "" {
93
+ args = append (args , a .Mode )
94
+ }
95
+
84
96
if a .ID != "" {
85
97
args = append (args , a .ID )
86
98
} else {
@@ -93,6 +105,16 @@ func (c cmdable) XAdd(ctx context.Context, a *XAddArgs) *StringCmd {
93
105
return cmd
94
106
}
95
107
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
+
96
118
func (c cmdable ) XDel (ctx context.Context , stream string , ids ... string ) * IntCmd {
97
119
args := []interface {}{"xdel" , stream }
98
120
for _ , id := range ids {
@@ -103,6 +125,16 @@ func (c cmdable) XDel(ctx context.Context, stream string, ids ...string) *IntCmd
103
125
return cmd
104
126
}
105
127
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
+
106
138
func (c cmdable ) XLen (ctx context.Context , stream string ) * IntCmd {
107
139
cmd := NewIntCmd (ctx , "xlen" , stream )
108
140
_ = c (ctx , cmd )
@@ -375,6 +407,8 @@ func xClaimArgs(a *XClaimArgs) []interface{} {
375
407
return args
376
408
}
377
409
410
+ // TODO: refactor xTrim, xTrimMode and the wrappers over the functions
411
+
378
412
// xTrim If approx is true, add the "~" parameter, otherwise it is the default "=" (redis default).
379
413
// example:
380
414
//
@@ -418,6 +452,42 @@ func (c cmdable) XTrimMinIDApprox(ctx context.Context, key string, minID string,
418
452
return c .xTrim (ctx , key , "minid" , true , minID , limit )
419
453
}
420
454
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
+
421
491
func (c cmdable ) XInfoConsumers (ctx context.Context , key string , group string ) * XInfoConsumersCmd {
422
492
cmd := NewXInfoConsumersCmd (ctx , key , group )
423
493
_ = c (ctx , cmd )
0 commit comments