This commit is contained in:
DengDai
2025-12-08 14:47:24 +08:00
commit 644b5aaaf8
21 changed files with 1543 additions and 0 deletions

15
pt_gen/services/cache.py Normal file
View File

@@ -0,0 +1,15 @@
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()