rag-chatbot / app /db /redis_client.py
Abeshith's picture
RAG Chatbot with LangChain, FastAPI, and service layer architecture
64d7fdf
raw
history blame contribute delete
839 Bytes
import redis.asyncio as aioredis
from app.config import config
from app.utils.logger import logger
class RedisClient:
def __init__(self):
self.client = None
async def connect(self):
if self.client is None:
redis_url = config["database"]["redis"]["url"]
self.client = await aioredis.from_url(
redis_url,
encoding="utf-8",
decode_responses=True
)
logger.info("Redis connected")
return self.client
async def disconnect(self):
if self.client:
await self.client.close()
logger.info("Redis disconnected")
async def get_client(self):
if self.client is None:
await self.connect()
return self.client
redis_client = RedisClient()