mirror of
https://github.com/fluencelabs/redis
synced 2025-04-01 15:21:03 +00:00
redis-trib: all node information into a single hash
This commit is contained in:
parent
b08c9dd280
commit
92dd76c8ee
@ -18,11 +18,11 @@ class ClusterNode
|
|||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
@r = nil
|
@r = nil
|
||||||
@host = s[0]
|
@info = {}
|
||||||
@port = s[1]
|
@info[:host] = s[0]
|
||||||
@slots = {}
|
@info[:port] = s[1]
|
||||||
@dirty = false
|
@info[:slots] = {}
|
||||||
@info = nil
|
@dirty = false # True if we need to flush slots info into node.
|
||||||
@friends = []
|
@friends = []
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -31,18 +31,18 @@ class ClusterNode
|
|||||||
end
|
end
|
||||||
|
|
||||||
def slots
|
def slots
|
||||||
@slots
|
@info[:slots]
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"#{@host}:#{@port}"
|
"#{@info[:host]}:#{@info[:port]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def connect(o={})
|
def connect(o={})
|
||||||
return if @r
|
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 => @info[:host], :port => @info[:port])
|
||||||
@r.ping
|
@r.ping
|
||||||
rescue
|
rescue
|
||||||
puts "ERROR"
|
puts "ERROR"
|
||||||
@ -85,8 +85,8 @@ class ClusterNode
|
|||||||
:link_status => link_status
|
:link_status => link_status
|
||||||
}
|
}
|
||||||
if info[:flags].index("myself")
|
if info[:flags].index("myself")
|
||||||
@info = info
|
@info = @info.merge(info)
|
||||||
@slots = {}
|
@info[:slots] = {}
|
||||||
slots.split(",").each{|s|
|
slots.split(",").each{|s|
|
||||||
if s.index("-")
|
if s.index("-")
|
||||||
start,stop = s.split("-")
|
start,stop = s.split("-")
|
||||||
@ -113,7 +113,7 @@ class ClusterNode
|
|||||||
|
|
||||||
def add_slots(slots)
|
def add_slots(slots)
|
||||||
slots.each{|s|
|
slots.each{|s|
|
||||||
@slots[s] = :new
|
@info[:slots][s] = :new
|
||||||
}
|
}
|
||||||
@dirty = true
|
@dirty = true
|
||||||
end
|
end
|
||||||
@ -121,10 +121,10 @@ class ClusterNode
|
|||||||
def flush_node_config
|
def flush_node_config
|
||||||
return if !@dirty
|
return if !@dirty
|
||||||
new = []
|
new = []
|
||||||
@slots.each{|s,val|
|
@info[:slots].each{|s,val|
|
||||||
if val == :new
|
if val == :new
|
||||||
new << s
|
new << s
|
||||||
@slots[s] = true
|
@info[:slots][s] = true
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@r.cluster("addslots",*new)
|
@r.cluster("addslots",*new)
|
||||||
@ -140,7 +140,7 @@ class ClusterNode
|
|||||||
|
|
||||||
# First step: we want an increasing array of integers
|
# First step: we want an increasing array of integers
|
||||||
# for instance: [1,2,3,4,5,8,9,20,21,22,23,24,25,30]
|
# for instance: [1,2,3,4,5,8,9,20,21,22,23,24,25,30]
|
||||||
slots = @slots.keys.sort
|
slots = @info[:slots].keys.sort
|
||||||
|
|
||||||
# As we want to aggregate adiacent slots we convert all the
|
# As we want to aggregate adiacent slots we convert all the
|
||||||
# slot integers into ranges (with just one element)
|
# slot integers into ranges (with just one element)
|
||||||
@ -167,12 +167,7 @@ class ClusterNode
|
|||||||
end
|
end
|
||||||
|
|
||||||
def info
|
def info
|
||||||
{
|
@info
|
||||||
:host => @host,
|
|
||||||
:port => @port,
|
|
||||||
:slots => @slots,
|
|
||||||
:dirty => @dirty
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_dirty?
|
def is_dirty?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user