Spaces:
Sleeping
Sleeping
axeronis
perf: optimize for 100 concurrent clients - DB pool 50, AI queue 20, Redis pool 100
eb11f98 Download backend/app/core/redis.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 950 Bytes
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/app/core/redis.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/app/core/redis.py
-
curl -L -o redis.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/app/core/redis.py
950 Bytes
| import redis.asyncio as redis | |
| from app.core.config import settings | |
| import logging | |
| logger = logging.getLogger(__name__) | |
| class RedisClient: | |
| _instance: redis.Redis = None | |
| def get_instance(cls) -> redis.Redis: | |
| if cls._instance is None: | |
| # Create connection pool with high concurrency settings | |
| pool = redis.ConnectionPool.from_url( | |
| settings.REDIS_URL, | |
| encoding="utf-8", | |
| decode_responses=True, | |
| max_connections=100 # Increased for 100+ clients | |
| ) | |
| cls._instance = redis.Redis(connection_pool=pool) | |
| logger.info("Redis client initialized.") | |
| return cls._instance | |
| async def close(cls): | |
| if cls._instance: | |
| await cls._instance.close() | |
| logger.info("Redis client closed.") | |
| def get_redis() -> redis.Redis: | |
| return RedisClient.get_instance() | |