Class: RedisClient::ClusterConfig
- Inherits:
-
Object
- Object
- RedisClient::ClusterConfig
- Defined in:
- lib/redis_client/cluster_config.rb
Constant Summary collapse
- DEFAULT_HOST =
'127.0.0.1'
- DEFAULT_PORT =
6379
- DEFAULT_SCHEME =
'redis'
- SECURE_SCHEME =
'rediss'
- DEFAULT_NODES =
["#{DEFAULT_SCHEME}://#{DEFAULT_HOST}:#{DEFAULT_PORT}"].freeze
- VALID_SCHEMES =
[DEFAULT_SCHEME, SECURE_SCHEME].freeze
- VALID_NODES_KEYS =
%i[ssl username password host port db].freeze
- MERGE_CONFIG_KEYS =
%i[ssl username password].freeze
- IGNORE_GENERIC_CONFIG_KEYS =
%i[url host port path].freeze
- InvalidClientConfigError =
Class.new(::RedisClient::Error)
Instance Method Summary collapse
- #add_node(host, port) ⇒ Object
- #dup ⇒ Object
-
#initialize(nodes: DEFAULT_NODES, replica: false, fixed_hostname: '', **client_config) ⇒ ClusterConfig
constructor
A new instance of ClusterConfig.
- #inspect ⇒ Object
- #new_client(**kwargs) ⇒ Object
- #new_pool(size: 5, timeout: 5, **kwargs) ⇒ Object
- #per_node_key ⇒ Object
- #update_node(addrs) ⇒ Object
- #use_replica? ⇒ Boolean
Constructor Details
#initialize(nodes: DEFAULT_NODES, replica: false, fixed_hostname: '', **client_config) ⇒ ClusterConfig
Returns a new instance of ClusterConfig.
22 23 24 25 26 27 28 29 |
# File 'lib/redis_client/cluster_config.rb', line 22 def initialize(nodes: DEFAULT_NODES, replica: false, fixed_hostname: '', **client_config) @replica = true & replica @fixed_hostname = fixed_hostname.to_s @node_configs = build_node_configs(nodes.dup) client_config = client_config.reject { |k, _| IGNORE_GENERIC_CONFIG_KEYS.include?(k) } @client_config = merge_generic_config(client_config, @node_configs) @mutex = Mutex.new end |
Instance Method Details
#add_node(host, port) ⇒ Object
60 61 62 |
# File 'lib/redis_client/cluster_config.rb', line 60 def add_node(host, port) @mutex.synchronize { @node_configs << { host: host, port: port } } end |
#dup ⇒ Object
64 65 66 |
# File 'lib/redis_client/cluster_config.rb', line 64 def dup self.class.new(nodes: @node_configs, replica: @replica, fixed_hostname: @fixed_hostname, **@client_config) end |
#inspect ⇒ Object
31 32 33 |
# File 'lib/redis_client/cluster_config.rb', line 31 def inspect "#<#{self.class.name} #{per_node_key.values}>" end |
#new_client(**kwargs) ⇒ Object
39 40 41 |
# File 'lib/redis_client/cluster_config.rb', line 39 def new_client(**kwargs) ::RedisClient::Cluster.new(self, **kwargs) end |
#new_pool(size: 5, timeout: 5, **kwargs) ⇒ Object
35 36 37 |
# File 'lib/redis_client/cluster_config.rb', line 35 def new_pool(size: 5, timeout: 5, **kwargs) ::RedisClient::Cluster.new(self, pool: { size: size, timeout: timeout }, **kwargs) end |
#per_node_key ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/redis_client/cluster_config.rb', line 43 def per_node_key @node_configs.to_h do |config| node_key = ::RedisClient::Cluster::NodeKey.build_from_host_port(config[:host], config[:port]) config = @client_config.merge(config) config = config.merge(host: @fixed_hostname) unless @fixed_hostname.empty? [node_key, config] end end |
#update_node(addrs) ⇒ Object
56 57 58 |
# File 'lib/redis_client/cluster_config.rb', line 56 def update_node(addrs) @mutex.synchronize { @node_configs = build_node_configs(addrs) } end |
#use_replica? ⇒ Boolean
52 53 54 |
# File 'lib/redis_client/cluster_config.rb', line 52 def use_replica? @replica end |