lib/asynchronic/data_store/redis.rb in asynchronic-1.4.0 vs lib/asynchronic/data_store/redis.rb in asynchronic-1.5.0
- old
+ new
@@ -6,12 +6,12 @@
LOCKED = 'locked'
include Helper
def initialize(scope, *args)
- @scope = Key.new scope
- @connection = ::Redis.new *args
+ @scope = Key[scope]
+ @connection = ::Redis.new(*args)
end
def [](key)
value = @connection.get @scope[key]
value ? Marshal.load(value) : nil
@@ -26,12 +26,17 @@
def delete(key)
@connection.del @scope[key]
end
+ def delete_cascade(key)
+ @connection.del @scope[key]
+ @connection.keys(@scope[key]['*']).each { |k| @connection.del k }
+ end
+
def keys
- @connection.keys(@scope['*']).map { |k| Key.new(k).remove_first }
+ @connection.keys(@scope['*']).map { |k| Key[k].remove_first }
end
def synchronize(key)
while @connection.getset(@scope[key][LOCKED], LOCKED) == LOCKED
sleep TIMEOUT
@@ -44,10 +49,10 @@
def connection_args
[@scope, @connection.client.options]
end
def self.connect(*args)
- new *args
+ new(*args)
end
end
end
end
\ No newline at end of file