class RedisClient::Config
Constants
- DEFAULT_DB
- DEFAULT_HOST
- DEFAULT_PORT
- DEFAULT_TIMEOUT
- DEFAULT_USERNAME
Attributes
host[R]
path[R]
port[R]
Public Class Methods
new( url: nil, host: nil, port: nil, path: nil, **kwargs )
click to toggle source
Calls superclass method
RedisClient::Config::Common::new
# File lib/redis_client/config.rb, line 155 def initialize( url: nil, host: nil, port: nil, path: nil, **kwargs ) if url uri = URI(url) unless uri.scheme == "redis" || uri.scheme == "rediss" raise ArgumentError, "Invalid URL: #{url.inspect}" end kwargs[:ssl] = uri.scheme == "rediss" unless kwargs.key?(:ssl) kwargs[:username] ||= uri.user if uri.password && !uri.user.empty? kwargs[:password] ||= if uri.user && !uri.password URI.decode_www_form_component(uri.user) elsif uri.user && uri.password URI.decode_www_form_component(uri.password) end db_path = uri.path&.delete_prefix("/") kwargs[:db] ||= Integer(db_path) if db_path && !db_path.empty? end super(**kwargs) @host = host unless @host uri_host = uri&.host uri_host = nil if uri_host&.empty? if uri_host @host = uri_host&.sub(/\A\[(.*)\]\z/, '\1') end end @host ||= DEFAULT_HOST @port = Integer(port || uri&.port || DEFAULT_PORT) @path = path end