cabol / nebulex_redis_adapter

Nebulex adapter for Redis

Home Page:https://hexdocs.pm/nebulex_redis_adapter/NebulexRedisAdapter.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow deletion of multiple keys

VitorTrin opened this issue · comments

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

Hey 👋 !

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

Thanks!

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!