Skip to content

Commit ea795f4

Browse files
committed
chore(redis): add max length in redis xadd
fix #16 Co-Author: @sankethkini Signed-off-by: Bo-Yi.Wu <[email protected]>
1 parent fa60f05 commit ea795f4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type options struct {
2121
cluster bool
2222
group string
2323
consumer string
24+
maxLength int64
2425
}
2526

2627
// WithAddr setup the addr of redis
@@ -30,6 +31,13 @@ func WithAddr(addr string) Option {
3031
}
3132
}
3233

34+
// WithMaxLength setup the max length for publish messages
35+
func WithMaxLength(m int64) Option {
36+
return func(w *options) {
37+
w.maxLength = m
38+
}
39+
}
40+
3341
// WithPassword redis password
3442
func WithDB(db int) Option {
3543
return func(w *options) {

redis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (w *Worker) queue(data interface{}) error {
208208
// Publish a message.
209209
err := w.rdb.XAdd(ctx, &redis.XAddArgs{
210210
Stream: w.opts.streamName,
211-
MaxLen: 0,
211+
MaxLen: w.opts.maxLength,
212212
Values: data,
213213
}).Err()
214214

0 commit comments

Comments
 (0)