From 29244a06d0ec9b3cf0bcf273c2c4e9046a26e196 Mon Sep 17 00:00:00 2001 From: Takumasa Ochi Date: Tue, 17 Nov 2020 04:08:43 +0900 Subject: [PATCH] Symbolize all the option keys at Redis::Client#initialize(option) Previously, a limited portion of options are symbolized at `Redis::Client#initialize(option)`. Specifically, only those defined at `Redis::Client::DEFAULTS` are symbolized. This invoked confusing behavior and increased maintenance cost. For example, specifying timeout was a little bit tricky as follows. ``` Redis::Client.new('timeout' => 10.0).options[:timeout] # => 10.0 Redis::Client.new('read_timeout' => 10.0).options[:read_timeout] # => 5.0 ``` Now, all the keys of options are symbolized, and consistent external behavior is achieved. ``` Redis::Client.new('timeout' => 10.0).options[:timeout] # => 10.0 Redis::Client.new('read_timeout' => 10.0).options[:read_timeout] # => 10.0 ``` --- lib/redis/client.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/redis/client.rb b/lib/redis/client.rb index 5ef5fdb6e..85c4e1103 100644 --- a/lib/redis/client.rb +++ b/lib/redis/client.rb @@ -404,14 +404,13 @@ def _parse_options(options) return options if options[:_parsed] defaults = DEFAULTS.dup - options = options.dup + options = options.each_with_object({}) do |(key, value), new_option| + new_option[key.to_sym] = value # Dup and symbolize keys + end defaults.keys.each do |key| # Fill in defaults if needed defaults[key] = defaults[key].call if defaults[key].respond_to?(:call) - - # Symbolize only keys that are needed - options[key] = options[key.to_s] if options.key?(key.to_s) end url = options[:url]