Class: Renoir::ClusterInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/renoir/cluster_info.rb

Overview

Store cluster information.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClusterInfo

Returns a new instance of ClusterInfo.



10
11
12
13
# File 'lib/renoir/cluster_info.rb', line 10

def initialize
  @slots = {}
  @nodes = {}
end

Class Method Details

.node_name(host, port) ⇒ Object



5
6
7
# File 'lib/renoir/cluster_info.rb', line 5

def node_name(host, port)
  "#{host}:#{port}"
end

Instance Method Details

#add_node(host, port) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/renoir/cluster_info.rb', line 37

def add_node(host, port)
  name = self.class.node_name(host, port)
  @nodes[name] = {
    host: host,
    port: port,
    name: name,
  }
end

#load_slots(slots) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/renoir/cluster_info.rb', line 15

def load_slots(slots)
  slots.each do |s, e, master, *slaves|
    ip, port, = master
    node = add_node(ip, port)
    (s..e).each do |slot|
      @slots[slot] = node[:name]
    end
  end
end

#node_namesObject



29
30
31
# File 'lib/renoir/cluster_info.rb', line 29

def node_names
  @nodes.keys
end

#nodesObject



33
34
35
# File 'lib/renoir/cluster_info.rb', line 33

def nodes
  @nodes.values
end

#slot_node(slot) ⇒ Object



25
26
27
# File 'lib/renoir/cluster_info.rb', line 25

def slot_node(slot)
  @nodes[@slots[slot]]
end