From 50cc8f0fda9eab2b48991abbeed41549f6bd8132 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Tue, 26 Sep 2023 12:57:16 -0400 Subject: [PATCH] Redis current is depericated, replace in a similar manner to other gems (#6322) * Redis current is depericated, replace in a similar manner to other gems * Don't use Redis.current for mock responses --------- Co-authored-by: Daniel Pierce --- app/services/hyrax/lock_manager.rb | 3 +-- lib/hyrax/redis_event_store.rb | 15 +++++++-------- spec/lib/hyrax/redis_event_store_spec.rb | 10 +++++----- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app/services/hyrax/lock_manager.rb b/app/services/hyrax/lock_manager.rb index 83fb734d21..2903b87294 100644 --- a/app/services/hyrax/lock_manager.rb +++ b/app/services/hyrax/lock_manager.rb @@ -47,11 +47,10 @@ def client(conn) # @api private # # @note support both a ConnectionPool and a raw Redis client for now. - # we should drop support for `Redis.current` in 5.0.0. # `#then` supports both options. for a ConnectionPool it will block # until a connection is available. def pool - Hyrax.config.redis_connection || Redis.current + Hyrax.config.redis_connection || Redis.new end end end diff --git a/lib/hyrax/redis_event_store.rb b/lib/hyrax/redis_event_store.rb index d1426dad9f..1b3a6521ab 100644 --- a/lib/hyrax/redis_event_store.rb +++ b/lib/hyrax/redis_event_store.rb @@ -25,15 +25,14 @@ def create(action, timestamp) # # @return [Redis] def instance - connection = Hyrax.config.redis_connection || Redis.current - - if connection.is_a? Redis::Namespace - connection.namespace = namespace - connection - elsif connection == Redis.current - Redis.current = Redis::Namespace.new(namespace, redis: connection) + if Hyrax.config.redis_connection&.is_a?(Redis::Namespace) + c = Hyrax.config.redis_connection + c.namespace = namespace + c + elsif Hyrax.config.redis_connection + Hyrax.config.redis_connection else - connection + Redis::Namespace.new(namespace, redis: Redis.new) end end diff --git a/spec/lib/hyrax/redis_event_store_spec.rb b/spec/lib/hyrax/redis_event_store_spec.rb index 29b5271ca0..3beffa2bc5 100644 --- a/spec/lib/hyrax/redis_event_store_spec.rb +++ b/spec/lib/hyrax/redis_event_store_spec.rb @@ -13,7 +13,7 @@ it { is_expected.to eq(1) } end context "when the Redis command fails" do - before { allow(Redis).to receive(:current).and_raise(Redis::CommandError) } + before { allow(Hyrax.config).to receive(:redis_connection).and_raise(Redis::CommandError) } context "without a logger" do before { allow(Rails).to receive(:logger).and_return(false) } it { is_expected.to be_nil } @@ -31,11 +31,11 @@ subject { described_class.new("key").fetch("size") } context "when the Redis command fails" do - before { allow(Redis).to receive(:current).and_raise(Redis::CommandError) } + before { allow(Hyrax.config).to receive(:redis_connection).and_raise(Redis::CommandError) } it { is_expected.to eq([]) } end context "when the Redis is unavailable" do - before { allow(Redis).to receive(:current).and_raise(Redis::CannotConnectError) } + before { allow(Hyrax.config).to receive(:redis_connection).and_raise(Redis::CannotConnectError) } it { is_expected.to eq([]) } end end @@ -44,11 +44,11 @@ subject { described_class.new("key").push("some value") } context "when the Redis command fails" do - before { allow(Redis).to receive(:current).and_raise(Redis::CommandError) } + before { allow(Hyrax.config).to receive(:redis_connection).and_raise(Redis::CommandError) } it { is_expected.to be_nil } end context "when the Redis is unavailable" do - before { allow(Redis).to receive(:current).and_raise(Redis::CannotConnectError) } + before { allow(Hyrax.config).to receive(:redis_connection).and_raise(Redis::CannotConnectError) } it { is_expected.to be_nil } end end