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

Allow deletion of multiple keys #37

Closed
VitorTrin opened this issue Apr 1, 2022 · 2 comments
Closed

Allow deletion of multiple keys #37

VitorTrin opened this issue Apr 1, 2022 · 2 comments

Comments

@VitorTrin
Copy link

VitorTrin commented Apr 1, 2022

The use case: I want to delete all key that matches "prefix*". Nebulex gives us Nebulex.Cache.delete_all, but that doesn't work as redis has no native methods to delete all matching keys, so right now this method only works if we send nil to delete the whole thing.

So, the best way to do this in redis to get all matching keys then delete them in a single DEL call sending a list of keys. Getting all matching keys can be done using Nebulex.Cache.all but there's no way to delete multiple keys at once, forcing us to do multiple calls

tl,dr: Please implement Nebulex.Cache.delete in a way we can send a list of keys to be deleted

@cabol
Copy link
Owner

cabol commented Apr 3, 2022

Hey 👋 !

Totally agree, this feature request makes a lot of sense, will try to work on it as soon as I can!

Thanks!

@cabol
Copy link
Owner

cabol commented May 14, 2022

Hey 👋 ! Sorry for the lateness, but finally I've pushed some changes to address this feature to allow removing multiple keys at once. For example:

MyApp.RedisCache.delete_all({:in, ["foo", "bar"]})

Now the adapter supports the queue predefined query {:in, [term, ...]} for c:Nebulex.Cache.delete_all/2.

This operation is internally optimized to do it in one command for the :standalone mode. For the :redis_cluster and :client_side_cluster modes, the keys are grouped in such a way in order to perform only one command per node or hash slot (avoiding multiple DEL commands).

Please try it out and let me know your thoughts, stay tuned!

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

No branches or pull requests

2 participants