26 lines
680 B
Python
26 lines
680 B
Python
from redis.asyncio import Redis
|
|
from config import conf
|
|
|
|
|
|
class RedisClient:
|
|
async def __aenter__(self):
|
|
self.client = Redis(
|
|
host=conf.reddis.host,
|
|
port=conf.reddis.port,
|
|
db=conf.reddis.db,
|
|
username=conf.reddis.login,
|
|
password=conf.reddis.pwd,
|
|
)
|
|
return self.client
|
|
|
|
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
await self.client.close()
|
|
|
|
async def set_value(self, key, value):
|
|
async with self as client:
|
|
await client.set(key, value)
|
|
|
|
async def get_value(self, key):
|
|
async with self as client:
|
|
return await client.get(key)
|