lib/asynchronic/data_store/redis.rb in asynchronic-0.1.0 vs lib/asynchronic/data_store/redis.rb in asynchronic-0.2.0
- old
+ new
@@ -1,51 +1,40 @@
module Asynchronic
module DataStore
class Redis
- attr_reader :connection
+ include Helper
def initialize(*args)
@connection = ::Redis.new *args
end
- def get(key)
- value = connection.get root[key]
+ def [](key)
+ value = @connection.get key.to_s
value ? Marshal.load(value) : nil
+ rescue => ex
+ Asynchronic.logger.warn('Asynchronic') { ex.message }
+ value
end
- def set(key, value)
- connection.set root[key], Marshal.dump(value)
+ def []=(key, value)
+ @connection.set key.to_s, Marshal.dump(value)
end
- def merge(key, hash)
- scoped_key = Key.new key
- hash.each do |k,v|
- set scoped_key[k], v
- end
+ def delete(key)
+ @connection.del key.to_s
end
- def to_hash(key)
- children_key = "#{key}:"
- keys(children_key).inject({}) do |hash, k|
- hash[k[children_key.size..-1]] = get k
- hash
- end
+ def keys
+ @connection.keys.map { |k| Key.new k }
end
- def keys(key=nil)
- keys = key ? connection.keys("#{root[key]}*") : connection.keys
- keys.map { |k| k[(root.size + 1)..-1] }
+ def connection
+ @connection.client.options
end
- def clear(key=nil)
- keys(key).each { |k| connection.del root[k] }
- end
-
- private
-
- def root
- Key.new :asynchronic
+ def self.connect(options)
+ new options
end
end
end
end
\ No newline at end of file