From d12d218042ee82ad457ca449704f21756b163e5c Mon Sep 17 00:00:00 2001 From: Donny Winston Date: Thu, 8 Sep 2016 13:44:03 -0700 Subject: [PATCH] Handle and document use of REDIS_URL env var --- README.rst | 2 ++ snappass/main.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 593de48..6793f87 100644 --- a/README.rst +++ b/README.rst @@ -66,6 +66,8 @@ need to change this. `SNAPPASS_REDIS_DB` is the database that you want to use on this redis server. Defaults to db 0 +`REDIS_URL` is optional and, if set, will be used instead of `REDIS_HOST`, `REDIS_PORT`, and `SNAPPASS_REDIS_DB` to configure the Redis client object. For example: redis://username:password@localhost:6379/0 + Docker ------ diff --git a/snappass/main.py b/snappass/main.py index 44abf7a..a4b489d 100644 --- a/snappass/main.py +++ b/snappass/main.py @@ -14,10 +14,14 @@ app.secret_key = os.environ.get('SECRET_KEY', 'Secret Key') app.config.update( dict(STATIC_URL=os.environ.get('STATIC_URL', 'static'))) -redis_host = os.environ.get('REDIS_HOST', 'localhost') -redis_port = os.environ.get('REDIS_PORT', 6379) -redis_db = os.environ.get('SNAPPASS_REDIS_DB', 0) -redis_client = redis.StrictRedis(host=redis_host, port=redis_port, db=redis_db) +if os.environ.get('REDIS_URL'): + redis_client = redis.StrictRedis.from_url(os.environ.get('REDIS_URL')) +else: + redis_host = os.environ.get('REDIS_HOST', 'localhost') + redis_port = os.environ.get('REDIS_PORT', 6379) + redis_db = os.environ.get('SNAPPASS_REDIS_DB', 0) + redis_client = redis.StrictRedis( + host=redis_host, port=redis_port, db=redis_db) time_conversion = { 'week': 604800,