mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-25 04:57:54 +00:00
The backend needs an async redis client with a pipeline method
The Abstract* classes lack the pipeline method so are not sufficient.
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user