Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incompatiable code with redis py #82

Closed
amirreza8002 opened this issue Sep 2, 2024 · 9 comments
Closed

incompatiable code with redis py #82

amirreza8002 opened this issue Sep 2, 2024 · 9 comments
Assignees
Labels
question Further information is requested

Comments

@amirreza8002
Copy link
Contributor

hi
so i want to fork django-redis package and turn into django-valkey
this parts of redis_py package is not available in your project.
some parts of it are used in django-redis so i was wondering if there is a reason why these are not presented.

Version: latest

@aiven-sal aiven-sal added the question Further information is requested label Sep 2, 2024
@aiven-sal aiven-sal self-assigned this Sep 2, 2024
@aiven-sal
Copy link
Member

aiven-sal commented Sep 2, 2024

Hi Amirreza! Thanks for reaching out.
Since when the fork happened, valkey-py and redis-py diverged a little bit.
They are still very similar, but they are also evolving independently.
I think that the code you are looking for is now here:

def to_bool(value) -> Optional[bool]:
if value is None or value == "":
return None
if isinstance(value, str) and value.upper() in FALSE_STRINGS:
return False
return bool(value)
FALSE_STRINGS = ("0", "F", "FALSE", "N", "NO")
URL_QUERY_ARGUMENT_PARSERS: Mapping[str, Callable[..., object]] = MappingProxyType(
{
"db": int,
"socket_timeout": float,
"socket_connect_timeout": float,
"socket_keepalive": to_bool,
"retry_on_timeout": to_bool,
"max_connections": int,
"health_check_interval": int,
"ssl_check_hostname": to_bool,
"timeout": float,
}
)
def parse_url(url: str, async_connection: bool):
supported_schemes = ["valkey", "valkeys", "redis", "rediss", "unix"]
parsed: ParseResult = urlparse(url)
kwargs: ConnectKwargs = {}
pattern = re.compile(
r"^(?:" + "|".join(map(re.escape, supported_schemes)) + r")://", re.IGNORECASE
)
if not pattern.match(url):
raise ValueError(
f"Valkey URL must specify one of the following schemes {supported_schemes}"
)
for name, value_list in parse_qs(parsed.query).items():
if value_list and len(value_list) > 0:
value = unquote(value_list[0])
parser = URL_QUERY_ARGUMENT_PARSERS.get(name)
if parser:
try:
kwargs[name] = parser(value)
except (TypeError, ValueError):
raise ValueError(f"Invalid value for `{name}` in connection URL.")
else:
kwargs[name] = value
if parsed.username:
kwargs["username"] = unquote(parsed.username)
if parsed.password:
kwargs["password"] = unquote(parsed.password)
# We only support valkey://, valkeys://, redis://, rediss://, and unix:// schemes.
if parsed.scheme == "unix":
if parsed.path:
kwargs["path"] = unquote(parsed.path)
kwargs["connection_class"] = (
UnixDomainSocketConnectionAsync
if async_connection
else UnixDomainSocketConnection
)
elif parsed.scheme in supported_schemes:
if parsed.hostname:
kwargs["host"] = unquote(parsed.hostname)
if parsed.port:
kwargs["port"] = int(parsed.port)
# If there's a path argument, use it as the db argument if a
# querystring value wasn't specified
if parsed.path and "db" not in kwargs:
try:
kwargs["db"] = int(unquote(parsed.path).replace("/", ""))
except (AttributeError, ValueError):
pass
if parsed.scheme in ("valkeys", "rediss"):
kwargs["connection_class"] = (
SSLConnectionAsync if async_connection else SSLConnection
)
else:
raise ValueError(
f"Valkey URL must specify one of the following schemes {supported_schemes}"
)

@amirreza8002
Copy link
Contributor Author

oh thanks
it makes sense
i was assuming that the projects go exactly the same way for the moment

I'll fix the import then

@aiven-sal
Copy link
Member

No problem,
feel free to re-open this issue if you encounter any other problem.

@amirreza8002
Copy link
Contributor Author

hello @aiven-sal
i wanted to know what version of python are you supporting?
i have some typing headaches coming from valkey_py and wanted to write a patch
need to know what syntax i can and can't use

@aiven-sal
Copy link
Member

We support from 3.8 to 3.12 (https://github.com/valkey-io/valkey-py/blob/main/setup.py#L50-L54),
BTW there is another issue related to typing you if you want to take a look #84

@amirreza8002
Copy link
Contributor Author

ah i was hoping for 3.10 to use | :)

ok then

also i know you are busy but if you ever find the time to reflect on django-valkey i would very much appreciate it
I'm new to caching and still trying to figure out stuff

@aiven-sal
Copy link
Member

ah i was hoping for 3.10 to use | :)

I think it will probably take a couple of years before we drop 3.9. :(

also i know you are busy but if you ever find the time to reflect on django-valkey i would very much appreciate it I'm new to caching and still trying to figure out stuff

What do you mean by "reflect on django-valkey" ?

@amirreza8002
Copy link
Contributor Author

amirreza8002 commented Sep 6, 2024

ah i just meant feedback on what can be added or fixed on the project
which i just realize i hadn't posted the link before
django-valkey

but again
i understand that it's not a small codebase and you are busy, so don't feel pressure

@aiven-sal
Copy link
Member

I'm not very much involved in django development.
I'd suggest to reach out to the original django-redis's devs. They might have some feedback and they may be even interested in cooperating on django-valkey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants