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

Clear() deletes all Redis keys instead of limiting deletes only to namespace #580

Open
Girgitt opened this issue Nov 30, 2022 · 4 comments

Comments

@Girgitt
Copy link

Girgitt commented Nov 30, 2022

Thank you for a very fast caching solution.

I think there could be an issue with clear method when aiocache is used with Redis.

environment

  1. OS: linux (mint 21 and Rocky 8.5)
  2. platform: amd64
  3. software stack: FastApi (v0.70.0) on python 3.6, redis (v6.0.16) and keydb (v6.2.1)
  4. aiocache versions:
    aiocache==0.11.1
    aioredis==1.3.1

how to reproduce

  1. create some keys in redis
  2. clear aiocache on startup (e.g. within FastApi's init) with code:
from fastapi import FastAPI

from asyncio import get_event_loop
from aiocache import Cache
from aiocache.serializers import PickleSerializer


class SomeRestServer(FastAPI):
    def __init__(self, title: str = "test api") -> None:
        super().__init__(title=title)

        self._results_cache = Cache(Cache.REDIS, serializer=PickleSerializer(),
                                    endpoint="127.0.0.1", port=6379, namespace="some_name")

        loop = get_event_loop()
        task = loop.create_task(self._results_cache.clear(namespace="some_name"))
        loop.run_until_complete(task)

expected behavior

3a. keys created in step 1 are available after calling the clear method

actual behavior

3b. all keys are deleted from redis (no matter if namespace value is passed to clear method or not)

@Dreamsorcerer
Copy link
Member

Think #523 is meant to solve this. If anyone wants to finish up the PR, then we can get this fixed.

@antont
Copy link

antont commented Jun 9, 2023

#523 is closed now, maybe this is fixed as well?

@KundaPanda
Copy link

Just encountered this quite randomly as well. We had to create our own subclass to solve this. Good thing the redis helm chart has flushdb disabled by default.

@teodoryantcheff
Copy link

Hey, could you at least mention that in the docs?
Calling .clear() on an alias cache of the Redis type clears the entire cache, ignoring the namespace given in the configuration.
Just costed us several hundred megs of moderately important cache data.

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

5 participants