Sha256: 376af38c3ce4800020ecb2b96a705d5f342c6eb76331ac6304497fc5c1ca4bb4
Contents?: true
Size: 1.82 KB
Versions: 6
Compression:
Stored size: 1.82 KB
Contents
-- redis.replicate_commands(); local exists_key = KEYS[1] local grabbed_key = KEYS[2] local available_key = KEYS[3] local unique_keys = KEYS[4] local unique_digest = KEYS[5] local job_id = ARGV[1] local ttl = tonumber(ARGV[2]) local lock = ARGV[3] local function current_time() local time = redis.call('time') local s = time[1] local ms = time[2] local number = tonumber((s .. '.' .. ms)) return number end local stored_token = redis.call('GET', exists_key) if stored_token and stored_token ~= job_id then return stored_token end redis.call('SET', exists_key, job_id) ---------------------------------------------------------------- -- TODO: Legacy support (Remove in v6.1) local old_token = redis.call('GET', unique_digest) if old_token then if old_token == job_id or old_token == '2' then -- No need to return, we just delete the old key redis.call('DEL', unique_digest) else return old_token end end ---------------------------------------------------------------- redis.call('SADD', unique_keys, unique_digest) redis.call('DEL', grabbed_key) -- TODO: Move this to LUA when redis 3.2 is the least supported -- redis.call('HSET', grabbed_key, job_id, current_time()) --------------------------------------------------------------- redis.call('DEL', available_key) redis.call('RPUSH', available_key, job_id) -- The client should only set ttl for until_expired -- The server should set ttl for all other jobs -- redis.log(redis.LOG_WARNING, "lock: " .. lock .. ", ttl: " .. tostring(ttl)) if lock == "until_expired" and ttl and ttl > 0 then -- We can't keep the key here because it will otherwise never be deleted redis.call('SREM', unique_keys, unique_digest) redis.call('EXPIRE', available_key, ttl) redis.call('EXPIRE', exists_key, ttl) redis.call('EXPIRE', unique_digest, ttl) end return job_id
Version data entries
6 entries across 6 versions & 1 rubygems