Class: RedisClient::Cluster::Node::RandomReplica
- Inherits:
-
Object
- Object
- RedisClient::Cluster::Node::RandomReplica
show all
- Includes:
- ReplicaMixin
- Defined in:
- lib/redis_client/cluster/node/random_replica.rb
Constant Summary
RedisClient::Cluster::Node::ReplicaMixin::EMPTY_ARRAY
Instance Attribute Summary
Attributes included from ReplicaMixin
#clients, #primary_clients
Instance Method Summary
collapse
#any_primary_node_key, #initialize
Instance Method Details
#any_replica_node_key(seed: nil) ⇒ Object
30
31
32
33
|
# File 'lib/redis_client/cluster/node/random_replica.rb', line 30
def any_replica_node_key(seed: nil)
random = seed.nil? ? Random : Random.new(seed)
@replica_node_keys.sample(random: random) || any_primary_node_key(seed: seed)
end
|
#clients_for_scanning(seed: nil) ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/redis_client/cluster/node/random_replica.rb', line 16
def clients_for_scanning(seed: nil)
random = seed.nil? ? Random : Random.new(seed)
keys = @replications.map do |primary_node_key, replica_node_keys|
replica_node_keys.empty? ? primary_node_key : replica_node_keys.sample(random: random)
end
clients.select { |k, _| keys.include?(k) }
end
|
#find_node_key_of_replica(primary_node_key, seed: nil) ⇒ Object
25
26
27
28
|
# File 'lib/redis_client/cluster/node/random_replica.rb', line 25
def find_node_key_of_replica(primary_node_key, seed: nil)
random = seed.nil? ? Random : Random.new(seed)
@replications.fetch(primary_node_key, EMPTY_ARRAY).sample(random: random) || primary_node_key
end
|
#replica_clients ⇒ Object
11
12
13
14
|
# File 'lib/redis_client/cluster/node/random_replica.rb', line 11
def replica_clients
keys = @replications.values.filter_map(&:sample)
@clients.select { |k, _| keys.include?(k) }
end
|