Debian Codegraph @

lualib/redis_scripts/neural_maybe_lock.lua

raw
1 -- Lua script lock ANN for learning
2 -- Uses the following keys
3 -- key1 - prefix for keys
4 -- key2 - current time
5 -- key3 - key expire
6 -- key4 - hostname
7
8 local locked = redis.call('HGET', KEYS[1], 'lock')
9 local now = tonumber(KEYS[2])
10 if locked then
11 locked = tonumber(locked)
12 local expire = tonumber(KEYS[3])
13 if now > locked and (now - locked) < expire then
14 return { tostring(locked), redis.call('HGET', KEYS[1], 'hostname') or 'unknown' }
15 end
16 end
17 redis.call('HSET', KEYS[1], 'lock', tostring(now))
18 redis.call('HSET', KEYS[1], 'hostname', KEYS[4])
19 return 1