-
Notifications
You must be signed in to change notification settings - Fork 224
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
cache.delete_pattern() is very slow #169
Comments
What version are you using? Would it be possible to throw that call in a celery task or spin off another thread? |
I can look into that. I'm running version 1.8.1 |
At version 1.8.1, the library is using |
To further expand on this it only happens when connecting to a Redis instance setup using AWS ElasticCache service. If I use it locally it works fine. I'm guessing it could also just be because that is a live instance and has much more data. I haven't tried to set this up using Celery yet. |
Facing the exact same issue. However, what troubles me is that there are only a few dozen keys in my |
I was not able to use the pattern delete at all because of latency issues. I ended up just deleting the cache records one by one. |
The
|
This at least join the deletions, changing a few lines this should be fine class CustomRedisClient(DefaultClient):
def delete_pattern(
self,
pattern: str | list[str],
version: Optional[int] = None,
prefix: Optional[str] = None,
client: Optional[Redis] = None,
itersize: Optional[int] = None,
) -> int:
"""
Remove all keys matching pattern.
"""
if isinstance(pattern, str):
return super().delete_pattern(pattern,
version=version,
prefix=prefix,
client=client,
itersize=itersize)
if client is None:
client = self.get_client(write=True)
patterns = [self.make_pattern(x, version=version, prefix=prefix) for x in pattern]
try:
count = 0
pipeline = client.pipeline()
for key in itertools.chain(*[client.scan_iter(match=x, count=itersize) for x in patterns]):
pipeline.delete(key)
count += 1
pipeline.execute()
return count
except redis_client_exceptions as e:
raise ConnectionInterrupted(connection=client) from e |
Hey, I'm not known if I got it, but |
This solution didn't work, if the performance is a priority you must set a key with all the keys you need to delete
|
When I use the cache.delete_pattern() in my application it is blocking the response and is running extremely slow. Is there a way to execute this asynchronously? Or in a more efficient manner of any kind?
The text was updated successfully, but these errors were encountered: