Problem:
In a Redis setup, utilizing setEX to set a key with an expiration time, I’ve encountered an issue where the expired event is triggered multiple times for the same key if the channel is subscribed to multiple times. Despite attempting to mitigate this by unsubscribing and then resubscribing to the channel, the expired event still occasionally fires twice.
Details:
- Redis client version: 4.6.7.
- The process involves setting a key with a defined expiration time using setEX.
- Upon expiration, an event is triggered on a subscribed channel.
- If the channel is subscribed to multiple times, the expired event may be emitted multiple times.
- To address this, unsubscribing from the channel before resubscribing is
attempted as a workaround. - Despite implementing this workaround, there are instances where the expired event is still triggered twice.
Expected Behavior:
The expired event should only be triggered once, regardless of how many times the channel is subscribed to.
Additional Information:
- I’ve ensured that the unsubscribe/resubscribe logic is correctly implemented.
- This issue occurs sporadically and is difficult to replicate consistently.
- Redis client version is 4.6.7.
- Any insights or suggestions on why the expired event might be firing twice, despite attempts to prevent it, would be greatly appreciated.