Files
PTGen/pt_gen/services/cache.py
DengDai 644b5aaaf8 init
2025-12-08 14:47:24 +08:00

16 lines
482 B
Python

import redis.asyncio as redis
from typing import Optional
class RedisCache:
def __init__(self, host: str, port: int, db: int):
self.client = redis.Redis(host=host, port=port, db=db, decode_responses=True)
async def get(self, key: str) -> Optional[str]:
return await self.client.get(key)
async def set(self, key: str, value: str, ttl: int):
await self.client.setex(key, ttl, value)
async def close(self):
await self.client.close()