Esempio n. 1
0
 async def flushall(self, *, async_op: Optional[bool] = False):
     if self._pool is None:
         raise NoRedisConfigured()
     ops = [b"FLUSHDB"]
     if async_op:
         ops.append(b"ASYNC")
     await self._pool.execute(*ops)
Esempio n. 2
0
 async def set(self, key: str, data: str, *, expire: Optional[int] = None):
     if self._pool is None:
         raise NoRedisConfigured()
     args: List[Any] = []
     if expire is not None:
         args[:] = [b"EX", expire]
     ok = await self._pool.execute(b"SET", key, data, *args)
     assert ok == b"OK", ok
Esempio n. 3
0
 async def unsubscribe(self, channel_name: str):
     if self._pubsub_subscriptor is None:
         raise NoRedisConfigured()
     try:
         await self._pubsub_subscriptor.unsubscribe(channel_name)
     except aioredis.errors.ConnectionClosedError:
         if self.initialized:
             raise
Esempio n. 4
0
 async def get(self, key: str) -> str:
     if self._pool is None:
         raise NoRedisConfigured()
     with watch("get") as w:
         val = await self._pool.execute(b"GET", key)
         if not val:
             w.labels["type"] = "get_miss"
         return val
Esempio n. 5
0
 async def delete_all(self, keys: List[str]):
     if self._pool is None:
         raise NoRedisConfigured()
     for key in keys:
         try:
             await self._pool.execute(b"DEL", key)
             logger.debug("Deleted cache keys {}".format(keys))
         except Exception:
             logger.warning("Error deleting cache keys {}".format(keys), exc_info=True)
Esempio n. 6
0
    async def subscribe(self, channel_name: str):
        if self._pubsub_subscriptor is None:
            raise NoRedisConfigured()
        try:
            (channel,) = await self._pubsub_subscriptor.subscribe(channel_name)
        except aioredis.errors.ConnectionClosedError:  # pragma: no cover
            # closed in middle
            try:
                self._pool.close(self._conn)
            except Exception:
                pass
            self._conn = await self._pool.acquire()
            self._pubsub_subscriptor = aioredis.Redis(self._conn)
            (channel,) = await self._pubsub_subscriptor.subscribe(channel_name)

        return self._listener(channel)
Esempio n. 7
0
 async def keys_startswith(self, key: str):
     if self._pool is None:
         raise NoRedisConfigured()
     return await self._pool.execute(b"KEYS", f"{key}*")
Esempio n. 8
0
 async def expire(self, key: str, expire: int):
     if self._pool is None:
         raise NoRedisConfigured()
     await self._pool.execute(b"EXPIRE", key, expire)
Esempio n. 9
0
 async def delete(self, key: str):
     if self._pool is None:
         raise NoRedisConfigured()
     await self._pool.execute(b"DEL", key)
Esempio n. 10
0
 async def get(self, key: str) -> str:
     if self._pool is None:
         raise NoRedisConfigured()
     return await self._pool.execute(b"GET", key)
Esempio n. 11
0
 async def publish(self, channel_name: str, data: str):
     if self._pool is None:
         raise NoRedisConfigured()
     await self._pool.execute(b"publish", channel_name, data)
Esempio n. 12
0
 async def subscribe(self, channel_name: str):
     if self._pubsub_subscriptor is None:
         raise NoRedisConfigured()
     (channel, ) = await self._pubsub_subscriptor.subscribe(channel_name)
     return self._listener(channel)
Esempio n. 13
0
 async def unsubscribe(self, channel_name: str):
     if self._pubsub_subscriptor is None:
         raise NoRedisConfigured()
     await self._pubsub_subscriptor.unsubscribe(channel_name)