Class: RedisCluster::Pool
- Inherits:
-
Object
- Object
- RedisCluster::Pool
- Defined in:
- lib/redis_cluster/pool.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
-
#add_node!(node_options, slots) ⇒ Object
TODO: type check.
- #delete_except!(master_hosts) ⇒ Object
-
#execute(method, args, other_options) ⇒ Object
other_options: asking random_node.
-
#initialize ⇒ Pool
constructor
A new instance of Pool.
- #keys(glob = "*") ⇒ Object
Constructor Details
#initialize ⇒ Pool
Returns a new instance of Pool.
6 7 8 |
# File 'lib/redis_cluster/pool.rb', line 6 def initialize @nodes = [] end |
Instance Attribute Details
#nodes ⇒ Object (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!(, slots) new_node = Node.new() 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 34 35 |
# File 'lib/redis_cluster/pool.rb', line 26 def execute(method, args, ) return keys(args.first) if Configuration::SUPPORT_MULTI_NODE_METHODS.include?(method.to_s) key = key_by_command(method, args) raise NotSupportError if key.nil? node = [:random_node] ? random_node : node_by(key) node.asking if [:asking] node.execute(method, args) end |
#keys(glob = "*") ⇒ Object
37 38 39 |
# File 'lib/redis_cluster/pool.rb', line 37 def keys(glob = "*") on_each_node(:keys, glob).flatten end |