init
This commit is contained in:
15
pt_gen/services/cache.py
Normal file
15
pt_gen/services/cache.py
Normal 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()
|
||||
Reference in New Issue
Block a user