Skip to content

Commit bf9e5e7

Browse files
author
Taishi Kasuga
committed
Reflect scheme of URI in client ID instead of hard coding
1 parent 399ebde commit bf9e5e7

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/redis/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def connect
150150
end
151151

152152
def id
153-
@options[:id] || "redis://#{location}/#{db}"
153+
@options[:id] || "#{@options[:ssl] ? 'rediss' : @options[:scheme]}://#{location}/#{db}"
154154
end
155155

156156
def location

test/connection_test.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,24 @@ def test_default_id_with_host_and_port
4949
assert_equal "redis://host:1234/0", redis.connection.fetch(:id)
5050
end
5151

52+
def test_default_id_with_host_and_port_and_ssl
53+
redis = Redis.new(OPTIONS.merge(host: 'host', port: '1234', db: 0, ssl: true))
54+
assert_equal "rediss://host:1234/0", redis.connection.fetch(:id)
55+
end
56+
5257
def test_default_id_with_host_and_port_and_explicit_scheme
5358
redis = Redis.new(OPTIONS.merge(host: "host", port: "1234", db: 0, scheme: "foo"))
54-
assert_equal "redis://host:1234/0", redis.connection.fetch(:id)
59+
assert_equal "foo://host:1234/0", redis.connection.fetch(:id)
5560
end
5661

5762
def test_default_id_with_path
5863
redis = Redis.new(OPTIONS.merge(path: "/tmp/redis.sock", db: 0))
59-
assert_equal "redis:///tmp/redis.sock/0", redis.connection.fetch(:id)
64+
assert_equal "unix:///tmp/redis.sock/0", redis.connection.fetch(:id)
6065
end
6166

6267
def test_default_id_with_path_and_explicit_scheme
6368
redis = Redis.new(OPTIONS.merge(path: "/tmp/redis.sock", db: 0, scheme: "foo"))
64-
assert_equal "redis:///tmp/redis.sock/0", redis.connection.fetch(:id)
69+
assert_equal "unix:///tmp/redis.sock/0", redis.connection.fetch(:id)
6570
end
6671

6772
def test_override_id

0 commit comments

Comments
 (0)