Class: RedisClient::Config

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/redis_client/config.rb

Defined Under Namespace

Modules: Common

Constant Summary collapse

DEFAULT_TIMEOUT =
1.0
DEFAULT_HOST =
"localhost"
DEFAULT_PORT =
6379
DEFAULT_USERNAME =
"default"
DEFAULT_DB =
0

Instance Attribute Summary collapse

Attributes included from Common

#circuit_breaker, #command_builder, #connect_timeout, #custom, #db, #driver, #id, #inherit_socket, #middlewares_stack, #protocol, #read_timeout, #ssl, #ssl_params, #write_timeout

Instance Method Summary collapse

Methods included from Common

#connection_prelude, #new_client, #new_pool, #password, #resolved?, #retriable?, #retry_connecting?, #sentinel?, #server_url, #ssl_context, #username

Constructor Details

#initialize(url: nil, host: nil, port: nil, path: nil, username: nil, password: nil, db: nil, **kwargs) ⇒ Config

Returns a new instance of Config.



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/redis_client/config.rb', line 191

def initialize(
  url: nil,
  host: nil,
  port: nil,
  path: nil,
  username: nil,
  password: nil,
  db: nil,
  **kwargs
)
  if url
    url_config = URLConfig.new(url)
    kwargs = {
      ssl: url_config.ssl?,
    }.compact.merge(kwargs)
    db ||= url_config.db
    host ||= url_config.host
    port ||= url_config.port
    path ||= url_config.path
    username ||= url_config.username
    password ||= url_config.password
  end

  super(username: username, password: password, db: db, **kwargs)

  if @path = path
    @host = nil
    @port = nil
  else
    @host = host || DEFAULT_HOST
    @port = Integer(port || DEFAULT_PORT)
  end

  @server_key = [@path, @host, @port].freeze
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



189
190
191
# File 'lib/redis_client/config.rb', line 189

def host
  @host
end

#pathObject (readonly)

Returns the value of attribute path.



189
190
191
# File 'lib/redis_client/config.rb', line 189

def path
  @path
end

#portObject (readonly)

Returns the value of attribute port.



189
190
191
# File 'lib/redis_client/config.rb', line 189

def port
  @port
end

#server_keyObject (readonly)

Returns the value of attribute server_key.



189
190
191
# File 'lib/redis_client/config.rb', line 189

def server_key
  @server_key
end