Class: SolidRedis::Cluster::DiscoverService

Inherits:
Service::Base
  • Object
show all
Defined in:
lib/solid_redis/cluster/discover_service.rb

Overview

Queries CLUSTER SLOTS on the first reachable node and returns the slot table as a list of ranges:

{ ranges: [{ from:, to:, master: { host:, port: }, replicas: [...] }], endpoint: }

Instance Method Summary collapse

Instance Method Details

#call ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/solid_redis/cluster/discover_service.rb', line 10

def call
  @endpoints.each do |endpoint|
    client = Config.new(**@specification.redis_client_options, **endpoint).new_client
    ranges = client.call("CLUSTER", "SLOTS").map { |entry| range(entry, endpoint) }
    if ranges.empty?
      append_error(:empty_topology, "#{endpoint_label(endpoint)} returned no slots")
      next
    end

    return { ranges: ranges, endpoint: endpoint }
  rescue SolidRedis::Error, KeyError, ArgumentError, TypeError => error
    append_error(:node_unavailable, "#{endpoint_label(endpoint)}: #{error.message}")
  ensure
    client&.close
  end

  nil
end