redisredis-streams

How to remove redis stream pending entries from a consumer?


When a consumer from a group xread a stream entry, it will go to the consumer pending entry and as far as I know, it could be removed from the PEL either the consumer do XACK or it is XCLAIM/XAUTOCLAIM by another consumer.

Though my question, if the original consumer died after reading the entry without sending XACK, is there a way to retrieve(?) or change it's status back to unprocessed, so when a consumer read the stream it was given to that consumer. or is the only way by claiming it to another consumer?

because XCLAIM can only be done if we know who's the consumer right? and in this case, i was hoping i could just change the status of the entry to unprocessed, so new consumer can read it

I'm new to Redis, so any thought would be appreciated :) thankyou


Solution

  • if the original consumer died after reading the entry without sending XACK, is there a way to retrieve(?) or change it's status back to unprocessed

    No, there isn't: once in the PEL, entries can only be pointed to another consumer but can't be released as if they were never read.

    because XCLAIM can only be done if we know who's the consumer right?

    Indeed, but you could have a special consumer which, within a single LUA script to guarantee atomicity:

    1. XCLAIMs pending entries based on certain criteria (e.g. idle time) and assigns them to itself;
    2. XREADGROUPs them from the PEL;
    3. XADDs them back to the original stream; and,
    4. XACKs the entries read in step 2.

    I would consider this sequence of commands overkill for most scenarios I can think of and I would suggest to avoid using it. But it would allow to re-read and re-assign a copy of the entries which were in the PEL to other consumers as they XREADGROUP them.