Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```

Expand Down
14 changes: 11 additions & 3 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Loading