From e94b37dd14d7b9c789349eb034dabdbc627ecce0 Mon Sep 17 00:00:00 2001 From: Takumasa Date: Fri, 21 Apr 2017 20:06:21 +0900 Subject: [PATCH] Add missing defaults --- lib/redis/client.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/redis/client.rb b/lib/redis/client.rb index 31be2de33..879c6848a 100644 --- a/lib/redis/client.rb +++ b/lib/redis/client.rb @@ -5,12 +5,16 @@ class Redis class Client + # Defaults are also used for converting string keys to symbols. DEFAULTS = { :url => lambda { ENV["REDIS_URL"] }, :scheme => "redis", :host => "127.0.0.1", :port => 6379, :path => nil, + :read_timeout => nil, + :write_timeout => nil, + :connect_timeout => nil, :timeout => 5.0, :password => nil, :db => 0, @@ -18,7 +22,10 @@ class Client :id => nil, :tcp_keepalive => 0, :reconnect_attempts => 1, - :inherit_socket => false + :inherit_socket => false, + :logger => nil, + :sentinels => [], + :role => nil } def options @@ -86,7 +93,7 @@ def initialize(options = {}) @pending_reads = 0 - if options.include?(:sentinels) + if @options[:sentinels].size > 0 @connector = Connector::Sentinel.new(@options) else @connector = Connector.new(@options) @@ -508,7 +515,7 @@ def initialize(options) @options[:db] = DEFAULTS.fetch(:db) @sentinels = @options.delete(:sentinels).dup - @role = @options.fetch(:role, "master").to_s + @role = (@options[:role] || "master").to_s @master = @options[:host] end