Class: SolidRedis::Config
- Inherits:
-
Object
- Object
- SolidRedis::Config
- Defined in:
- lib/solid_redis/config.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
1.0- DEFAULT_PORT =
6379- UNSPECIFIED =
Object.new.freeze
Instance Attribute Summary collapse
-
#connect_timeout ⇒ Object
readonly
Returns the value of attribute connect_timeout.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
-
#reconnect_attempts ⇒ Object
readonly
Returns the value of attribute reconnect_attempts.
-
#ssl_params ⇒ Object
readonly
Returns the value of attribute ssl_params.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
-
#write_timeout ⇒ Object
readonly
Returns the value of attribute write_timeout.
Instance Method Summary collapse
-
#initialize(url: nil, host: "127.0.0.1", port: DEFAULT_PORT, path: nil, username: nil, password: nil, db: UNSPECIFIED, timeout: DEFAULT_TIMEOUT, connect_timeout: timeout, read_timeout: timeout, write_timeout: timeout, reconnect_attempts: 1, ssl: false, ssl_params: nil, callbacks: nil) ⇒ Config
constructor
A new instance of Config.
- #inspect ⇒ Object
- #new_client(**options) ⇒ Object
- #new_pool(**options) ⇒ Object
- #new_subscription(**options) ⇒ Object
- #notify(event, *arguments) ⇒ Object
- #resolved? ⇒ Boolean
- #sentinel? ⇒ Boolean
- #server_key ⇒ Object
- #server_url ⇒ Object
- #ssl? ⇒ Boolean
Constructor Details
#initialize(url: nil, host: "127.0.0.1", port: DEFAULT_PORT, path: nil, username: nil, password: nil, db: UNSPECIFIED, timeout: DEFAULT_TIMEOUT, connect_timeout: timeout, read_timeout: timeout, write_timeout: timeout, reconnect_attempts: 1, ssl: false, ssl_params: nil, callbacks: nil) ⇒ Config
Returns a new instance of Config.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/solid_redis/config.rb', line 15 def initialize( url: nil, host: "127.0.0.1", port: DEFAULT_PORT, path: nil, username: nil, password: nil, db: UNSPECIFIED, timeout: DEFAULT_TIMEOUT, connect_timeout: timeout, read_timeout: timeout, write_timeout: timeout, reconnect_attempts: 1, ssl: false, ssl_params: nil, callbacks: nil ) if url values = parse_url(url) host = values[:host] port = values[:port] path = values[:path] username ||= values[:username] password ||= values[:password] db = values[:db] if db.equal?(UNSPECIFIED) && !values[:db].nil? ssl ||= values[:ssl] end db = 0 if db.equal?(UNSPECIFIED) @host = String(host).dup.freeze unless path @port = Integer(port) unless path @path = String(path).dup.freeze if path @username = String(username).dup.freeze if username @password = String(password).dup.freeze if password @db = Integer(db) @connect_timeout = positive_float(connect_timeout, :connect_timeout) @read_timeout = positive_float(read_timeout, :read_timeout) @write_timeout = positive_float(write_timeout, :write_timeout) @reconnect_attempts = Integer(reconnect_attempts) raise ArgumentError, "reconnect_attempts must not be negative" if @reconnect_attempts.negative? @ssl = !!ssl @ssl_params = Shareable.copy(ssl_params, label: "ssl_params") if ssl_params @callbacks = Shareable.copy(callbacks, label: "callbacks") if callbacks Ractor.make_shareable(self) end |
Instance Attribute Details
#connect_timeout ⇒ Object (readonly)
Returns the value of attribute connect_timeout.
11 12 13 |
# File 'lib/solid_redis/config.rb', line 11 def connect_timeout @connect_timeout end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
11 12 13 |
# File 'lib/solid_redis/config.rb', line 11 def db @db end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
11 12 13 |
# File 'lib/solid_redis/config.rb', line 11 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
11 12 13 |
# File 'lib/solid_redis/config.rb', line 11 def password @password end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/solid_redis/config.rb', line 11 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
11 12 13 |
# File 'lib/solid_redis/config.rb', line 11 def port @port end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
11 12 13 |
# File 'lib/solid_redis/config.rb', line 11 def read_timeout @read_timeout end |
#reconnect_attempts ⇒ Object (readonly)
Returns the value of attribute reconnect_attempts.
11 12 13 |
# File 'lib/solid_redis/config.rb', line 11 def reconnect_attempts @reconnect_attempts end |
#ssl_params ⇒ Object (readonly)
Returns the value of attribute ssl_params.
11 12 13 |
# File 'lib/solid_redis/config.rb', line 11 def ssl_params @ssl_params end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
11 12 13 |
# File 'lib/solid_redis/config.rb', line 11 def username @username end |
#write_timeout ⇒ Object (readonly)
Returns the value of attribute write_timeout.
11 12 13 |
# File 'lib/solid_redis/config.rb', line 11 def write_timeout @write_timeout end |
Instance Method Details
#inspect ⇒ Object
104 105 106 |
# File 'lib/solid_redis/config.rb', line 104 def inspect "#<#{self.class.name} #{server_url}>" end |
#new_client(**options) ⇒ Object
86 87 88 |
# File 'lib/solid_redis/config.rb', line 86 def new_client(**) Client.new(self, **) end |
#new_pool(**options) ⇒ Object
90 91 92 |
# File 'lib/solid_redis/config.rb', line 90 def new_pool(**) Pool.new(self, **) end |
#new_subscription(**options) ⇒ Object
94 95 96 |
# File 'lib/solid_redis/config.rb', line 94 def new_subscription(**) Subscription.new(self, **) end |
#notify(event, *arguments) ⇒ Object
98 99 100 101 102 |
# File 'lib/solid_redis/config.rb', line 98 def notify(event, *arguments) return unless @callbacks&.respond_to?(event) @callbacks.respond_with(event, *arguments) end |
#resolved? ⇒ Boolean
70 71 72 |
# File 'lib/solid_redis/config.rb', line 70 def resolved? true end |
#sentinel? ⇒ Boolean
66 67 68 |
# File 'lib/solid_redis/config.rb', line 66 def sentinel? false end |
#server_key ⇒ Object
74 75 76 |
# File 'lib/solid_redis/config.rb', line 74 def server_key [path, host, port].freeze end |
#server_url ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/solid_redis/config.rb', line 78 def server_url return "unix://#{path}?db=#{db}" if path scheme = ssl? ? "rediss" : "redis" address = host.include?(":") ? "[#{host}]" : host "#{scheme}://#{address}:#{port}/#{db}" end |
#ssl? ⇒ Boolean
62 63 64 |
# File 'lib/solid_redis/config.rb', line 62 def ssl? @ssl end |