-
Notifications
You must be signed in to change notification settings - Fork 162
implement valkey support #975
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: amirreza <[email protected]>
Signed-off-by: amirreza <[email protected]>
Signed-off-by: amirreza <[email protected]>
Signed-off-by: amirreza <[email protected]>
Signed-off-by: amirreza <[email protected]>
notes about this PR:
i'll continue to debug the problems with the tests, they could be something obvious that my tired eyes can't see or something hard, idk, i really appreciate any help and ideas and tips some extra notes: also the packaging and development setup is painful |
Looking good. A bit of cleanup still to do and the tests need to pass, but looks like it's mostly good. |
should be noted that the lua script for cas had a bug as well
hi! I'm back so currently i fixed more importatnly tho, i looked into why tests are failing on the discussion about context managers, i have something like this in mind async with ValkeyCache(config=my_config) as cache:
await cache.set(...) where another idea i have is to use a classmethod async with ValkeyCache.with_context_manager(config=congi):
... this way we don't need to change the signature of but i do think config should be provided by the user, so they can configure it as they please p.s: i know the commits have gotten a bit messy, i'm keeping it like this so i can see diff, i'll clean it up before un-drafting |
There is no released version with the current signature. The first version is fine. |
Once the tests actually run in the CI, I might be able to help.
Don't bother, it makes reviewing more difficult. We'll squash commit the PR. |
Ah, that's awkward, there's also no pypy version for valkey-glide? |
https://github.com/valkey-io/valkey-glide/blob/main/python/pyproject.toml#L24 |
Is that a bug in glide? From what I see at a glance, the _reader_loop() task is never awaited on. It looks like it's been cancelled here, which appears to only happen when the client is garbage collected. Either we're not closing the client correctly, or glide is depending on |
Oh, well, pip can't find it to install on the pypy job for some reason. |
hi again 👋🏼 let me know what you think |
aiocache/backends/valkey.py
Outdated
client: Optional[GlideClient] = None, | ||
serializer: Optional["BaseSerializer"] = None, | ||
namespace: str = "", | ||
key_builder: Callable[[str, str], str] = lambda k, ns: f"{ns}:{k}" if ns else k, | ||
backend: type[GlideClient] = GlideClient, | ||
config: GlideClientConfiguration = None, | ||
**kwargs: Any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this a bit awkward and confusing. I think I'd rather make the config required and simplify it to:
client: Optional[GlideClient] = None, | |
serializer: Optional["BaseSerializer"] = None, | |
namespace: str = "", | |
key_builder: Callable[[str, str], str] = lambda k, ns: f"{ns}:{k}" if ns else k, | |
backend: type[GlideClient] = GlideClient, | |
config: GlideClientConfiguration = None, | |
**kwargs: Any, | |
config: GlideClientConfiguration, | |
serializer: Optional["BaseSerializer"] = None, | |
*, | |
namespace: str = "", | |
key_builder: Callable[[str, str], str] = lambda k, ns: f"{ns}:{k}" if ns else k, | |
**kwargs: Any, |
We will add it the future. But, connection pool is mainly used for sync API as each thread has to get a connection from the pool and return it once it got the response back from Valkey. For async mode it is less important as multiple tasks can share the same connection.
I will work with the other maintainers to add it in the next release in end of May. @amirreza8002 Are there any blockers? If yes, we can add them and release a patch version. It would be amazing to get valkey-glide integrated to aiocache. |
hi @asafpamzn , thanks for your response 🙌 about blockers, dreamsourcerer would have a better take i did make a pr about something I'd seen here, but i wouldn't call that a blocker we're currently discussing how to implement a context manager, i agree that the current implementation is ugly |
@amirreza8002 @Dreamsorcerer I will be looking into the issue with not tearing down the client object correctly, we might have a bug. Will update |
Main thing I'd like looked at ASAP is Pypy. If it's supposed to be supported, why can't the CI install it? |
@amirreza8002 @Dreamsorcerer Having said that, we will look into an option to integrate the close() logic into the destructor. I am pretty sure we've already tried but will re-investigate |
I think you got that the wrong way round. You can't close in the destructor, we just missed the close() call originally. Only (minor) concern I see is that the close() method should probably await the _reader_loop() task to ensure any exceptions etc. get raised correctly (like https://docs.aiohttp.org/en/stable/web_advanced.html#complex-applications). |
cleaned up some stuff btw did my comments on context manager come through? |
Which ones? |
i left two comments on your review on context manager. |
first comment: so i did try that, there is one issue tho: since glide clients are made by awaiting the create() method, we can't do that in init class ValkeyCache(...):
def __init__(self, config, ...):
self.client = await GlideClient.create(config=config) # error
async def __aenter__(self):
return self
async def __aexit__(self, *args, **kwargs):
await self.client.close() or is there something i'm missing? |
i have two designs in mind class ValkeyCache(...):
def __init__(self, config, ...):
self.config = config
async def __aenter__(self):
await connect()
return self
async def __aexit__(self, *args, **kwargs):
await self.client.close()
async def connect(self):
self.client = await GlideClient.create(config=self.config) and document that the user should await on connect after instantiation or: class ValkeyCache(...):
def __init__(self, config, ...):
self.config = config
async def __aenter__(self):
self.client = await GlideClient.create(config=self.config)
return self
async def __aexit__(self, *args, **kwargs):
await self.client.close()
@classmethod
async def connect(cls, config):
client = await GlideClient.create(config=config)
self = cls(config=config)
self.client = client
return self and instantiate using classmethod admittedly both are somewhat ugly |
Maybe you started a review and didn't submit the review?
Just create the client in
You mean a Cache? I don't think we need another way to do so. The user can just call |
only context manager is supported to instantiate ValkeyBackend
@asafpamzn @ikolomi Could one of you confirm the situation with Pypy support? |
we discussed pypy here : valkey-io/valkey-glide#3553 is the general feeling around this PR good? |
the glide team have informed me that pypy issue is fixed |
Yeah, that's only a couple of weeks, so maybe we wait for that and then cleanup this PR. |
What do these changes do?
add support for valkey, using valkey-gilde
Related issue number
Fixes #882
Checklist