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
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: 0, 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: 0, 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.
14 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 |
# File 'lib/solid_redis/config.rb', line 14 def initialize( url: nil, host: "127.0.0.1", port: DEFAULT_PORT, path: nil, username: nil, password: nil, db: 0, 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] unless values[:db].nil? ssl ||= values[:ssl] end @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.
10 11 12 |
# File 'lib/solid_redis/config.rb', line 10 def connect_timeout @connect_timeout end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
10 11 12 |
# File 'lib/solid_redis/config.rb', line 10 def db @db end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/solid_redis/config.rb', line 10 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
10 11 12 |
# File 'lib/solid_redis/config.rb', line 10 def password @password end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/solid_redis/config.rb', line 10 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/solid_redis/config.rb', line 10 def port @port end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
10 11 12 |
# File 'lib/solid_redis/config.rb', line 10 def read_timeout @read_timeout end |
#reconnect_attempts ⇒ Object (readonly)
Returns the value of attribute reconnect_attempts.
10 11 12 |
# File 'lib/solid_redis/config.rb', line 10 def reconnect_attempts @reconnect_attempts end |
#ssl_params ⇒ Object (readonly)
Returns the value of attribute ssl_params.
10 11 12 |
# File 'lib/solid_redis/config.rb', line 10 def ssl_params @ssl_params end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
10 11 12 |
# File 'lib/solid_redis/config.rb', line 10 def username @username end |
#write_timeout ⇒ Object (readonly)
Returns the value of attribute write_timeout.
10 11 12 |
# File 'lib/solid_redis/config.rb', line 10 def write_timeout @write_timeout end |
Instance Method Details
#inspect ⇒ Object
102 103 104 |
# File 'lib/solid_redis/config.rb', line 102 def inspect "#<#{self.class.name} #{server_url}>" end |
#new_client(**options) ⇒ Object
84 85 86 |
# File 'lib/solid_redis/config.rb', line 84 def new_client(**) Client.new(self, **) end |
#new_pool(**options) ⇒ Object
88 89 90 |
# File 'lib/solid_redis/config.rb', line 88 def new_pool(**) Pool.new(self, **) end |
#new_subscription(**options) ⇒ Object
92 93 94 |
# File 'lib/solid_redis/config.rb', line 92 def new_subscription(**) Subscription.new(self, **) end |
#notify(event, *arguments) ⇒ Object
96 97 98 99 100 |
# File 'lib/solid_redis/config.rb', line 96 def notify(event, *arguments) return unless @callbacks&.respond_to?(event) @callbacks.respond_with(event, *arguments) end |
#resolved? ⇒ Boolean
68 69 70 |
# File 'lib/solid_redis/config.rb', line 68 def resolved? true end |
#sentinel? ⇒ Boolean
64 65 66 |
# File 'lib/solid_redis/config.rb', line 64 def sentinel? false end |
#server_key ⇒ Object
72 73 74 |
# File 'lib/solid_redis/config.rb', line 72 def server_key [path, host, port].freeze end |
#server_url ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/solid_redis/config.rb', line 76 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
60 61 62 |
# File 'lib/solid_redis/config.rb', line 60 def ssl? @ssl end |