Class: RedisClient::Cluster::Node::BaseTopology
- Inherits:
-
Object
- Object
- RedisClient::Cluster::Node::BaseTopology
- Defined in:
- lib/redis_client/cluster/node/base_topology.rb
Direct Known Subclasses
LatencyReplica, PrimaryOnly, RandomReplica, RandomReplicaOrPrimary
Constant Summary collapse
- IGNORE_GENERIC_CONFIG_KEYS =
%i[url host port path].freeze
- EMPTY_HASH =
{}.freeze
- EMPTY_ARRAY =
[].freeze
Instance Attribute Summary collapse
-
#clients ⇒ Object
readonly
Returns the value of attribute clients.
-
#primary_clients ⇒ Object
readonly
Returns the value of attribute primary_clients.
-
#replica_clients ⇒ Object
readonly
Returns the value of attribute replica_clients.
Instance Method Summary collapse
- #any_primary_node_key(seed: nil) ⇒ Object
-
#initialize(pool, concurrent_worker, **kwargs) ⇒ BaseTopology
constructor
A new instance of BaseTopology.
-
#process_topology_update!(replications, options) ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(pool, concurrent_worker, **kwargs) ⇒ BaseTopology
Returns a new instance of BaseTopology.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/redis_client/cluster/node/base_topology.rb', line 13 def initialize(pool, concurrent_worker, **kwargs) @pool = pool @clients = {} @client_options = kwargs.reject { |k, _| IGNORE_GENERIC_CONFIG_KEYS.include?(k) } @concurrent_worker = concurrent_worker @replications = EMPTY_HASH @primary_node_keys = EMPTY_ARRAY @replica_node_keys = EMPTY_ARRAY @primary_clients = EMPTY_ARRAY @replica_clients = EMPTY_ARRAY end |
Instance Attribute Details
#clients ⇒ Object (readonly)
Returns the value of attribute clients.
11 12 13 |
# File 'lib/redis_client/cluster/node/base_topology.rb', line 11 def clients @clients end |
#primary_clients ⇒ Object (readonly)
Returns the value of attribute primary_clients.
11 12 13 |
# File 'lib/redis_client/cluster/node/base_topology.rb', line 11 def primary_clients @primary_clients end |
#replica_clients ⇒ Object (readonly)
Returns the value of attribute replica_clients.
11 12 13 |
# File 'lib/redis_client/cluster/node/base_topology.rb', line 11 def replica_clients @replica_clients end |
Instance Method Details
#any_primary_node_key(seed: nil) ⇒ Object
25 26 27 28 |
# File 'lib/redis_client/cluster/node/base_topology.rb', line 25 def any_primary_node_key(seed: nil) random = seed.nil? ? Random : Random.new(seed) @primary_node_keys.sample(random: random) end |
#process_topology_update!(replications, options) ⇒ Object
rubocop:disable Metrics/AbcSize
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/redis_client/cluster/node/base_topology.rb', line 30 def process_topology_update!(replications, ) # rubocop:disable Metrics/AbcSize @replications = replications.freeze @primary_node_keys = @replications.keys.sort.select { |k| .key?(k) }.freeze @replica_node_keys = @replications.values.flatten.sort.select { |k| .key?(k) }.freeze # Disconnect from nodes that we no longer want, and connect to nodes we're not connected to yet disconnect_from_unwanted_nodes() connect_to_new_nodes() @primary_clients, @replica_clients = @clients.partition { |k, _| @primary_node_keys.include?(k) }.map(&:to_h) @primary_clients.freeze @replica_clients.freeze end |