lib/redis/lock.rb in redis-objects-0.3.2 vs lib/redis/lock.rb in redis-objects-0.4.0
- old
+ new
@@ -1,21 +1,21 @@
+require File.dirname(__FILE__) + '/base_object'
+
class Redis
#
# Class representing a lock. This functions like a proxy class, in
# that you can say @object.lock_name { block } to use the lock and also
# @object.counter_name.clear to reset on it. You can use this
# directly, but it is better to use the lock :foo class method in your
# class to define a lock.
#
- class Lock
+ class Lock < BaseObject
class LockTimeout < StandardError; end #:nodoc:
attr_reader :key, :options, :redis
def initialize(key, *args)
- @key = key
- @options = args.last.is_a?(Hash) ? args.pop : {}
- @redis = args.first || $redis
+ super(key, *args)
@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
@@ -79,6 +79,6 @@
def generate_expiration
@options[:expiration].nil? ? 1 : (Time.now + @options[:expiration].to_f + 1).to_f
end
end
-end
\ No newline at end of file
+end