Remove support for redis-namespace and old Redis

This commit is contained in:
Mike Perham 2022-05-11 12:24:22 -07:00
parent 470657b177
commit f22a1c27c7
8 changed files with 19 additions and 125 deletions

View File

@ -7,7 +7,7 @@ require "sidekiq/logger"
require "sidekiq/client"
require "sidekiq/job"
require "sidekiq/worker_compatibility_alias"
require "sidekiq/redis_connection"
require "sidekiq/redis_client_adapter"
require "json"
@ -63,7 +63,7 @@ module Sidekiq
# Configuration for Sidekiq server, use like:
#
# Sidekiq.configure_server do |config|
# config.redis = { :namespace => 'myapp', :size => 25, :url => 'redis://myhost:8877/0' }
# config.redis = { :size => 25, :url => 'redis://myhost:8877/0' }
# config.server_middleware do |chain|
# chain.add MyServerHook
# end
@ -76,7 +76,7 @@ module Sidekiq
# Configuration for Sidekiq client, use like:
#
# Sidekiq.configure_client do |config|
# config.redis = { :namespace => 'myapp', :size => 1, :url => 'redis://myhost:8877/0' }
# config.redis = { :size => 1, :url => 'redis://myhost:8877/0' }
# end
def self.configure_client
yield self unless server?
@ -110,13 +110,7 @@ module Sidekiq
def self.redis_info
redis do |conn|
# admin commands can't go through redis-namespace starting
# in redis-namespace 2.0
if conn.respond_to?(:namespace)
conn.redis.info
else
conn.info
end
conn.info
rescue RedisConnection.adapter::CommandError => ex
# 2850 return fake version when INFO command has (probably) been renamed
raise unless /unknown command/.match?(ex.message)

View File

@ -4,6 +4,7 @@ require "connection_pool"
require "redis_client"
require "redis_client/decorator"
require "uri"
require "sidekiq/redis_connection"
module Sidekiq
class RedisClientAdapter

View File

@ -1,76 +1,16 @@
# frozen_string_literal: true
require "connection_pool"
require "redis"
require "uri"
module Sidekiq
module RedisConnection
class RedisAdapter
BaseError = Redis::BaseError
CommandError = Redis::CommandError
def initialize(options)
warn("Usage of the 'redis' gem within Sidekiq itself is deprecated, Sidekiq 7.0 will only use the new, simpler 'redis-client' gem", caller) if ENV["SIDEKIQ_REDIS_CLIENT"] == "1"
@options = options
end
def new_client
namespace = @options[:namespace]
client = Redis.new client_opts(@options)
if namespace
begin
require "redis/namespace"
Redis::Namespace.new(namespace, redis: client)
rescue LoadError
Sidekiq.logger.error("Your Redis configuration uses the namespace '#{namespace}' but the redis-namespace gem is not included in the Gemfile." \
"Add the gem to your Gemfile to continue using a namespace. Otherwise, remove the namespace parameter.")
exit(-127)
end
else
client
end
end
private
def client_opts(options)
opts = options.dup
if opts[:namespace]
opts.delete(:namespace)
end
if opts[:network_timeout]
opts[:timeout] = opts[:network_timeout]
opts.delete(:network_timeout)
end
opts[:driver] ||= Redis::Connection.drivers.last || "ruby"
# Issue #3303, redis-rb will silently retry an operation.
# This can lead to duplicate jobs if Sidekiq::Client's LPUSH
# is performed twice but I believe this is much, much rarer
# than the reconnect silently fixing a problem; we keep it
# on by default.
opts[:reconnect_attempts] ||= 1
opts
end
end
@adapter = RedisAdapter
class << self
attr_reader :adapter
# RedisConnection.adapter = :redis
# RedisConnection.adapter = :redis_client
def adapter=(adapter)
raise "no" if adapter == self
result = case adapter
when :redis
RedisAdapter
when Class
adapter
else

View File

@ -158,10 +158,6 @@ module Sidekiq
end
end
def namespace
@ns ||= Sidekiq.redis { |conn| conn.respond_to?(:namespace) ? conn.namespace : nil }
end
def redis_info
Sidekiq.redis_info
end
@ -314,13 +310,6 @@ module Sidekiq
Time.now.utc.strftime("%H:%M:%S UTC")
end
def redis_connection_and_namespace
@redis_connection_and_namespace ||= begin
namespace_suffix = namespace.nil? ? "" : "##{namespace}"
"#{redis_connection}#{namespace_suffix}"
end
end
def retry_or_delete_or_kill(job, params)
if params["retry"]
job.retry

View File

@ -140,33 +140,15 @@ describe Sidekiq::RedisConnection do
end
describe "namespace" do
if redis_client?
it "isn't supported" do
Kernel.stub(:exit, ->(code) { raise "Exited #{code}" }) do
output = capture_logging do
error = assert_raises RuntimeError do
Sidekiq::RedisConnection.create(namespace: "xxx")
end
assert_includes error.message, "Exited -127"
it "isn't supported" do
Kernel.stub(:exit, ->(code) { raise "Exited #{code}" }) do
output = capture_logging do
error = assert_raises RuntimeError do
Sidekiq::RedisConnection.create(namespace: "xxx")
end
assert_includes output, "Your Redis configuration uses the namespace 'xxx' but this feature isn't supported by redis-client"
assert_includes error.message, "Exited -127"
end
end
else
it "uses a given :namespace set by a symbol key" do
pool = Sidekiq::RedisConnection.create(namespace: "xxx")
assert_equal "xxx", pool.checkout.namespace
end
it "uses a given :namespace set by a string key" do
pool = Sidekiq::RedisConnection.create("namespace" => "xxx")
assert_equal "xxx", pool.checkout.namespace
end
it "uses given :namespace over :namespace from Sidekiq.options" do
Sidekiq.options[:namespace] = "xxx"
pool = Sidekiq::RedisConnection.create(namespace: "yyy")
assert_equal "yyy", pool.checkout.namespace
assert_includes output, "Your Redis configuration uses the namespace 'xxx' but this feature isn't supported by redis-client"
end
end
end

View File

@ -69,9 +69,9 @@ describe Sidekiq do
describe "redis connection" do
it "does not continually retry" do
assert_raises Redis::CommandError do
assert_raises Sidekiq::RedisConnection.adapter::CommandError do
Sidekiq.redis do |c|
raise Redis::CommandError, "READONLY You can't write against a replica."
raise Sidekiq::RedisConnection.adapter::CommandError, "READONLY You can't write against a replica."
end
end
end

View File

@ -882,37 +882,25 @@ div.interval-slider input {
}
}
.redis-url, .redis-namespace {
.redis-url {
overflow: hidden;
white-space: nowrap;
}
@media (min-width: 768px) {
.redis-url {
max-width: 200px;
}
.redis-namespace {
max-width: 150px;
max-width: 250px;
}
}
@media (min-width: 992px) {
.redis-url {
max-width: 390px;
}
.redis-namespace {
max-width: 300px;
max-width: 490px;
}
}
@media (min-width: 1200px) {
.redis-url {
max-width: 480px;
}
.redis-namespace {
max-width: 350px;
max-width: 600px;
}
}

View File

@ -6,7 +6,7 @@
<p class="navbar-text product-version"><%= product_version %></p>
</li>
<li>
<p class="navbar-text redis-url" title="<%= redis_connection_and_namespace %>"><%= redis_connection_and_namespace %></p>
<p class="navbar-text redis-url" title="<%= redis_connection %>"><%= redis_connection %></p>
</li>
<li>
<p id="serverUtcTime" class="navbar-text server-utc-time"><%= server_utc_time %></p>