Module: Schked::RedisClientFactory

Defined in:
lib/schked/redis_client_factory.rb

Class Method Summary collapse

Class Method Details

.build(options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/schked/redis_client_factory.rb', line 7

def self.build(options)
  unless options.key?(:reconnect_attempts)
    options[:reconnect_attempts] = 3
  end

  if options.key?(:sentinels)
    if (url = options.delete(:url))
      uri = URI.parse(url)
      if !options.key?(:name) && uri.host
        options[:name] = uri.host
      end

      if !options.key?(:password) && uri.password && !uri.password.empty?
        options[:password] = uri.password
      end

      if !options.key?(:username) && uri.user && !uri.user.empty?
        options[:username] = uri.user
      end
    end

    RedisClient.sentinel(**options).new_client
  else
    RedisClient.config(**options).new_client
  end
end