support for custom redis port
This commit is contained in:
parent
401c26e85b
commit
bece1a90e7
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue