lib/sidekiq/throttled/strategy/concurrency.lua in sidekiq-throttled-0.7.3 vs lib/sidekiq/throttled/strategy/concurrency.lua in sidekiq-throttled-0.8.0
- old
+ new
@@ -1,13 +1,16 @@
local key = KEYS[1]
local jid = ARGV[1]
local lmt = tonumber(ARGV[2])
local ttl = tonumber(ARGV[3])
+local now = tonumber(ARGV[4])
-if lmt <= redis.call("SCARD", key) and 0 == redis.call("SISMEMBER", key, jid) then
+redis.call("ZREMRANGEBYSCORE", key, "-inf", "(" .. now)
+
+if lmt <= redis.call("ZCARD", key) and not redis.call("ZSCORE", key, jid) then
return 1
end
-redis.call("SADD", key, jid)
+redis.call("ZADD", key, now + ttl, jid)
redis.call("EXPIRE", key, ttl)
return 0