10

I just realized that the XACK do not auto delete message when only one consumer group exist.

I thought that when all consumer groups ack the same message, the message will be deleted by Redis-server, but seemed that this is not the case.

So, the Redis stream memory increases infinitely because of no messages will be deleted.

Maybe the only way to preventing this is manually XDEL message? But how can I know all consumer groups have acked the message?

Need some help, thanks!

UNSTABLE
  • 393
  • 1
  • 4
  • 13
  • 2
    why downvote? I know we can add MAXLEN in XADD, but it maybe deletes msg that no one has consumed if msg is pending too much. I just curious about how to achieve safety and efficiency at the same time. – UNSTABLE Mar 20 '20 at 06:22

1 Answers1

7

Redis streams are primarily an append-only data structure. It's possible to remove an entry using the XDEL command, however that doesn't necessarily free up the memory used by the entry:

> XDEL mystream 1538561700640-0
(integer) 1

You could also cap the stream with an arbitrary threshold using the MAXLEN option to XADD or use the XTRIM command explicitly:

> XADD mystream MAXLEN 1000 * value 1
1526654998691-0
...
> XLEN mystream
(integer) 1000

But how can I know all consumer groups have acked the message?

You can inspect the list of pending messages for each consumer group using the XPENDING command:

> XPENDING mystream mygroup
1) (integer) 1
2) 1526984818136-0
3) 1526984818136-0
4) 1) 1) "consumer-1"
      2) "1"
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378