module Redis::Cluster::NodeLoader

Load and hashify node info for Redis Cluster Client

Public Instance Methods

fetch_node_info(node) click to toggle source
# File lib/redis/cluster/node_loader.rb, line 23
def fetch_node_info(node)
  node.call(%i[cluster nodes])
      .split("\n")
      .map { |str| str.split(' ') }
      .map { |arr| [arr[1].split('@').first, (arr[2].split(',') & %w[master slave]).first] }
      .to_h
rescue CannotConnectError, ConnectionError, CommandError
  {} # can retry on another node
end
load_flags(nodes) click to toggle source
# File lib/redis/cluster/node_loader.rb, line 10
def load_flags(nodes)
  info = {}

  nodes.each do |node|
    info = fetch_node_info(node)
    info.empty? ? next : break
  end

  return info unless info.empty?

  raise CannotConnectError, 'Redis client could not connect to any cluster nodes'
end