Skip to content

Commit

Permalink
Fix parse_cluster_info in RedisCluster.ConfigManager (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
norbajunior authored Aug 1, 2023
1 parent ec641ba commit 3bb98f0
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions lib/nebulex_redis_adapter/redis_cluster/config_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -264,32 +264,17 @@ defmodule NebulexRedisAdapter.RedisCluster.ConfigManager do
Enum.reduce(config, [], fn
# Redis version >= 7 (["CLUSTER", "SHARDS"])
["slots", [start, stop], "nodes", nodes], acc ->
for [
"id",
_,
"port",
port,
"ip",
_,
"endpoint",
endpoint,
"role",
"master",
"replication-offset",
_,
"health",
"online"
] <- nodes do
{endpoint, port}
end
|> case do
case parse_node_attrs(nodes) do
[] ->
# coveralls-ignore-start
acc

# coveralls-ignore-stop

[{host, port} | _] ->
[attrs | _] ->
host = attrs["endpoint"]
port = attrs["tls-port"] || attrs["port"]

[{start, stop, host, port} | acc]
end

Expand All @@ -302,6 +287,20 @@ defmodule NebulexRedisAdapter.RedisCluster.ConfigManager do
end)
end

defp parse_node_attrs(nodes) do
Enum.reduce(nodes, [], fn attrs, acc ->
attrs =
attrs
|> Enum.chunk_every(2)
|> Enum.reduce(%{}, fn [key, value], acc ->
Map.put(acc, key, value)
end)

[attrs | acc]
end)
|> Enum.filter(&(&1["role"] == "master" and &1["health"] == "online"))
end

defp maybe_override_host(_host, config_endpoint, true) do
config_endpoint
end
Expand Down

0 comments on commit 3bb98f0

Please sign in to comment.