lib/redis/lock.rb in redis-objects-0.2.3 vs lib/redis/lock.rb in redis-objects-0.2.4
- old
+ new
@@ -8,14 +8,15 @@
#
class Lock
class LockTimeout < StandardError; end #:nodoc:
attr_reader :key, :options, :redis
- def initialize(key, redis=$redis, options={})
+ def initialize(key, *args)
@key = key
- @redis = redis
- @options = options
+ @options = args.last.is_a?(Hash) ? args.pop : {}
+ @redis = args.first || $redis
@options[:timeout] ||= 5
+ @options[:init] = false if @options[:init].nil? # default :init to false
@redis.setnx(key, @options[:start]) unless @options[:start] == 0 || @options[:init] === false
end
# Clear the lock. Should only be needed if there's a server crash
# or some other event that gets locks in a stuck state.
\ No newline at end of file