Skip to content

Commit

Permalink
Handle empty host
Browse files Browse the repository at this point in the history
  • Loading branch information
Silvere Lestang committed Sep 28, 2020
1 parent 94c5ce7 commit f72fe1b
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/redix_cluster/monitor.ex
Expand Up @@ -145,6 +145,7 @@ defmodule RedixCluster.Monitor do
cluster_info
|> Stream.with_index()
|> Stream.map(&parse_cluster_slot/1)
|> Stream.reject(&is_nil/1)
|> Enum.to_list()
end

Expand Down Expand Up @@ -175,13 +176,19 @@ defmodule RedixCluster.Monitor do
defp parse_cluster_slot({cluster_slot, index}) do
[start_slot, end_slot | nodes] = cluster_slot

%{
index: index + 1,
name: get_slot_name(start_slot, end_slot),
start_slot: start_slot,
end_slot: end_slot,
node: parse_master_node(nodes)
}
case parse_master_node(nodes) do
nil ->
nil

node ->
%{
index: index + 1,
name: get_slot_name(start_slot, end_slot),
start_slot: start_slot,
end_slot: end_slot,
node: node
}
end
end

defp connect_node(cache_name, node) do
Expand All @@ -197,6 +204,11 @@ defmodule RedixCluster.Monitor do
|> String.to_atom()
end

# Handle empty hosts, aka disconnected node
defp parse_master_node([["", 0| _] | _]) do
nil
end

defp parse_master_node([[master_host, master_port | _] | _]) do
%{host: to_charlist(master_host), port: master_port, pool: nil}
end
Expand Down

0 comments on commit f72fe1b

Please sign in to comment.