FIX: use Redis replica host and port (#11543)

* FIX: use Redis replica host and port

Introduce Redis `replica` config and deprecate `slave`

* FIX: move deprecations to separate file
This commit is contained in:
Krzysztof Kotlarek 2020-12-22 15:52:00 +11:00 committed by GitHub
parent d10d296e92
commit b0e1210b0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 17 deletions

View File

@ -163,6 +163,26 @@ class GlobalSetting
@message_bus_config = nil
end
def self.get_redis_replica_host
return redis_replica_host if redis_replica_host.present?
redis_slave_host if respond_to?(:redis_slave_host) && redis_slave_host.present?
end
def self.get_redis_replica_port
return redis_replica_port if redis_replica_port.present?
redis_slave_port if respond_to?(:redis_slave_port) && redis_slave_port.present?
end
def self.get_message_bus_redis_replica_host
return message_bus_redis_replica_host if message_bus_redis_replica_host.present?
message_bus_redis_slave_host if respond_to?(:message_bus_redis_slave_host) && message_bus_redis_slave_host.present?
end
def self.get_message_bus_redis_replica_port
return message_bus_redis_replica_port if message_bus_redis_replica_port.present?
message_bus_redis_slave_port if respond_to?(:message_bus_redis_slave_port) && message_bus_redis_slave_port.present?
end
def self.redis_config
@config ||=
begin
@ -170,9 +190,9 @@ class GlobalSetting
c[:host] = redis_host if redis_host
c[:port] = redis_port if redis_port
if redis_slave_host && redis_slave_port && defined?(RailsFailover)
c[:replica_host] = redis_slave_host
c[:replica_port] = redis_slave_port
if get_redis_replica_host && get_redis_replica_port && defined?(RailsFailover)
c[:replica_host] = get_redis_replica_host
c[:replica_port] = get_redis_replica_port
c[:connector] = RailsFailover::Redis::Connector
end
@ -194,9 +214,9 @@ class GlobalSetting
c[:host] = message_bus_redis_host if message_bus_redis_host
c[:port] = message_bus_redis_port if message_bus_redis_port
if message_bus_redis_slave_host && message_bus_redis_slave_port
c[:replica_host] = message_bus_redis_slave_host
c[:replica_port] = message_bus_redis_slave_port
if get_message_bus_redis_replica_host && get_message_bus_redis_replica_port
c[:replica_host] = get_message_bus_redis_replica_host
c[:replica_port] = get_message_bus_redis_replica_port
c[:connector] = RailsFailover::Redis::Connector
end

View File

@ -124,11 +124,11 @@ redis_host = localhost
# redis server port
redis_port = 6379
# redis slave server address
redis_slave_host =
# redis replica server address
redis_replica_host =
# redis slave server port
redis_slave_port = 6379
# redis replica server port
redis_replica_port = 6379
# redis database
redis_db = 0
@ -151,11 +151,11 @@ message_bus_redis_host = localhost
# message bus redis server port
message_bus_redis_port = 6379
# message bus redis slave server address
message_bus_redis_slave_host =
# message bus redis replica server address
message_bus_redis_replica_host =
# message bus redis slave server port
message_bus_redis_slave_port = 6379
message_bus_redis_replica_port = 6379
# message bus redis database
message_bus_redis_db = 0

View File

@ -0,0 +1,17 @@
# frozen_string_literal: true
if GlobalSetting.respond_to?(:redis_slave_host) && GlobalSetting.redis_slave_host.present?
Discourse.deprecate("redis_slave_host is deprecated, use redis_replica_host instead", drop_from: "2.8")
end
if GlobalSetting.respond_to?(:redis_slave_port) && GlobalSetting.redis_slave_port.present?
Discourse.deprecate("redis_slave_port is deprecated, use redis_replica_port instead", drop_from: "2.8")
end
if GlobalSetting.respond_to?(:message_bus_redis_slave_host) && GlobalSetting.message_bus_redis_slave_host.present?
Discourse.deprecate("message_bus_redis_slave_host is deprecated, use message_bus_redis_replica_host", drop_from: "2.8")
end
if GlobalSetting.respond_to?(:message_bus_redis_slave_port) && GlobalSetting.message_bus_redis_slave_port.present?
Discourse.deprecate("message_bus_redis_slave_port is deprecated, use message_bus_redis_replica_port", drop_from: "2.8")
end

View File

@ -67,13 +67,13 @@ describe GlobalSetting do
end
describe '.redis_config' do
describe 'when slave config is not present' do
describe 'when replica config is not present' do
it "should not set any connector" do
expect(GlobalSetting.redis_config[:connector]).to eq(nil)
end
end
describe 'when slave config is present' do
describe 'when replica config is present' do
before do
GlobalSetting.reset_redis_config!
end
@ -83,8 +83,8 @@ describe GlobalSetting do
end
it "should set the right connector" do
GlobalSetting.expects(:redis_slave_port).returns(6379).at_least_once
GlobalSetting.expects(:redis_slave_host).returns('0.0.0.0').at_least_once
GlobalSetting.expects(:redis_replica_port).returns(6379).at_least_once
GlobalSetting.expects(:redis_replica_host).returns('0.0.0.0').at_least_once
expect(GlobalSetting.redis_config[:connector]).to eq(RailsFailover::Redis::Connector)
end