diff --git a/funding/factory.py b/funding/factory.py index fffce45..6387699 100644 --- a/funding/factory.py +++ b/funding/factory.py @@ -4,6 +4,7 @@ from flask import Flask from flask_caching import Cache from flask_session import Session from flask_sqlalchemy import SQLAlchemy +import redis app = None cache = None @@ -17,9 +18,13 @@ def _setup_cache(app: Flask): cache_config = { "CACHE_TYPE": "redis", "CACHE_DEFAULT_TIMEOUT": 60, - "CACHE_KEY_PREFIX": "wow_cache_" + "CACHE_KEY_PREFIX": "wow_cache_", + "CACHE_REDIS_PORT": settings.REDIS_PORT } + if settings.REDIS_PASSWD: + cache_config["CACHE_REDIS_PASSWORD"] = settings.REDIS_PASSWD + app.config.from_mapping(cache_config) cache = Cache(app) @@ -27,6 +32,7 @@ def _setup_cache(app: Flask): def _setup_session(app: Flask): app.config['SESSION_TYPE'] = 'redis' app.config['SESSION_COOKIE_NAME'] = 'bar' + app.config['SESSION_REDIS'] = redis.from_url(settings.REDIS_URI) Session(app) # defaults to timedelta(days=31) diff --git a/settings.py_example b/settings.py_example index 7e5efaf..a984164 100644 --- a/settings.py_example +++ b/settings.py_example @@ -22,6 +22,10 @@ SESSION_PREFIX = os.environ.get('{coincode}_SESSION_PREFIX', 'session:').format( REDIS_HOST = os.environ.get('REDIS_HOST', '127.0.0.1') REDIS_PORT = int(os.environ.get('REDIS_PORT', 6379)) REDIS_PASSWD = os.environ.get('REDIS_PASSWD', None) +REDIS_URI = "redis://" +if REDIS_PASSWD: + REDIS_URI += f":{REDIS_PASSWD}" +REDIS_URI += f"@{REDIS_HOST}:{REDIS_PORT}" BIND_HOST = os.environ.get("BIND_HOST", "0.0.0.0") if not BIND_HOST: