Bot become a Community Guard & Post send manager
added: dictionary support for censore message/user management with dict triggers
This commit is contained in:
25
app/infra/redis_client.py
Normal file
25
app/infra/redis_client.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import os
|
||||
try:
|
||||
from redis import asyncio as aioredis
|
||||
except Exception:
|
||||
aioredis = None
|
||||
|
||||
_redis = None
|
||||
|
||||
async def get_redis():
|
||||
"""
|
||||
Возвращает подключение к Redis (async) или None, если REDIS_URL не задан
|
||||
или библиотека не установлена.
|
||||
"""
|
||||
global _redis
|
||||
if _redis is not None:
|
||||
return _redis
|
||||
url = os.getenv("REDIS_URL", "").strip()
|
||||
if not url or aioredis is None:
|
||||
return None
|
||||
_redis = aioredis.from_url(url, encoding="utf-8", decode_responses=True)
|
||||
try:
|
||||
await _redis.ping()
|
||||
except Exception:
|
||||
_redis = None
|
||||
return _redis
|
||||
Reference in New Issue
Block a user