lib/distributed_mutex.rb
# Use lua script to maintain atomicity
Use lua script to maintain atomicity
Use lua script to maintain atomicity
def lock
    lock_lua = %(
      if (redis.call('setnx', KEYS[1], ARGV[1]) < 1)
      then
        return 0
      end
      return redis.call('expire', KEYS[1], tonumber(ARGV[2]))
    )
    redis.eval(lock_lua, keys: [key], argv: [uuid, timeout]).positive?
  end
def lock lock_lua = %(
      if (redis.call('setnx', KEYS[1], ARGV[1]) < 1)
      then
        return 0
      end
      return redis.call('expire', KEYS[1], tonumber(ARGV[2]))
    ) redis . eval ( lock_lua , keys : [ key ] , argv : [ uuid , timeout ] ) . positive? end
Use lua script to maintain atomicity
Use lua script to maintain atomicity