lib/redis/objects/locks.rb in redis-objects-0.2.2 vs lib/redis/objects/locks.rb in redis-objects-0.2.3

- old
+ new

@@ -14,10 +14,11 @@ module ClassMethods # Define a new lock. It will function like a model attribute, # so it can be used alongside ActiveRecord/DataMapper, etc. def lock(name, options={}) options[:timeout] ||= 5 # seconds + options[:init] = false if options[:init].nil? # default :init to false @redis_objects[name] = options.merge(:type => :lock) if options[:global] instance_eval <<-EndMethods def #{name}_lock(&block) @#{name} ||= Redis::Lock.new(field_key(:#{name}_lock, ''), redis, @redis_objects[:#{name}]) @@ -45,10 +46,10 @@ # that was specified when the lock was defined. def obtain_lock(name, id, &block) verify_lock_defined!(name) raise ArgumentError, "Missing block to #{self.name}.obtain_lock" unless block_given? lock_name = field_key("#{name}_lock", id) - Redis::Lock.new(redis, lock_name, self.class.redis_objects[name]).lock(&block) + Redis::Lock.new(lock_name, redis, self.redis_objects[name]).lock(&block) end # Clear the lock. Use with care - usually only in an Admin page to clear # stale locks (a stale lock should only happen if a server crashes.) def clear_lock(name, id)