unlock.lua 248 Bytes
Newer Older
fangxinjiang's avatar
fangxinjiang committed
1 2 3 4 5 6 7 8 9 10 11 12
local key = KEYS[1];
local threadId = ARGV[1];

if (redis.call('HEXISTS', key, threadId) == 0) then
    return nil;
end;
local count = redis.call('HINCRBY', key, threadId, -1);

if (count == 0) then
    redis.call('DEL', key);
    return nil;
end;