I use redis as transport in messenger, I thought that after processing a flow the deletion was automatic but alas not. I do not know how to delete a repeat stream when the processing has been carried out with success.
I use symfony 4.4.latest and redis server 6.0
Thanks
3
Answers
The way to do it is by using XTRIM command.
You can call you process couple of messages you trim the stream to retain only the messages that were not processed. By, calling XLEN you can get the stream size and if you subtract the amount of messages you processed you should be left with the right argument for the XTRIM.
Simple steps:
BTW redis streams are not supposed to be used like this, better use pub/sub functionality as @Dudo mentioned. This is a good introduction to redis streams: https://redis.io/topics/streams-intro
Want to add here that in Symfony 5
?delete_after_ack=true
was added.Why the default in Symfony 5 is false. The default in Symfony 6 is
true
so Symfony 6 will automatically remove acked message.See also: https://symfony.com/doc/current/messenger.html#redis-transport
There are also other parameters like
delete_after_reject
orstream_max_entries
which trims the stream. Keep in mindstream_max_entries
is trim messages aways which also are not processed. So it should be a high enough value.