Class: RedisUrlParser

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_url_parser.rb

Class Method Summary collapse

Class Method Details

.call(uri) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/redis_url_parser.rb', line 4

def self.call(uri)
  return { url: uri } unless uri.start_with?("sentinel")

  m = uri.match("sentinel://:([^@]*)@([^/]*)/service_name:(.*)")
  password = m[1]
  sentinel_uris = m[2]
  name = m[3]
  url = "redis://:#{password}@#{name}"
  sentinels = sentinel_uris.split(",").map do |sentinel_uri|
    host, port = sentinel_uri.split(":")
    {
      host: host,
      port: port
    }
  end

  {
    url: url,
    sentinels: sentinels
  }
end