Parses a Redis connection URL into keyword arguments, supporting redis://, rediss://, and unix:// schemes, and handles query parameters, authentication, and connection class selection.
# Source: https://github.com/redis/redis-py | License: MIT | Copyright 2022-2023, Redis, inc
# Provided via justclaw.it.com; keep this notice with the code.
def parse_url(url: str) -> ConnectKwargs:
# Scheme names are case-insensitive (RFC 3986), so normalize before the
# prefix check; the "://" is required so a URL like "redis:foo" (which
# urlparse would still report as the "redis" scheme) is rejected.
if not url.lower().startswith(("redis://", "rediss://", "unix://")):
raise ValueError(
"Redis URL must specify one of the following schemes "
"(redis://, rediss://, unix://)"
)
parsed: ParseResult = urlparse(url)
kwargs: ConnectKwargs = {}
for name, value_list in parse_qs(parsed.query).items():
if value_list and
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key