diff --git a/lib/progressrus/store/redis.rb b/lib/progressrus/store/redis.rb index 0bc2291..ad618f1 100644 --- a/lib/progressrus/store/redis.rb +++ b/lib/progressrus/store/redis.rb @@ -17,9 +17,11 @@ def persist(progress, now: Time.now, force: false, expires_at: nil) if outdated?(progress) || force key_for_scope = key(progress.scope) - redis.pipelined do |pipeline| - pipeline.hset(key_for_scope, progress.id, progress.to_serializeable.to_json) - pipeline.expireat(key_for_scope, expires_at.to_i) if expires_at + redis.with do |client| + client.pipelined do |pipeline| + pipeline.hset(key_for_scope, progress.id, progress.to_serializeable.to_json) + pipeline.expireat(key_for_scope, expires_at.to_i) if expires_at + end end @persisted_ats[progress.scope][progress.id] = now @@ -29,7 +31,9 @@ def persist(progress, now: Time.now, force: false, expires_at: nil) end def scope(scope) - scope = redis.hgetall(key(scope)) + scope = redis.with do |client| + client.hgetall(key(scope)) + end scope.each_pair { |id, value| scope[id] = Progressrus.new(**deserialize(value)) } @@ -38,7 +42,7 @@ def scope(scope) end def find(scope, id) - value = redis.hget(key(scope), id) + value = redis.with { |client| client.hget(key(scope), id) } return unless value Progressrus.new(**deserialize(value)) @@ -47,10 +51,12 @@ def find(scope, id) end def flush(scope, id = nil) - if id - redis.hdel(key(scope), id) - else - redis.del(key(scope)) + redis.with do |client| + if id + client.hdel(key(scope), id) + else + client.del(key(scope)) + end end rescue *BACKEND_EXCEPTIONS => e raise Progressrus::Store::BackendError.new(e) diff --git a/progressrus.gemspec b/progressrus.gemspec index 2bf5fd4..451467b 100644 --- a/progressrus.gemspec +++ b/progressrus.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.add_dependency "redis", ">= 3.0" + spec.add_dependency "redis", ">= 4.7.0" spec.add_dependency "ruby-progressbar", "~> 1.0" spec.add_development_dependency "rake"