Skip to content

Commit

Permalink
Redis current is depericated, replace in a similar manner to other ge…
Browse files Browse the repository at this point in the history
…ms (#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 <[email protected]>
  • Loading branch information
orangewolf and dlpierce authored Sep 26, 2023
1 parent 0a611e2 commit 50cc8f0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
3 changes: 1 addition & 2 deletions app/services/hyrax/lock_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 7 additions & 8 deletions lib/hyrax/redis_event_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions spec/lib/hyrax/redis_event_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 50cc8f0

Please sign in to comment.