From 81c472e5d61795397f7b0828b88dd7b5f7764e8e Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Sun, 17 Sep 2023 08:33:25 -0700 Subject: [PATCH 1/2] Redis current is depericated, replace in a similar manner to other gems --- app/services/hyrax/lock_manager.rb | 3 +-- lib/hyrax/redis_event_store.rb | 15 +++++++-------- 2 files changed, 8 insertions(+), 10 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 From 0e5df76edb973d9016fc283cfc94ff246fe4c358 Mon Sep 17 00:00:00 2001 From: Daniel Pierce Date: Wed, 20 Sep 2023 11:39:39 -0400 Subject: [PATCH 2/2] Don't use Redis.current for mock responses --- spec/lib/hyrax/redis_event_store_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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