From 590f1f45767412fb7fd7f50443fc18e5305d2d8b Mon Sep 17 00:00:00 2001 From: Mathias Goncalves Date: Mon, 15 Aug 2022 16:10:08 -0400 Subject: [PATCH] FIX: Check for `REDIS_TLS_URL` before `MIGAS_REDIS_URI` (#49) --- README.md | 2 +- migas_server/connections.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 991b4ab..54d040c 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Migas is built with [FastAPI](https://fastapi.tiangolo.com/), [Strawberry](https | Service | Environmental Variable | Alternatives | Required | | ------- | ---------------------- | -------------| -------- | -| redis | MIGAS_REDIS_URI | n/a | Yes +| redis | REDIS_TLS_URI, MIGAS_REDIS_URI | n/a | At least one | postgres | DATABASE_URL | n/a | Yes | sqlalchemy | MIGAS_DEBUG | n/a | No diff --git a/migas_server/connections.py b/migas_server/connections.py index 3571bdc..45861fc 100644 --- a/migas_server/connections.py +++ b/migas_server/connections.py @@ -25,8 +25,12 @@ async def get_redis_connection() -> redis.Redis: global MEM_CACHE if MEM_CACHE is None: print("Creating new redis connection") - if (uri := os.getenv("MIGAS_REDIS_URI")) is None: - raise ConnectionError("`MIGAS_REDIS_URI` is not set.") + + # Check for both REDIS_TLS_URL (prioritized) and MIGAS_REDIS_URI + if (uri := os.getenv("REDIS_TLS_URL")) is None and ( + uri := os.getenv("MIGAS_REDIS_URI") + ) is None: + raise ConnectionError("Redis environmental variable is not set.") rkwargs = {'decode_responses': True} if os.getenv("HEROKU_DEPLOYED") and uri.startswith('rediss://'):