Hi everyone, I'm evaluating Redis streams for a project, and I'm trying to figure out the most efficient way to make sure that old messages are deleted from streams once they've been processed by all consumer groups. It seems like the generally recommended way to trim streams is using XTRIM, but it's important for this use case that I not delete any messages that haven't yet been processed, which XTRIM doesn't guarantee.
I've been considering having a process that inspects the state of the stream and uses XDEL on individual messages once it knows that all existing groups have seen them. It seems like I'd need to use XPENDING for each consumer group to find the oldest pending ids, then XRANGE to fetch all messages below the single oldest pending id, then XDEL all of their ids? And if XPENDING is empty, then the whole stream has been processed, and I should just be able to XTRIM the whole stream to zero. I'm assuming I'll do all this in a Lua script, so that there's no chance of any messages being added between the XPENDING and the XTRIM.
This all seems pretty inefficient, though. Has anyone solved this problem in a better/cleaner way? Also, does anyone see any flaws in this plan?
Thanks!
Chris