lib/distributed_mutex.rb
def unlock
    unlock_lua = %(
      if (redis.call('get', KEYS[1]) == ARGV[1])
      then
        return redis.call('del', KEYS[1])
      else
        return 0
      end
    )
    redis.eval(unlock_lua, keys: [key], argv: [uuid]).positive?
  end
# Use lua script to maintain atomicity
Use lua script to maintain atomicity
Use lua script to maintain atomicity
def unlock
    unlock_lua = %(
      if (redis.call('get', KEYS[1]) == ARGV[1])
      then
        return redis.call('del', KEYS[1])
      else
        return 0
      end
    )
    redis.eval(unlock_lua, keys: [key], argv: [uuid]).positive?
  end
def unlock unlock_lua = %(
      if (redis.call('get', KEYS[1]) == ARGV[1])
      then
        return redis.call('del', KEYS[1])
      else
        return 0
      end
    ) redis . eval ( unlock_lua , keys : [ key ] , argv : [ uuid ] ) . positive? end
Use lua script to maintain atomicity
Use lua script to maintain atomicity