Class: RailsFailover::Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_failover/redis.rb,
lib/rails_failover/redis/handler.rb,
lib/rails_failover/redis/connector.rb

Defined Under Namespace

Classes: Connector, Handler

Constant Summary collapse

PRIMARY =
:primary
REPLICA =
:replica

Class Method Summary collapse

Class Method Details

.clear_callbacksObject

For testing



64
65
66
67
# File 'lib/rails_failover/redis.rb', line 64

def self.clear_callbacks
  @on_fallback_callback = nil
  @on_failover_callback = nil
end

.loggerObject



23
24
25
26
27
28
29
# File 'lib/rails_failover/redis.rb', line 23

def self.logger
  if @logger
    @logger
  elsif defined?(::Rails)
    ::Rails.logger
  end
end

.logger=(logger) ⇒ Object



19
20
21
# File 'lib/rails_failover/redis.rb', line 19

def self.logger=(logger)
  @logger = logger
end

.on_failover(&block) ⇒ Object



39
40
41
# File 'lib/rails_failover/redis.rb', line 39

def self.on_failover(&block)
  @on_failover_callback = block
end

.on_failover_callback!(key) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/rails_failover/redis.rb', line 43

def self.on_failover_callback!(key)
  @on_failover_callback&.call(key)
rescue => e
  logger.warn(
    "RailsFailover::Redis.on_failover failed: #{e.class} #{e.message}\n#{e.backtrace.join("\n")}",
  )
end

.on_fallback(&block) ⇒ Object



51
52
53
# File 'lib/rails_failover/redis.rb', line 51

def self.on_fallback(&block)
  @on_fallback_callback = block
end

.on_fallback_callback!(key) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/rails_failover/redis.rb', line 55

def self.on_fallback_callback!(key)
  @on_fallback_callback&.call(key)
rescue => e
  logger.warn(
    "RailsFailover::Redis.on_fallback failed: #{e.class} #{e.message}\n#{e.backtrace.join("\n")}",
  )
end

.verify_primary_frequency_secondsObject



35
36
37
# File 'lib/rails_failover/redis.rb', line 35

def self.verify_primary_frequency_seconds
  @verify_primary_frequency_seconds || 5
end

.verify_primary_frequency_seconds=(seconds) ⇒ Object



31
32
33
# File 'lib/rails_failover/redis.rb', line 31

def self.verify_primary_frequency_seconds=(seconds)
  @verify_primary_frequency_seconds = seconds
end