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)
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
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
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
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)
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)
async def keys_startswith(self, key: str): if self._pool is None: raise NoRedisConfigured() return await self._pool.execute(b"KEYS", f"{key}*")
async def expire(self, key: str, expire: int): if self._pool is None: raise NoRedisConfigured() await self._pool.execute(b"EXPIRE", key, expire)
async def delete(self, key: str): if self._pool is None: raise NoRedisConfigured() await self._pool.execute(b"DEL", key)
async def get(self, key: str) -> str: if self._pool is None: raise NoRedisConfigured() return await self._pool.execute(b"GET", key)
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)
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)
async def unsubscribe(self, channel_name: str): if self._pubsub_subscriptor is None: raise NoRedisConfigured() await self._pubsub_subscriptor.unsubscribe(channel_name)