ExHammer / hammer-backend-redis

A Redis backend for for the Hammer rate-limiter
https://hexdocs.pm/ExHammer/hammer-backend-redis
MIT License
48 stars 32 forks source link

Remove the need for optimistic locking when counting hits #28

Closed mrnovalles closed 2 years ago

mrnovalles commented 2 years ago

The behaviour of redis changed between version 6.0 and 6.2 when it comes to expiring keys while in the middle of a MULTI block execution (see https://github.com/redis/redis/pull/7920). This caused issues in our production environment since WATCH preventend the EXEC in create_bucket to succeed when some key expired. This resulted in a race condition that would prevent the creation of a new bucket time after time.

While trying to fix this behaviour we realized that the complexity added by WATCHing different keys drived this problem. Our intention is to remove the need for watch (used as an optimistic locking mechanism) and simplify this piece of code.

Fixes: https://github.com/ExHammer/hammer-backend-redis/issues/26

Changes

Notes

epinault commented 2 years ago

that looks fine to me but eventually I wonder if a simple lua script would be more efficient