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, #connection_prelude, #custom, #db, #driver, #id, #inherit_socket, #middlewares_stack, #password, #protocol, #read_timeout, #ssl, #ssl_params, #write_timeout

Instance Method Summary collapse

Methods included from Common

#new_client, #new_pool, #resolved?, #retry_connecting?, #sentinel?, #server_url, #ssl_context, #username

Constructor Details

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

Returns a new instance of Config.



185
186
187
188
189
190
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
# File 'lib/redis_client/config.rb', line 185

def initialize(
  url: nil,
  host: nil,
  port: nil,
  path: nil,
  username: nil,
  password: nil,
  **kwargs
)
  if url
    url_config = URLConfig.new(url)
    kwargs = {
      ssl: url_config.ssl?,
      db: url_config.db,
    }.compact.merge(kwargs)
    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, **kwargs)

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

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



183
184
185
# File 'lib/redis_client/config.rb', line 183

def host
  @host
end

#pathObject (readonly)

Returns the value of attribute path.



183
184
185
# File 'lib/redis_client/config.rb', line 183

def path
  @path
end

#portObject (readonly)

Returns the value of attribute port.



183
184
185
# File 'lib/redis_client/config.rb', line 183

def port
  @port
end