#!/usr/bin/env ruby require "bundler/setup" require "redis_getlock" require 'logger' require 'optparse' opts = { timeout: -1, kill: false } OptionParser.new.tap {|op| op.on('--timeout VALUE') {|v| opts[:timeout] = Float(v) } op.on('--kill') {|v| opts[:kill] = true } op.parse(ARGV) } if opts[:kill] trap('INT') do exit! end end mutex = RedisGetlock.new( redis: Redis.new, key: 'redis_getlock', logger: Logger.new(STDOUT), timeout: opts[:timeout], ) puts 'redis-cli> del redis_getlock' mutex.synchronize do loop do puts "locked?:#{mutex.locked?} self_locked?:#{mutex.self_locked?}" sleep 1 end end