DEV: Add `REDIS_RAILS_FAILOVER` env to test our new redis failover.

DEV: Add REDIS_RAILS_FAILOVER env to test our new redis failover.

diff --git a/Gemfile.lock b/Gemfile.lock
index 53a0a69..92e1f2a 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,6 +1,6 @@
 GIT
   remote: https://github.com/discourse/rails_failover
-  revision: 291bf1c18e9a704556a40204d8160549d0438e96
+  revision: 73ceb21624079e007a7d3bf0bf201f0b34dcd6aa
   specs:
     rails_failover (0.4.0)
       activerecord (~> 6.0)
diff --git a/app/models/global_setting.rb b/app/models/global_setting.rb
index a31df60..cd80df6 100644
--- a/app/models/global_setting.rb
+++ b/app/models/global_setting.rb
@@ -169,9 +169,15 @@ class GlobalSetting
         c[:port] = redis_port if redis_port
 
         if redis_slave_host && redis_slave_port
-          c[:slave_host] = redis_slave_host
-          c[:slave_port] = redis_slave_port
-          c[:connector] = DiscourseRedis::Connector
+          if ENV["REDIS_RAILS_FAILOVER"]
+            c[:replica_host] = redis_slave_host
+            c[:replica_port] = redis_slave_port
+            c[:connector] = RailsFailover::Redis::Connector
+          else
+            c[:slave_host] = redis_slave_host
+            c[:slave_port] = redis_slave_port
+            c[:connector] = DiscourseRedis::Connector
+          end
         end
 
         c[:password] = redis_password if redis_password.present?
@@ -193,9 +199,15 @@ class GlobalSetting
         c[:port] = message_bus_redis_port if message_bus_redis_port
 
         if message_bus_redis_slave_host && message_bus_redis_slave_port
-          c[:slave_host] = message_bus_redis_slave_host
-          c[:slave_port] = message_bus_redis_slave_port
-          c[:connector] = DiscourseRedis::Connector
+          if ENV["REDIS_RAILS_FAILOVER"]
+            c[:replica_host] = redis_slave_host
+            c[:replica_port] = redis_slave_port
+            c[:connector] = RailsFailover::Redis::Connector
+          else
+            c[:slave_host] = message_bus_redis_slave_host
+            c[:slave_port] = message_bus_redis_slave_port
+            c[:connector] = DiscourseRedis::Connector
+          end
         end
 
         c[:password] = message_bus_redis_password if message_bus_redis_password.present?
diff --git a/config/application.rb b/config/application.rb
index f2cbb14..07730bc 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -31,6 +31,10 @@ if ENV['ACTIVE_RECORD_RAILS_FAILOVER']
   require 'rails_failover/active_record'
 end
 
+if ENV['REDIS_RAILS_FAILOVER']
+  require 'rails_failover/redis'
+end
+
 # Global config
 require_relative '../app/models/global_setting'
 GlobalSetting.configure!
diff --git a/config/initializers/002-rails_failover.rb b/config/initializers/002-rails_failover.rb
index 0418654..5b65d57 100644
--- a/config/initializers/002-rails_failover.rb
+++ b/config/initializers/002-rails_failover.rb
@@ -1,5 +1,16 @@
 # frozen_string_literal: true
 
+if ENV["REDIS_RAILS_FAILOVER"]
+  RailsFailover::Redis.on_failover do
+    Discourse.received_redis_readonly!
+  end
+
+  RailsFailover::Redis.on_fallback do
+    Discourse.clear_readonly!
+    Discourse.request_refresh!
+  end
+end
+
 if ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
   RailsFailover::ActiveRecord.on_failover do
     RailsMultisite::ConnectionManagement.each_connection do
diff --git a/lib/discourse_redis.rb b/lib/discourse_redis.rb
index e273810..b172c02 100644
--- a/lib/discourse_redis.rb
+++ b/lib/discourse_redis.rb
@@ -176,7 +176,10 @@ class DiscourseRedis
         STDERR.puts "WARN: Redis is in a readonly state. Performed a noop"
       end
 
-      fallback_handler.verify_master if !fallback_handler.master
+      if !ENV["REDIS_RAILS_FAILOVER"]
+        fallback_handler.verify_master if !fallback_handler.master
+      end
+
       Discourse.received_redis_readonly!
       nil
     else

GitHub sha: 439db7ca