Skip to content

Commit e8f0c32

Browse files
authored
Merge pull request #28 from vitorarins/add-default-maxlen
2 parents d73fcac + 3c809ba commit e8f0c32

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
up:
22
docker-compose up -d
33

4+
down:
5+
docker-compose down
6+
47
test:
58
go test ./...
69

pkg/redisstream/publisher.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ func NewPublisher(config PublisherConfig, logger watermill.LoggerAdapter) (*Publ
4040
}
4141

4242
type PublisherConfig struct {
43-
Client redis.UniversalClient
44-
Marshaller Marshaller
45-
Maxlens map[string]int64
43+
Client redis.UniversalClient
44+
Marshaller Marshaller
45+
Maxlens map[string]int64
46+
DefaultMaxlen int64
4647
}
4748

4849
func (c *PublisherConfig) setDefaults() {
@@ -58,7 +59,7 @@ func (c *PublisherConfig) Validate() error {
5859
for topic, maxlen := range c.Maxlens {
5960
if maxlen < 0 {
6061
// zero maxlen stream indicates unlimited stream length
61-
c.Maxlens[topic] = 0
62+
c.Maxlens[topic] = c.DefaultMaxlen
6263
}
6364
}
6465
return nil
@@ -87,7 +88,7 @@ func (p *Publisher) Publish(topic string, msgs ...*message.Message) error {
8788

8889
maxlen, ok := p.config.Maxlens[topic]
8990
if !ok {
90-
maxlen = 0
91+
maxlen = p.config.DefaultMaxlen
9192
}
9293

9394
id, err := p.client.XAdd(context.Background(), &redis.XAddArgs{

0 commit comments

Comments
 (0)