Class: RedisClient::Cluster::Router::RoutingTable

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_client/cluster/router/routing_table.rb

Overview

The routing table for the commands which shouldn't be routed by their keys. The built-in entries can be overridden with the command_routings option of the config.

Constant Summary collapse

BuildError =
Class.new(::RedisClient::Cluster::Error)

Class Method Summary collapse

Class Method Details

.build(routings) ⇒ Object

Builds the routing table: the built-in entries overridden by the command routings which the config validated and normalized. A nil routing removes the built-in entry of the command, so that the command follows the default resolution: the command tips which the server reports, or the routing by its key. It raises a BuildError for an unnormalized input as a defense, e.g. an unsupported policy.



108
109
110
111
112
113
114
# File 'lib/redis_client/cluster/router/routing_table.rb', line 108

def build(routings)
  return DEDICATED_ACTIONS if routings.nil? || routings.empty?

  routings.each_with_object(DEDICATED_ACTIONS.dup) do |(key, policies), acc|
    merge_action(acc, key, fetch_action(key, policies))
  end.freeze
end

.find_policy_action(request_policy, response_policy) ⇒ Object



116
117
118
# File 'lib/redis_client/cluster/router/routing_table.rb', line 116

def find_policy_action(request_policy, response_policy)
  POLICY_ACTIONS.dig(request_policy, response_policy)
end