lib/sfn/cache.rb in sfn-1.1.0 vs lib/sfn/cache.rb in sfn-1.1.2
- old
+ new
@@ -263,11 +263,11 @@
begin
self[lock_name].lock do
yield
end
rescue => e
- if(e.class.to_s == 'Redis::Lock::LockTimeout')
+ if(e.class.to_s.end_with?('Timeout'))
raise if raise_on_locked
else
raise
end
end
@@ -283,10 +283,13 @@
end
# Simple lock for memory cache
class LocalLock
+ class LocalLockTimeout < RuntimeError
+ end
+
# @return [Symbol] key name
attr_reader :_key
# @return [Numeric] timeout
attr_reader :_timeout
# @return [Mutex] underlying lock
@@ -318,10 +321,14 @@
yield
ensure
_lock.unlock if _lock.locked?
end
else
- raise Redis::Lock::LockTimeout.new "Timeout on lock #{_key} exceeded #{_timeout} sec"
+ if(defined?(Redis))
+ raise Redis::Lock::LockTimeout.new "Timeout on lock #{_key} exceeded #{_timeout} sec"
+ else
+ raise LocalLockTimeout.new "Timeout on lock #{_key} exceeded #{_timeout} sec"
+ end
end
end
# Clear the lock
#