add clear method

This commit is contained in:
long2ice
2020-11-03 18:08:06 +08:00
parent dc2ac9cc90
commit e483e0dc55
6 changed files with 40 additions and 2 deletions

View File

@@ -20,3 +20,10 @@ class RedisBackend(Backend):
async def set(self, key: str, value: str, expire: int = None):
return await self.redis.set(key, value, expire=expire)
async def clear(self, namespace: str = None, key: str = None) -> int:
if namespace:
lua = f"for i, name in ipairs(redis.call('KEYS', '{namespace}:*')) do redis.call('DEL', name); end"
return await self.redis.eval(lua)
elif key:
return await self.redis.delete(key)