From 4724c1bfde2d5679128ced8ec7b46bac66605b7b Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Sat, 21 May 2022 13:04:28 -0400 Subject: [PATCH] Support IPv6 URLs Fix: https://github.com/redis/redis-rb/issues/1100 --- CHANGELOG.md | 1 + lib/redis/client.rb | 2 +- test/url_param_test.rb | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fad00f07..446bbcdeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased +* Support IPv6 URLs. * Add `Redis#with` for better compatibility with `connection_pool` usage. * Fix the block form of `multi` called inside `pipelined`. Previously the `MUTLI/EXEC` wouldn't be sent. See #1073. diff --git a/lib/redis/client.rb b/lib/redis/client.rb index a9d734f48..a988af37c 100644 --- a/lib/redis/client.rb +++ b/lib/redis/client.rb @@ -464,7 +464,7 @@ def _parse_options(options) defaults[:path] = uri.path when "redis", "rediss" defaults[:scheme] = uri.scheme - defaults[:host] = uri.host if uri.host + defaults[:host] = uri.host.sub(/\A\[(.*)\]\z/, '\1') if uri.host defaults[:port] = uri.port if uri.port defaults[:username] = CGI.unescape(uri.user) if uri.user && !uri.user.empty? defaults[:password] = CGI.unescape(uri.password) if uri.password && !uri.password.empty? diff --git a/test/url_param_test.rb b/test/url_param_test.rb index 59626c295..7b0ac7230 100644 --- a/test/url_param_test.rb +++ b/test/url_param_test.rb @@ -135,6 +135,12 @@ def test_defaults_to_localhost assert_equal "127.0.0.1", redis._client.host end + def test_ipv6_url + redis = Redis.new url: "redis://[::1]" + + assert_equal "::1", redis._client.host + end + def test_user_and_password redis = Redis.new(url: 'redis://johndoe:mysecret@foo.com:999/2')