Skip to content

Commit

Permalink
added support for redis and rediss
Browse files Browse the repository at this point in the history
Signed-off-by: ahmedsobeh <[email protected]>
  • Loading branch information
ahmedsobeh committed Jul 1, 2024
1 parent 9e8873f commit eedef29
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions valkey/_parsers/url_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ def to_bool(value) -> Optional[bool]:


def parse_url(url: str, async_connection: bool):
url_prefixes = ["valkey://", "valkeys://", "unix://", "redis://", "rediss://"]

if not (
url.startswith("valkey://")
or url.startswith("valkeys://")
or url.startswith("unix://")
):
if not any(url.startswith(prefix) for prefix in url_prefixes):
raise ValueError(
"Valkey URL must specify one of the following "
"schemes (valkey://, valkeys://, unix://)"
f"Valkey URL must specify one of the following schemes `{url_prefixes}`"
)

parsed: ParseResult = urlparse(url)
Expand All @@ -67,7 +63,7 @@ def parse_url(url: str, async_connection: bool):
if parsed.password:
kwargs["password"] = unquote(parsed.password)

# We only support valkey://, valkeys:// and unix:// schemes.
# We only support valkey://, valkeys://, redis://, rediss://, and unix:// schemes.
if parsed.scheme == "unix":
if parsed.path:
kwargs["path"] = unquote(parsed.path)
Expand All @@ -77,7 +73,7 @@ def parse_url(url: str, async_connection: bool):
else UnixDomainSocketConnection
)

elif parsed.scheme in ("valkey", "valkeys"):
elif parsed.scheme in ("valkey", "valkeys", "redis", "rediss"):
if parsed.hostname:
kwargs["host"] = unquote(parsed.hostname)
if parsed.port:
Expand All @@ -91,14 +87,13 @@ def parse_url(url: str, async_connection: bool):
except (AttributeError, ValueError):
pass

if parsed.scheme == "valkeys":
if parsed.scheme in ("valkeys", "rediss"):
kwargs["connection_class"] = (
SSLConnectionAsync if async_connection else SSLConnection
)
else:
valid_schemes = "valkey://, valkeys://, unix://"
raise ValueError(
f"Valkey URL must specify one of the following schemes ({valid_schemes})"
f"Valkey URL must specify one of the following schemes ({url_prefixes})"
)

return kwargs

0 comments on commit eedef29

Please sign in to comment.