Skip to content

Commit

Permalink
Merge pull request #1081 from supercaracal/fix-id-for-obj-inspection
Browse files Browse the repository at this point in the history
Reflect scheme of URI in client ID instead of hard coding
  • Loading branch information
byroot authored Feb 25, 2022
2 parents 399ebde + bf9e5e7 commit 610c783
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/redis/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def connect
end

def id
@options[:id] || "redis://#{location}/#{db}"
@options[:id] || "#{@options[:ssl] ? 'rediss' : @options[:scheme]}://#{location}/#{db}"
end

def location
Expand Down
11 changes: 8 additions & 3 deletions test/connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,24 @@ def test_default_id_with_host_and_port
assert_equal "redis://host:1234/0", redis.connection.fetch(:id)
end

def test_default_id_with_host_and_port_and_ssl
redis = Redis.new(OPTIONS.merge(host: 'host', port: '1234', db: 0, ssl: true))
assert_equal "rediss://host:1234/0", redis.connection.fetch(:id)
end

def test_default_id_with_host_and_port_and_explicit_scheme
redis = Redis.new(OPTIONS.merge(host: "host", port: "1234", db: 0, scheme: "foo"))
assert_equal "redis://host:1234/0", redis.connection.fetch(:id)
assert_equal "foo://host:1234/0", redis.connection.fetch(:id)
end

def test_default_id_with_path
redis = Redis.new(OPTIONS.merge(path: "/tmp/redis.sock", db: 0))
assert_equal "redis:///tmp/redis.sock/0", redis.connection.fetch(:id)
assert_equal "unix:///tmp/redis.sock/0", redis.connection.fetch(:id)
end

def test_default_id_with_path_and_explicit_scheme
redis = Redis.new(OPTIONS.merge(path: "/tmp/redis.sock", db: 0, scheme: "foo"))
assert_equal "redis:///tmp/redis.sock/0", redis.connection.fetch(:id)
assert_equal "unix:///tmp/redis.sock/0", redis.connection.fetch(:id)
end

def test_override_id
Expand Down

0 comments on commit 610c783

Please sign in to comment.