Class: Redis::Cluster::Node
- Inherits:
-
Object
- Object
- Redis::Cluster::Node
- Includes:
- Enumerable
- Defined in:
- lib/redis/cluster/node.rb
Overview
Keep client list of node for Redis Cluster Client
Constant Summary collapse
- ReloadNeeded =
Class.new(StandardError)
- ROLE_SLAVE =
'slave'
Instance Method Summary collapse
- #call_all(command, &block) ⇒ Object
- #call_master(command, &block) ⇒ Object
- #call_slave(command, &block) ⇒ Object
- #each(&block) ⇒ Object
- #find_by(node_key) ⇒ Object
-
#initialize(options, node_flags = {}, with_replica = false) ⇒ Node
constructor
A new instance of Node.
- #process_all(commands, &block) ⇒ Object
- #sample ⇒ Object
Constructor Details
#initialize(options, node_flags = {}, with_replica = false) ⇒ Node
Returns a new instance of Node.
15 16 17 18 19 |
# File 'lib/redis/cluster/node.rb', line 15 def initialize(, node_flags = {}, with_replica = false) @with_replica = with_replica @node_flags = node_flags @clients = build_clients() end |
Instance Method Details
#call_all(command, &block) ⇒ Object
35 36 37 |
# File 'lib/redis/cluster/node.rb', line 35 def call_all(command, &block) try_map { |_, client| client.call(command, &block) }.values end |
#call_master(command, &block) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/redis/cluster/node.rb', line 39 def call_master(command, &block) try_map do |node_key, client| next if slave?(node_key) client.call(command, &block) end.values end |
#call_slave(command, &block) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/redis/cluster/node.rb', line 46 def call_slave(command, &block) return call_master(command, &block) if replica_disabled? try_map do |node_key, client| next if master?(node_key) client.call(command, &block) end.values end |
#each(&block) ⇒ Object
21 22 23 |
# File 'lib/redis/cluster/node.rb', line 21 def each(&block) @clients.values.each(&block) end |
#find_by(node_key) ⇒ Object
29 30 31 32 33 |
# File 'lib/redis/cluster/node.rb', line 29 def find_by(node_key) @clients.fetch(node_key) rescue KeyError raise ReloadNeeded end |
#process_all(commands, &block) ⇒ Object
55 56 57 |
# File 'lib/redis/cluster/node.rb', line 55 def process_all(commands, &block) try_map { |_, client| client.process(commands, &block) }.values end |
#sample ⇒ Object
25 26 27 |
# File 'lib/redis/cluster/node.rb', line 25 def sample @clients.values.sample end |