Skip to content

Commit

Permalink
FIX: Check for REDIS_TLS_URL before MIGAS_REDIS_URI (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgxd authored Aug 15, 2022
1 parent 4068a73 commit 590f1f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions migas_server/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://'):
Expand Down

0 comments on commit 590f1f4

Please sign in to comment.