Class: RedisClient::Cluster::Node::LatencyReplica
- Inherits:
-
BaseTopology
- Object
- BaseTopology
- RedisClient::Cluster::Node::LatencyReplica
- Defined in:
- lib/redis_client/cluster/node/latency_replica.rb
Instance Attribute Summary
Attributes inherited from BaseTopology
#clients, #primary_clients, #replica_clients
Instance Method Summary collapse
- #any_replica_node_key(seed: nil) ⇒ Object
-
#clients_for_scanning(seed: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#find_node_key_of_replica(primary_node_key, seed: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
- #process_topology_update!(replications, options) ⇒ Object
Methods inherited from BaseTopology
#any_primary_node_key, #initialize
Constructor Details
This class inherits a constructor from RedisClient::Cluster::Node::BaseTopology
Instance Method Details
#any_replica_node_key(seed: nil) ⇒ Object
22 23 24 25 |
# File 'lib/redis_client/cluster/node/latency_replica.rb', line 22 def any_replica_node_key(seed: nil) random = seed.nil? ? Random : Random.new(seed) @existed_replicas.sample(random: random)&.first || any_primary_node_key(seed: seed) end |
#clients_for_scanning(seed: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
14 15 16 |
# File 'lib/redis_client/cluster/node/latency_replica.rb', line 14 def clients_for_scanning(seed: nil) # rubocop:disable Lint/UnusedMethodArgument @clients_for_scanning end |
#find_node_key_of_replica(primary_node_key, seed: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
18 19 20 |
# File 'lib/redis_client/cluster/node/latency_replica.rb', line 18 def find_node_key_of_replica(primary_node_key, seed: nil) # rubocop:disable Lint/UnusedMethodArgument @replications.fetch(primary_node_key, EMPTY_ARRAY).first || primary_node_key end |
#process_topology_update!(replications, options) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/redis_client/cluster/node/latency_replica.rb', line 27 def process_topology_update!(replications, ) super all_replica_clients = @clients.select { |k, _| @replica_node_keys.include?(k) } latencies = measure_latencies(all_replica_clients, @concurrent_worker) @replications.each_value { |keys| keys.sort_by! { |k| latencies.fetch(k) } } @replica_clients = select_replica_clients(@replications, @clients) @clients_for_scanning = select_clients_for_scanning(@replications, @clients) @existed_replicas = @replications.values.reject(&:empty?) end |