Skip to content

Commit 66bd1f8

Browse files
committed
Merge pull request #386 from Napolskih/clone-connection
Ability to access complete set of client options.
2 parents 9bb4156 + f549e50 commit 66bd1f8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/redis/client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class Client
1919
:tcp_keepalive => 0
2020
}
2121

22+
def options
23+
Marshal.load(Marshal.dump(@options))
24+
end
25+
2226
def scheme
2327
@options[:scheme]
2428
end
@@ -51,6 +55,10 @@ def db=(db)
5155
@options[:db] = db.to_i
5256
end
5357

58+
def driver
59+
@options[:driver]
60+
end
61+
5462
attr_accessor :logger
5563
attr_reader :connection
5664
attr_reader :command_map

test/internals_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,26 @@ def test_bubble_timeout_without_retrying
320320
serv.close if serv
321321
end
322322
end
323+
324+
def test_client_options
325+
redis = Redis.new(OPTIONS.merge(:host => "host", :port => 1234, :db => 1, :scheme => "foo"))
326+
327+
assert_equal "host", redis.client.options[:host]
328+
assert_equal 1234, redis.client.options[:port]
329+
assert_equal 1, redis.client.options[:db]
330+
assert_equal "foo", redis.client.options[:scheme]
331+
end
332+
333+
def test_does_not_change_self_client_options
334+
redis = Redis.new(OPTIONS.merge(:host => "host", :port => 1234, :db => 1, :scheme => "foo"))
335+
options = redis.client.options
336+
337+
options[:host] << "new_host"
338+
options[:scheme] << "bar"
339+
options.merge!(:db => 0)
340+
341+
assert_equal "host", redis.client.options[:host]
342+
assert_equal 1, redis.client.options[:db]
343+
assert_equal "foo", redis.client.options[:scheme]
344+
end
323345
end

0 commit comments

Comments
 (0)