16 lines
482 B
Python
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()
|