You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

neural_maybe_lock.lua 565B

12345678910111213141516171819
  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. local locked = redis.call('HGET', KEYS[1], 'lock')
  8. local now = tonumber(KEYS[2])
  9. if locked then
  10. locked = tonumber(locked)
  11. local expire = tonumber(KEYS[3])
  12. if now > locked and (now - locked) < expire then
  13. return {tostring(locked), redis.call('HGET', KEYS[1], 'hostname') or 'unknown'}
  14. end
  15. end
  16. redis.call('HSET', KEYS[1], 'lock', tostring(now))
  17. redis.call('HSET', KEYS[1], 'hostname', KEYS[4])
  18. return 1