diff --git a/docker-compose.yml b/docker-compose.yml index ff13f16..893b3e3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3' services: web: build: . - command: ["--port", "$PORT", "main:app", "--reload"] + command: "gunicorn main:app --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000 --reload" ports: - "8000:8000" volumes: diff --git a/src/functions.py b/src/functions.py index c6d0e18..d459822 100644 --- a/src/functions.py +++ b/src/functions.py @@ -92,11 +92,16 @@ def redis_connection(): # try connection string, or default to separate REDIS_* env vars if "REDIS_URL" in os.environ: rds = redis.Redis.from_url(os.environ["REDIS_URL"]) - else: + elif "REDIS_PASSWORD" in os.environ: rds = redis.Redis( host=os.environ["REDIS_HOST"], port=os.environ["REDIS_PORT"], - password=os.environ["REDIS_PASSWORD"], + password=os.environ["REDIS_PASSWORD"] + ) + else: + rds = redis.Redis( + host=os.environ["REDIS_HOST"], + port=os.environ["REDIS_PORT"] ) # return connection @@ -152,8 +157,8 @@ def redis_write(app_id, data): data = json.dumps(data) # insert data into cache - rds.set(app_id, data) - rds.expire(app_id, os.environ["CACHE_EXPIRATION"]) + expiration = int(os.environ["CACHE_EXPIRATION"]) + rds.set(app_id, data, ex=expiration) # return succes status return True