Class: RedisClient::ClusterConfig
- Inherits:
-
Object
- Object
- RedisClient::ClusterConfig
- Defined in:
- lib/redis_client/cluster_config.rb
Constant Summary collapse
- DEFAULT_NODE =
"#{DEFAULT_SCHEME}://#{DEFAULT_HOST}:#{DEFAULT_PORT}"- InvalidClientConfigError =
Class.new(::RedisClient::Cluster::Error)
Instance Attribute Summary collapse
-
#client_config ⇒ Object
readonly
Returns the value of attribute client_config.
-
#command_builder ⇒ Object
readonly
Returns the value of attribute command_builder.
-
#command_routings ⇒ Object
readonly
Returns the value of attribute command_routings.
-
#connect_with_original_config ⇒ Object
readonly
Returns the value of attribute connect_with_original_config.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#max_startup_sample ⇒ Object
readonly
Returns the value of attribute max_startup_sample.
-
#replica_affinity ⇒ Object
readonly
Returns the value of attribute replica_affinity.
-
#slow_command_timeout ⇒ Object
readonly
Returns the value of attribute slow_command_timeout.
-
#startup_nodes ⇒ Object
readonly
Returns the value of attribute startup_nodes.
Instance Method Summary collapse
- #client_config_for_node(node_key) ⇒ Object
- #connect_timeout ⇒ Object
-
#initialize(nodes: DEFAULT_NODES, replica: false, replica_affinity: :random, fixed_hostname: '', concurrency: nil, connect_with_original_config: false, client_implementation: ::RedisClient::Cluster, slow_command_timeout: SLOW_COMMAND_TIMEOUT, command_builder: ::RedisClient::CommandBuilder, max_startup_sample: MAX_STARTUP_SAMPLE, command_routings: nil, **client_config) ⇒ ClusterConfig
constructor
rubocop:disable Metrics/ParameterLists, Metrics/AbcSize.
- #inspect ⇒ Object
- #new_client(**kwargs) ⇒ Object
- #new_pool(size: 5, timeout: 5, **kwargs) ⇒ Object
- #read_timeout ⇒ Object
- #resolved? ⇒ Boolean
- #sentinel? ⇒ Boolean
- #server_url ⇒ Object
- #use_replica? ⇒ Boolean
- #write_timeout ⇒ Object
Constructor Details
#initialize(nodes: DEFAULT_NODES, replica: false, replica_affinity: :random, fixed_hostname: '', concurrency: nil, connect_with_original_config: false, client_implementation: ::RedisClient::Cluster, slow_command_timeout: SLOW_COMMAND_TIMEOUT, command_builder: ::RedisClient::CommandBuilder, max_startup_sample: MAX_STARTUP_SAMPLE, command_routings: nil, **client_config) ⇒ ClusterConfig
rubocop:disable Metrics/ParameterLists, Metrics/AbcSize
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/redis_client/cluster_config.rb', line 53 def initialize( # rubocop:disable Metrics/ParameterLists, Metrics/AbcSize nodes: DEFAULT_NODES, replica: false, replica_affinity: :random, fixed_hostname: '', concurrency: nil, connect_with_original_config: false, client_implementation: ::RedisClient::Cluster, # for redis gem slow_command_timeout: SLOW_COMMAND_TIMEOUT, command_builder: ::RedisClient::CommandBuilder, max_startup_sample: MAX_STARTUP_SAMPLE, command_routings: nil, **client_config ) @replica = true & replica @replica_affinity = replica_affinity.to_s.to_sym @fixed_hostname = fixed_hostname.to_s @command_builder = command_builder node_configs = build_node_configs(nodes.dup) @client_config = merge_generic_config(client_config, node_configs) # Keep tabs on the original startup nodes we were constructed with @startup_nodes = build_startup_nodes(node_configs) @concurrency = merge_concurrency_option(concurrency) @connect_with_original_config = connect_with_original_config @client_implementation = client_implementation @slow_command_timeout = slow_command_timeout @max_startup_sample = max_startup_sample @command_routings = normalize_command_routings(command_routings) @id = client_config[:id] end |
Instance Attribute Details
#client_config ⇒ Object (readonly)
Returns the value of attribute client_config.
50 51 52 |
# File 'lib/redis_client/cluster_config.rb', line 50 def client_config @client_config end |
#command_builder ⇒ Object (readonly)
Returns the value of attribute command_builder.
50 51 52 |
# File 'lib/redis_client/cluster_config.rb', line 50 def command_builder @command_builder end |
#command_routings ⇒ Object (readonly)
Returns the value of attribute command_routings.
50 51 52 |
# File 'lib/redis_client/cluster_config.rb', line 50 def command_routings @command_routings end |
#connect_with_original_config ⇒ Object (readonly)
Returns the value of attribute connect_with_original_config.
50 51 52 |
# File 'lib/redis_client/cluster_config.rb', line 50 def connect_with_original_config @connect_with_original_config end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
50 51 52 |
# File 'lib/redis_client/cluster_config.rb', line 50 def id @id end |
#max_startup_sample ⇒ Object (readonly)
Returns the value of attribute max_startup_sample.
50 51 52 |
# File 'lib/redis_client/cluster_config.rb', line 50 def max_startup_sample @max_startup_sample end |
#replica_affinity ⇒ Object (readonly)
Returns the value of attribute replica_affinity.
50 51 52 |
# File 'lib/redis_client/cluster_config.rb', line 50 def replica_affinity @replica_affinity end |
#slow_command_timeout ⇒ Object (readonly)
Returns the value of attribute slow_command_timeout.
50 51 52 |
# File 'lib/redis_client/cluster_config.rb', line 50 def slow_command_timeout @slow_command_timeout end |
#startup_nodes ⇒ Object (readonly)
Returns the value of attribute startup_nodes.
50 51 52 |
# File 'lib/redis_client/cluster_config.rb', line 50 def startup_nodes @startup_nodes end |
Instance Method Details
#client_config_for_node(node_key) ⇒ Object
117 118 119 120 121 |
# File 'lib/redis_client/cluster_config.rb', line 117 def client_config_for_node(node_key) config = ::RedisClient::Cluster::NodeKey.hashify(node_key) config[:port] = ensure_integer(config[:port]) augment_client_config(config) end |
#connect_timeout ⇒ Object
88 89 90 |
# File 'lib/redis_client/cluster_config.rb', line 88 def connect_timeout @client_config[:connect_timeout] || @client_config[:timeout] || ::RedisClient::Config::DEFAULT_TIMEOUT end |
#inspect ⇒ Object
84 85 86 |
# File 'lib/redis_client/cluster_config.rb', line 84 def inspect "#<#{self.class.name} #{startup_nodes.values.map { |v| redact_for_inspect(v) }}>" end |
#new_client(**kwargs) ⇒ Object
109 110 111 |
# File 'lib/redis_client/cluster_config.rb', line 109 def new_client(**kwargs) @client_implementation.new(self, concurrency: @concurrency, **kwargs) end |
#new_pool(size: 5, timeout: 5, **kwargs) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/redis_client/cluster_config.rb', line 100 def new_pool(size: 5, timeout: 5, **kwargs) @client_implementation.new( self, pool: { size: size, timeout: timeout }, concurrency: @concurrency, **kwargs ) end |
#read_timeout ⇒ Object
92 93 94 |
# File 'lib/redis_client/cluster_config.rb', line 92 def read_timeout @client_config[:read_timeout] || @client_config[:timeout] || ::RedisClient::Config::DEFAULT_TIMEOUT end |
#resolved? ⇒ Boolean
123 124 125 |
# File 'lib/redis_client/cluster_config.rb', line 123 def resolved? true end |
#sentinel? ⇒ Boolean
127 128 129 |
# File 'lib/redis_client/cluster_config.rb', line 127 def sentinel? false end |
#server_url ⇒ Object
131 132 133 |
# File 'lib/redis_client/cluster_config.rb', line 131 def server_url nil end |
#use_replica? ⇒ Boolean
113 114 115 |
# File 'lib/redis_client/cluster_config.rb', line 113 def use_replica? @replica end |
#write_timeout ⇒ Object
96 97 98 |
# File 'lib/redis_client/cluster_config.rb', line 96 def write_timeout @client_config[:write_timeout] || @client_config[:timeout] || ::RedisClient::Config::DEFAULT_TIMEOUT end |