From 3a08fedc84f1057162a424722332f3406c0fda87 Mon Sep 17 00:00:00 2001 From: Raul Castro Date: Fri, 26 Dec 2025 20:09:28 -0300 Subject: [PATCH] fix redis connection, update readme --- README.md | 3 +++ api.py | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 27801a5..b2f5faa 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ To run this project, you will need to add the following environment variables to | `FLASK_ENV` | Environment mode (`production` enables Redis) | No | `development` | | `REDIS_HOST` | Redis Hostname (Required if Prod) | No | - | | `REDIS_PORT` | Redis Port (Required if Prod) | No | - | +| `REDIS_USER` | Redis Username (Optional) | No | - | | `REDIS_PASSWORD` | Redis Password (Required if Prod) | No | - | ### Caching @@ -53,7 +54,9 @@ CORS_ORIGIN=http://localhost:3000 # Redis (Production only) FLASK_ENV=production REDIS_HOST=mx.redis-server.com +REDIS_HOST=mx.redis-server.com REDIS_PORT=6379 +REDIS_USER=default REDIS_PASSWORD=secret ``` diff --git a/api.py b/api.py index 31e31be..01699ec 100644 --- a/api.py +++ b/api.py @@ -15,11 +15,19 @@ # Cache Configuration is_prod = os.getenv('FLASK_ENV') == 'production' if is_prod: + redis_user = os.getenv('REDIS_USER') or os.getenv('READIS_USER') + redis_password = os.getenv('REDIS_PASSWORD') + redis_host = os.getenv('REDIS_HOST') + redis_port = os.getenv('REDIS_PORT') + + if redis_user: + redis_url = f"redis://{redis_user}:{redis_password}@{redis_host}:{redis_port}" + else: + redis_url = f"redis://:{redis_password}@{redis_host}:{redis_port}" + cache_config = { 'CACHE_TYPE': 'RedisCache', - 'CACHE_REDIS_HOST': os.getenv('REDIS_HOST'), - 'CACHE_REDIS_PORT': os.getenv('REDIS_PORT'), - 'CACHE_REDIS_PASSWORD': os.getenv('REDIS_PASSWORD') + 'CACHE_REDIS_URL': redis_url } else: cache_config = {