When incrementing the counter, we should use Redis#multi, rather than Redis#pipeline, to ensure that the hincrby, hdel, and expire are in the same call. If another process is checking #count between when hincrby and expire are called it could lead to an invalid count. Redis#multi protects against that.
Coverage remained the same at 99.138% when pulling 789f2c800db00c5fccc8cc30caab140d8076cdf3 on jeremywadsack:race_condition into aa8bd7a71e263a86451a75216589d408fa133342 on ejfinneran:master.
When incrementing the counter, we should use
Redis#multi
, rather thanRedis#pipeline
, to ensure that thehincrby
,hdel
, andexpire
are in the same call. If another process is checking#count
between whenhincrby
andexpire
are called it could lead to an invalid count.Redis#multi
protects against that.See the first example for rate limiting in the Redis documentation for
INCR
. Also note that the JS code that this gem was inspired by used themulti/exec
pattern as well.