Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse files- app/cache/redis_client.py +11 -4
app/cache/redis_client.py
CHANGED
|
@@ -8,7 +8,13 @@ import logging
|
|
| 8 |
import time
|
| 9 |
from collections import OrderedDict
|
| 10 |
from typing import Optional
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
from app.config import get_settings
|
| 13 |
|
| 14 |
logger = logging.getLogger(__name__)
|
|
@@ -71,21 +77,22 @@ class LRUCache:
|
|
| 71 |
_in_memory_cache = LRUCache(maxsize=5000)
|
| 72 |
|
| 73 |
_redis_client = None
|
| 74 |
-
_redis_is_available =
|
| 75 |
_reconnect_task = None
|
| 76 |
|
| 77 |
|
| 78 |
async def get_redis():
|
| 79 |
global _redis_client
|
|
|
|
|
|
|
| 80 |
if _redis_client is None:
|
| 81 |
-
import redis.asyncio as aioredis
|
| 82 |
from app.config import get_settings
|
| 83 |
settings = get_settings()
|
| 84 |
_redis_client = await aioredis.from_url(
|
| 85 |
settings.redis_url,
|
| 86 |
encoding="utf-8",
|
| 87 |
decode_responses=True,
|
| 88 |
-
max_connections=settings
|
| 89 |
socket_keepalive=True,
|
| 90 |
socket_connect_timeout=5,
|
| 91 |
socket_timeout=5,
|
|
|
|
| 8 |
import time
|
| 9 |
from collections import OrderedDict
|
| 10 |
from typing import Optional
|
| 11 |
+
try:
|
| 12 |
+
import redis.asyncio as aioredis
|
| 13 |
+
_REDIS_MODULE_AVAILABLE = True
|
| 14 |
+
except ImportError:
|
| 15 |
+
aioredis = None
|
| 16 |
+
_REDIS_MODULE_AVAILABLE = False
|
| 17 |
+
|
| 18 |
from app.config import get_settings
|
| 19 |
|
| 20 |
logger = logging.getLogger(__name__)
|
|
|
|
| 77 |
_in_memory_cache = LRUCache(maxsize=5000)
|
| 78 |
|
| 79 |
_redis_client = None
|
| 80 |
+
_redis_is_available = _REDIS_MODULE_AVAILABLE # False si el m贸dulo no est谩 instalado
|
| 81 |
_reconnect_task = None
|
| 82 |
|
| 83 |
|
| 84 |
async def get_redis():
|
| 85 |
global _redis_client
|
| 86 |
+
if not _REDIS_MODULE_AVAILABLE:
|
| 87 |
+
raise RuntimeError("redis module not installed; using in-memory fallback")
|
| 88 |
if _redis_client is None:
|
|
|
|
| 89 |
from app.config import get_settings
|
| 90 |
settings = get_settings()
|
| 91 |
_redis_client = await aioredis.from_url(
|
| 92 |
settings.redis_url,
|
| 93 |
encoding="utf-8",
|
| 94 |
decode_responses=True,
|
| 95 |
+
max_connections=getattr(settings, 'redis_max_connections', 20) or 20,
|
| 96 |
socket_keepalive=True,
|
| 97 |
socket_connect_timeout=5,
|
| 98 |
socket_timeout=5,
|