Skip to content

Commit

Permalink
Merge pull request #7 from vitalyserhienko/feature-fix-for-new-aioredis
Browse files Browse the repository at this point in the history
fix for issue #5
  • Loading branch information
cr0hn committed Jun 26, 2019
2 parents a6af17c + 2bcd26c commit b3292ac
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions aiohttp_cache/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def load_object(self, value):

async def get(self, key: str):
async with self._redis_pool.get() as redis:
redis_value = await redis.get(self.key_prefix + key)
redis_value = await redis.execute('GET', self.key_prefix + key)

return self.load_object(redis_value)

Expand All @@ -125,28 +125,27 @@ async def set(self, key: str, value: dict, expires: int = 3000):

if _expires == 0:
async with self._redis_pool.get() as redis:
await redis.set(name=self.key_prefix + key,
value=dump)
await redis.execute('SET', name=self.key_prefix + key,
value=dump)
else:
async with self._redis_pool.get() as redis:
await redis.setex(key=self.key_prefix + key,
seconds=_expires,
value=dump)
await redis.execute('SETEX', key=self.key_prefix + key,
seconds=_expires, value=dump)

async def delete(self, key: str):
async with self._redis_pool.get() as redis:
await redis.delete(self.key_prefix + key)
await redis.execute('DEL', self.key_prefix + key)

async def has(self, key: str) -> bool:
async with self._redis_pool.get() as redis:
return await redis.exists(self.key_prefix + key)
return await redis.execute('EXISTS', self.key_prefix + key)

async def clear(self):
async with self._redis_pool.get() as redis:
if self.key_prefix:
keys = await redis.keys(self.key_prefix + '*')
keys = await redis.execute('KEYS', self.key_prefix + '*')
if keys:
await redis.delete(*keys)
await redis.execute('DELETE', *keys)
else:
await redis.flushdb()

Expand Down

0 comments on commit b3292ac

Please sign in to comment.