Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,16 @@ class ConnectKwargs(TypedDict, total=False):


def parse_url(url: str) -> ConnectKwargs:
if not (
url.startswith("redis://")
or url.startswith("rediss://")
or url.startswith("unix://")
):
Comment thread
petyaslavova marked this conversation as resolved.
Outdated
raise ValueError(
"Redis URL must specify one of the following schemes "
"(redis://, rediss://, unix://)"
)

parsed: ParseResult = urlparse(url)
kwargs: ConnectKwargs = {}

Expand Down Expand Up @@ -1795,7 +1805,7 @@ def parse_url(url: str) -> ConnectKwargs:
kwargs["path"] = unquote(parsed.path)
kwargs["connection_class"] = UnixDomainSocketConnection

elif parsed.scheme in ("redis", "rediss"):
else: # implied: parsed.scheme in ("redis", "rediss")
if parsed.hostname:
kwargs["host"] = unquote(parsed.hostname)
if parsed.port:
Expand All @@ -1812,12 +1822,6 @@ def parse_url(url: str) -> ConnectKwargs:
if parsed.scheme == "rediss":
kwargs["connection_class"] = SSLConnection

else:
valid_schemes = "redis://, rediss://, unix://"
raise ValueError(
f"Redis URL must specify one of the following schemes ({valid_schemes})"
)

return kwargs


Expand Down
8 changes: 8 additions & 0 deletions tests/test_asyncio/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,14 @@ def test_invalid_scheme_raises_error(self):
"(redis://, rediss://, unix://)"
)

def test_invalid_scheme_raises_error_when_double_slash_missing(self):
with pytest.raises(ValueError) as cm:
redis.ConnectionPool.from_url("redis:foo.bar.com:12345")
assert str(cm.value) == (
"Redis URL must specify one of the following schemes "
"(redis://, rediss://, unix://)"
)


@pytest.mark.fixed_client
class TestBlockingConnectionPoolURLParsing:
Expand Down