Class: RedisCluster::Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_cluster/pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePool

Returns a new instance of Pool.



6
7
8
# File 'lib/redis_cluster/pool.rb', line 6

def initialize
  @nodes = []
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



4
5
6
# File 'lib/redis_cluster/pool.rb', line 4

def nodes
  @nodes
end

Instance Method Details

#add_node!(node_options, slots) ⇒ Object

TODO: type check



11
12
13
14
15
16
# File 'lib/redis_cluster/pool.rb', line 11

def add_node!(node_options, slots)
  new_node = Node.new(node_options)
  node = @nodes.find {|n| n.name == new_node.name } || new_node
  node.slots = slots
  @nodes.push(node).uniq!
end

#delete_except!(master_hosts) ⇒ Object



18
19
20
21
# File 'lib/redis_cluster/pool.rb', line 18

def delete_except!(master_hosts)
  names = master_hosts.map {|host, port| "#{host}:#{port}" }
  @nodes.delete_if {|n| !names.include?(n.name) }
end

#execute(method, args, other_options) ⇒ Object

other_options:

asking
random_node


26
27
28
29
30
31
32
33
# File 'lib/redis_cluster/pool.rb', line 26

def execute(method, args, other_options)
  key = key_by_command(method, args)
  raise "not usable" if key.nil?

  node = other_options[:random_node] ? random_node : node_by(key)
  node.asking if other_options[:asking]
  node.execute(method, args)
end