mirror of
https://github.com/fluencelabs/redis
synced 2025-03-30 22:31:03 +00:00
initial node loading info code for redis-trib
This commit is contained in:
parent
1ef8b0a96d
commit
d3f7fbfc09
@ -22,6 +22,8 @@ class ClusterNode
|
|||||||
@port = s[1]
|
@port = s[1]
|
||||||
@slots = {}
|
@slots = {}
|
||||||
@dirty = false
|
@dirty = false
|
||||||
|
@info = nil
|
||||||
|
@friends = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
@ -29,6 +31,7 @@ class ClusterNode
|
|||||||
end
|
end
|
||||||
|
|
||||||
def connect(o={})
|
def connect(o={})
|
||||||
|
return if @r
|
||||||
xputs "Connecting to node #{self}: "
|
xputs "Connecting to node #{self}: "
|
||||||
begin
|
begin
|
||||||
@r = Redis.new(:host => @host, :port => @port)
|
@r = Redis.new(:host => @host, :port => @port)
|
||||||
@ -58,6 +61,39 @@ class ClusterNode
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_info(o={})
|
||||||
|
self.connect
|
||||||
|
nodes = @r.cluster("nodes").split("\n")
|
||||||
|
nodes.each{|n|
|
||||||
|
# name addr flags role ping_sent ping_recv link_status slots
|
||||||
|
name,addr,flags,role,ping_sent,ping_recv,link_status,slots = n.split(" ")
|
||||||
|
info = {
|
||||||
|
:name => name,
|
||||||
|
:addr => addr,
|
||||||
|
:flags => flags.split(","),
|
||||||
|
:role => role,
|
||||||
|
:ping_sent => ping_sent.to_i,
|
||||||
|
:ping_recv => ping_recv.to_i,
|
||||||
|
:link_status => link_status
|
||||||
|
}
|
||||||
|
if info[:flags].index("myself")
|
||||||
|
@info = info
|
||||||
|
@slots = {}
|
||||||
|
slots.split(",").each{|s|
|
||||||
|
if s.index("-")
|
||||||
|
start,stop = s.split("-")
|
||||||
|
self.add_slots((start.to_i)..(stop.to_i))
|
||||||
|
else
|
||||||
|
self.add_slots((s.to_i)..(s.to_i))
|
||||||
|
end
|
||||||
|
}
|
||||||
|
@dirty = false
|
||||||
|
elsif o[:getfriends]
|
||||||
|
@friends << info
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def add_slots(slots)
|
def add_slots(slots)
|
||||||
slots.each{|s|
|
slots.each{|s|
|
||||||
@slots[s] = :new
|
@slots[s] = :new
|
||||||
@ -205,6 +241,7 @@ class RedisTrib
|
|||||||
node = ClusterNode.new(ARGV[1])
|
node = ClusterNode.new(ARGV[1])
|
||||||
node.connect(:abort => true)
|
node.connect(:abort => true)
|
||||||
node.assert_cluster
|
node.assert_cluster
|
||||||
|
node.load_info
|
||||||
add_node(node)
|
add_node(node)
|
||||||
check_cluster
|
check_cluster
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user