roulette-bot/tools/redis.py
2024-04-30 11:28:13 +03:00

31 lines
567 B
Python

import contextlib
import redis
import settings
class RedisClient:
def __init__(self, host, password=None):
kwargs = {
"host": host,
}
if password:
kwargs['password'] = password
self.cli = redis.Redis(**kwargs)
def get(self, key):
with self.cli as cli:
return cli.get(f"ruletka_{key}")
def set(self, key, value):
with self.cli as cli:
cli.set(f"ruletka_{key}", value)
redis_client = RedisClient(
settings.REDIS_HOST,
settings.REDIS_PASSWORD
)