Class: Redis::Cluster::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/redis/cluster/option.rb

Overview

Keep options for Redis Cluster Client

Constant Summary collapse

DEFAULT_SCHEME =
'redis'
SECURE_SCHEME =
'rediss'
VALID_SCHEMES =
[DEFAULT_SCHEME, SECURE_SCHEME].freeze

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Option

Returns a new instance of Option.



15
16
17
18
19
20
21
22
23
24
# File 'lib/redis/cluster/option.rb', line 15

def initialize(options)
  options = options.dup
  node_addrs = options.delete(:cluster)
  @node_opts = build_node_options(node_addrs)
  @replica = options.delete(:replica) == true
  add_common_node_option_if_needed(options, @node_opts, :scheme)
  add_common_node_option_if_needed(options, @node_opts, :username)
  add_common_node_option_if_needed(options, @node_opts, :password)
  @options = options
end

Instance Method Details

#add_node(host, port) ⇒ Object



39
40
41
# File 'lib/redis/cluster/option.rb', line 39

def add_node(host, port)
  @node_opts << { host: host, port: port }
end

#per_node_keyObject



26
27
28
29
# File 'lib/redis/cluster/option.rb', line 26

def per_node_key
  @node_opts.map { |opt| [NodeKey.build_from_host_port(opt[:host], opt[:port]), @options.merge(opt)] }
            .to_h
end

#update_node(addrs) ⇒ Object



35
36
37
# File 'lib/redis/cluster/option.rb', line 35

def update_node(addrs)
  @node_opts = build_node_options(addrs)
end

#use_replica?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/redis/cluster/option.rb', line 31

def use_replica?
  @replica
end