aio-libs/aiocache

Clear() method with 'namespace' parameter fails: TypeError: delete() missing 1 required positional argument: 'key'

Open

#472 aperta il 24 dic 2019

Vedi su GitHub
 (8 commenti) (1 reazione) (1 assegnatario)Python (177 fork)auto 404
buggood first issue

Metriche repository

Star
 (1432 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

I want to use certain namespace while cleaning redis cache, like below: coros.append(asyncio.ensure_future(cache.clear(namespace='main'))) Error occured when redis cache doesn't have key with namespace 'main' : coros.append(asyncio.ensure_future(cache.clear(namespace='dialog_api')))

I've found the problem in file aiocache/backends/redis.py in 187 line:

async def _clear(self, namespace=None, _conn=None):
        if namespace:
            keys = await _conn.keys("{}:*".format(namespace))
            await _conn.delete(*keys)
        else:
            await _conn.flushdb()
        return True

So, I want to fix it by adding if statement, like:

async def _clear(self, namespace=None, _conn=None):
        if namespace:
            keys = await _conn.keys("{}:*".format(namespace))
            if keys:
                await _conn.delete(*keys)

I could be wrong or miss something, if anybody faced with it please comment

Guida contributor