Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis current is depericated, replace in a similar manner to other gems #6322

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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