From 82b1c4a77a32db43d754504255b73bb3c7112376 Mon Sep 17 00:00:00 2001 From: Johan Koke Date: Thu, 6 Feb 2025 15:44:16 +0000 Subject: [PATCH] modifeid redis and app --- app/main.py | 10 +++++----- docker-compose.yaml | 7 +++---- requirements.txt | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/main.py b/app/main.py index ffdb7b8..bff9b67 100644 --- a/app/main.py +++ b/app/main.py @@ -16,15 +16,15 @@ app = FastAPI() # Secret API Key SECRET_PHRASE = os.getenv("API_SECRET", "my_secret_key") -# Use the Redis password from the environment variable -REDIS_URL = os.getenv("REDIS_URL", "redis://:my_redis_password@redis:6379") -redis_client = redis.from_url(REDIS_URL) +# Use the Redis password from the environment variable +REDIS_URL = os.getenv("REDIS_URL", "redis://redis:6379/0") @app.on_event("startup") async def startup(): - """Initialize FastAPI Limiter.""" - await FastAPILimiter.init(redis_client) + """Initialize FastAPI Limiter with async Redis connection.""" + redis = await aioredis.from_url(REDIS_URL, decode_responses=True) + await FastAPILimiter.init(redis) # Setup Static Files for Documentation app.mount("/", StaticFiles(directory="app/docs", html=True), name="docs") diff --git a/docker-compose.yaml b/docker-compose.yaml index 0249979..f4233f3 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,10 +5,10 @@ services: build: . container_name: screenshot-api ports: - - "80:80" + - "8990:80" environment: - - API_SECRET=kokeserver - - REDIS_URL=redis://:my_redis_password@redis:6379 + - API_SECRET=my_secret_key + - REDIS_URL=redis://redis:6379/0 depends_on: - redis networks: @@ -20,7 +20,6 @@ services: restart: always ports: - "6379:6379" - command: redis-server --requirepass my_redis_password networks: - screenshot-network diff --git a/requirements.txt b/requirements.txt index b993bef..ba66c68 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ fastapi uvicorn playwright fastapi-limiter -redis +aioredis