From 72c42325ab2b1cbbe6b0bb459e49e354a3355a07 Mon Sep 17 00:00:00 2001 From: Martijn Pieters Date: Thu, 27 Apr 2023 16:33:43 +0100 Subject: [PATCH] The backend needs an async redis client with a pipeline method The Abstract* classes lack the pipeline method so are not sufficient. --- fastapi_cache/backends/redis.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fastapi_cache/backends/redis.py b/fastapi_cache/backends/redis.py index 0bff5c7..a40bde4 100644 --- a/fastapi_cache/backends/redis.py +++ b/fastapi_cache/backends/redis.py @@ -1,15 +1,15 @@ from typing import Optional, Tuple -from redis.asyncio.client import AbstractRedis -from redis.asyncio.cluster import AbstractRedisCluster +from redis.asyncio.client import Redis +from redis.asyncio.cluster import RedisCluster from fastapi_cache.backends import Backend class RedisBackend(Backend): - def __init__(self, redis: AbstractRedis): + def __init__(self, redis: Redis[str] | RedisCluster[str]): self.redis = redis - self.is_cluster = isinstance(redis, AbstractRedisCluster) + self.is_cluster: bool = isinstance(redis, RedisCluster) async def get_with_ttl(self, key: str) -> Tuple[int, str]: async with self.redis.pipeline(transaction=not self.is_cluster) as pipe: