Class: Redis::Sentinel::URL
- Inherits:
-
Object
- Object
- Redis::Sentinel::URL
- Defined in:
- lib/redis/sentinel/url.rb
Constant Summary collapse
- DEFAULT_SENTINEL_PORT =
26379
- DEFAULT_SENTINEL_SERVICE =
'mymaster'
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(url) ⇒ URL
constructor
A new instance of URL.
- #parse ⇒ Object
-
#path_options ⇒ Object
[/service_name].
- #query_options ⇒ Object
Constructor Details
#initialize(url) ⇒ URL
Returns a new instance of URL.
16 17 18 |
# File 'lib/redis/sentinel/url.rb', line 16 def initialize(url) @uri = URI(url) end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
10 11 12 |
# File 'lib/redis/sentinel/url.rb', line 10 def uri @uri end |
Class Method Details
.parse(url) ⇒ Object
12 13 14 |
# File 'lib/redis/sentinel/url.rb', line 12 def self.parse(url) new(url).parse end |
Instance Method Details
#parse ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/redis/sentinel/url.rb', line 37 def parse = .merge() service_name = .delete(:service_name) || DEFAULT_SENTINEL_SERVICE [:url] = "redis://#{service_name}" [:sentinels] = [{ host: uri.host, port: uri.port || DEFAULT_SENTINEL_PORT }] end |
#path_options ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/redis/sentinel/url.rb', line 21 def path_parts = uri.path.split('/') case path_parts.length when 3 { service_name: path_parts[1], db: path_parts[2] } when 2 { service_name: path_parts[1] } else {} end end |
#query_options ⇒ Object
33 34 35 |
# File 'lib/redis/sentinel/url.rb', line 33 def CGI::parse(uri.query.to_s).transform_keys(&:to_sym) end |