4

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

FOKO THierry
  • 241
  • 3
  • 12

3 Answers3

4

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.

Guy Korland
  • 9,139
  • 14
  • 59
  • 106
  • 1
    Thank you I find it hard to understand how to do it. Is there a way when the symfony handler retrieves the message to process, how to retrieve the message id so that at the end of processing by the handler   symfony, I can remove this message from the redis stream. Thank you – FOKO THierry May 14 '20 at 16:43
0

Simple steps:

  1. Read a stream message and keep its ID.
  2. When you are done processing the message use the XDEL command to delete specific entries from the redis stream.

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

rsjethani
  • 2,179
  • 6
  • 24
  • 30
-1

Want to add here that in Symfony 5 ?delete_after_ack=true was added.

MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages?delete_after_ack=true

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 or stream_max_entries which trims the stream. Keep in mind stream_max_entries is trim messages aways which also are not processed. So it should be a high enough value.

Alexander Schranz
  • 2,154
  • 2
  • 25
  • 42