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
|
# File 'lib/redis/factory.rb', line 15
def self.convert_to_redis_client_options(address_or_options)
if address_or_options.is_a?(Hash)
options = address_or_options.dup
options[:namespace] ||= options.delete(:key_prefix) options
else
if address_or_options =~ /redis\:\/\//
require 'uri'
uri = URI.parse address_or_options
_, db, namespace = if uri.path
uri.path.split /\//
end
else
warn "[DEPRECATION] `#{address_or_options}` is deprecated. Please use `redis://#{address_or_options}` instead."
address_or_options, password = address_or_options.split(/\@/).reverse
password = password.gsub(/\:/, "") if password
host, port = address_or_options.split /\:/
port, db, namespace = port.split /\// if port
end
options = {}
options[:host] = host || uri && uri.host
options[:port] = port || uri && uri.port
options[:db] = db.to_i if db
options[:namespace] = namespace if namespace
options[:password] = password || uri && uri.password
options[:marshalling] = false if RUBY_VERSION =~ /1\.9/
options
end
end
|