lib/progressrus/store/redis.rb in progressrus-0.0.2 vs lib/progressrus/store/redis.rb in progressrus-0.0.3

- old
+ new

@@ -1,8 +1,10 @@ class Progressrus class Store class Redis < Base + BACKEND_EXCEPTIONS = [ ::Redis::BaseError ] + attr_reader :redis, :interval, :persisted_at, :prefix, :name def initialize(instance, prefix: "progressrus", interval: 1, now: Time.now) @name = :redis @redis = instance @@ -14,34 +16,43 @@ def persist(progress, now: Time.now, force: false) if outdated?(progress) || force redis.hset(key(progress.scope), progress.id, progress.to_serializeable.to_json) @persisted_ats[progress.scope][progress.id] = now end + rescue *BACKEND_EXCEPTIONS => e + raise Progressrus::Store::BackendError.new(e) end def scope(scope) scope = redis.hgetall(key(scope)) scope.each_pair { |id, value| scope[id] = Progressrus.new(deserialize(value)) } + rescue *BACKEND_EXCEPTIONS => e + raise Progressrus::Store::BackendError.new(e) end def find(scope, id) value = redis.hget(key(scope), id) return unless value Progressrus.new(deserialize(value)) + rescue *BACKEND_EXCEPTIONS => e + raise Progressrus::Store::BackendError.new(e) end def flush(scope, id = nil) if id redis.hdel(key(scope), id) else redis.del(key(scope)) end + rescue *BACKEND_EXCEPTIONS => e + raise Progressrus::Store::BackendError.new(e) end private + def key(scope) "#{prefix}:#{scope.join(":")}" end def deserialize(value)