Skip to content

Commit

Permalink
Merge pull request #153 from valkey-io/aiven-sal/url
Browse files Browse the repository at this point in the history
Allow relative path in unix socket URLs
  • Loading branch information
aiven-sal authored Dec 16, 2024
2 parents 02c2bfe + e9e3bfb commit 1d0ac55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,10 @@ def test_unix_socket_connection_failure():
str(e.value)
== "Error 2 connecting to unix:///tmp/a.sock. No such file or directory."
)


def test_parsing_unix_socket_relative_path():
parsed = parse_url("unix:./valkey.sock", False)
assert parsed["path"] == "./valkey.sock"
assert parsed["connection_class"] is UnixDomainSocketConnection
assert len(parsed) == 2
5 changes: 3 additions & 2 deletions valkey/_parsers/url_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ def parse_url(url: str, async_connection: bool):
supported_schemes = ["valkey", "valkeys", "redis", "rediss", "unix"]
parsed: ParseResult = urlparse(url)
kwargs: ConnectKwargs = {}
lower_url = url.lower()
pattern = re.compile(
r"^(?:" + "|".join(map(re.escape, supported_schemes)) + r")://", re.IGNORECASE
r"^(?:" + "|".join(map(re.escape, supported_schemes)) + r")://"
)
if not pattern.match(url):
if not pattern.match(lower_url) and not lower_url.startswith("unix:"):
raise ValueError(
f"Valkey URL must specify one of the following schemes {supported_schemes}"
)
Expand Down

0 comments on commit 1d0ac55

Please sign in to comment.