class Redis::Sentinel::URL

Constants

DEFAULT_SENTINEL_PORT
DEFAULT_SENTINEL_SERVICE

Attributes

uri[R]

Public Class Methods

new(url) click to toggle source
# File lib/redis/sentinel/url.rb, line 16
def initialize(url)
  @uri = URI(url)
end
parse(url) click to toggle source
# File lib/redis/sentinel/url.rb, line 12
def self.parse(url)
  new(url).parse
end

Public Instance Methods

parse() click to toggle source
# File lib/redis/sentinel/url.rb, line 37
def parse
  uri_options  = path_options.merge(query_options)
  service_name = uri_options.delete(:service_name) || DEFAULT_SENTINEL_SERVICE

  uri_options[:url]       = "redis://#{service_name}"
  uri_options[:sentinels] = [{ host: uri.host, port: uri.port || DEFAULT_SENTINEL_PORT }]

  uri_options
end
path_options() click to toggle source
/service_name[/db]
# File lib/redis/sentinel/url.rb, line 21
def path_options
  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() click to toggle source
# File lib/redis/sentinel/url.rb, line 33
def query_options
  CGI::parse(uri.query.to_s).transform_keys(&:to_sym)
end