Class: Async::Redis::SentinelClient
- Inherits:
-
Object
- Object
- Async::Redis::SentinelClient
- Includes:
- Client::Methods, Protocol::Redis::Methods
- Defined in:
- lib/async/redis/sentinel_client.rb
Overview
A Redis Sentinel client for high availability Redis deployments.
Constant Summary collapse
- DEFAULT_MASTER_NAME =
"mymaster"
Instance Attribute Summary collapse
-
#master_name ⇒ Object
readonly
Returns the value of attribute master_name.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
- #The name of the master instance.(nameofthemasterinstance.) ⇒ Object readonly
Instance Method Summary collapse
-
#close ⇒ Object
Close the sentinel client and all connections.
-
#failover(name = @master_name) ⇒ Object
Initiate a failover for the specified master.
-
#initialize(endpoints, master_name: DEFAULT_MASTER_NAME, master_options: nil, slave_options: nil, role: :master, **options) ⇒ SentinelClient
constructor
Create a new instance of the SentinelClient.
-
#master(name = @master_name) ⇒ Object
Get information about a specific master.
-
#masters ⇒ Object
Get information about all masters.
-
#resolve_address(role = @role) ⇒ Object
Resolve an address for the specified role.
- #The role of the instance that you want to connect to.=(roleoftheinstancethatyouwanttoconnectto. = (value)) ⇒ Object
Methods included from Client::Methods
#call, #pipeline, #psubscribe, #ssubscribe, #subscribe, #transaction
Constructor Details
#initialize(endpoints, master_name: DEFAULT_MASTER_NAME, master_options: nil, slave_options: nil, role: :master, **options) ⇒ SentinelClient
Create a new instance of the SentinelClient.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/async/redis/sentinel_client.rb', line 27 def initialize(endpoints, master_name: DEFAULT_MASTER_NAME, master_options: nil, slave_options: nil, role: :master, **) @endpoints = endpoints @master_name = master_name @master_options = || {} @slave_options = || @master_options @role = role # A cache of sentinel connections. @sentinels = {} @pool = make_pool(**) end |
Instance Attribute Details
#master_name ⇒ Object (readonly)
Returns the value of attribute master_name.
41 42 43 |
# File 'lib/async/redis/sentinel_client.rb', line 41 def master_name @master_name end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
44 45 46 |
# File 'lib/async/redis/sentinel_client.rb', line 44 def role @role end |
#The name of the master instance.(nameofthemasterinstance.) ⇒ Object (readonly)
41 |
# File 'lib/async/redis/sentinel_client.rb', line 41 attr :master_name |
Instance Method Details
#close ⇒ Object
Close the sentinel client and all connections.
65 66 67 68 69 70 71 |
# File 'lib/async/redis/sentinel_client.rb', line 65 def close super @sentinels.each do |_, client| client.close end end |
#failover(name = @master_name) ⇒ Object
Initiate a failover for the specified master.
76 77 78 79 80 |
# File 'lib/async/redis/sentinel_client.rb', line 76 def failover(name = @master_name) sentinels do |client| return client.call("SENTINEL", "FAILOVER", name) end end |
#master(name = @master_name) ⇒ Object
Get information about a specific master.
93 94 95 96 97 |
# File 'lib/async/redis/sentinel_client.rb', line 93 def master(name = @master_name) sentinels do |client| return client.call("SENTINEL", "MASTER", name).each_slice(2).to_h end end |
#masters ⇒ Object
Get information about all masters.
84 85 86 87 88 |
# File 'lib/async/redis/sentinel_client.rb', line 84 def masters sentinels do |client| return client.call("SENTINEL", "MASTERS").map{|fields| fields.each_slice(2).to_h} end end |
#resolve_address(role = @role) ⇒ Object
Resolve an address for the specified role.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/async/redis/sentinel_client.rb', line 49 def resolve_address(role = @role) case role when :master resolve_master when :slave resolve_slave else raise ArgumentError, "Unknown instance role #{role}" end => address Console.debug(self, "Resolved #{@role} address: #{address}") address or raise RuntimeError, "Unable to fetch #{role} via Sentinel." end |
#The role of the instance that you want to connect to.=(roleoftheinstancethatyouwanttoconnectto. = (value)) ⇒ Object
44 |
# File 'lib/async/redis/sentinel_client.rb', line 44 attr :role |