use custom redis

This commit is contained in:
purerosefallen 2019-07-31 20:16:36 +08:00
parent df272f60f7
commit 1554f20583
No known key found for this signature in database
GPG Key ID: E6D78C90943A3185
3 changed files with 21 additions and 9 deletions

View File

@ -17,7 +17,7 @@ WORKDIR /taiko-web
#python virtualenv #python virtualenv
RUN bash -c 'virtualenv -p /usr/bin/python2 .venv2 && \ RUN bash -c 'virtualenv -p /usr/bin/python2 .venv2 && \
source .venv2/bin/activate && \ source .venv2/bin/activate && \
pip install Flask Flask-Caching ffmpy gunicorn && \ pip install Flask Flask-Caching ffmpy gunicorn redis && \
deactivate' deactivate'
RUN bash -c 'virtualenv -p /usr/bin/python3 .venv3 && \ RUN bash -c 'virtualenv -p /usr/bin/python3 .venv3 && \

22
app.py
View File

@ -10,13 +10,6 @@ from flask import Flask, g, jsonify, render_template, request, abort, redirect
from flask_caching import Cache from flask_caching import Cache
from ffmpy import FFmpeg from ffmpy import FFmpeg
app = Flask(__name__)
try:
app.cache = Cache(app, config={'CACHE_TYPE': 'redis'})
except RuntimeError:
import tempfile
app.cache = Cache(app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': tempfile.gettempdir()})
DATABASE = 'taiko.db' DATABASE = 'taiko.db'
DEFAULT_URL = 'https://github.com/purerosefallen/taiko-web-another/' DEFAULT_URL = 'https://github.com/purerosefallen/taiko-web-another/'
@ -70,6 +63,21 @@ def get_version():
return version return version
app = Flask(__name__)
try:
config = get_config()
app.cache = Cache(app, config={
'CACHE_TYPE': 'redis',
'CACHE_REDIS_HOST': config['redis_host'],
'CACHE_REDIS_PORT': config['redis_port'],
'CACHE_REDIS_PASSWORD': config['redis_password'],
'CACHE_REDIS_DB': config['redis_db']
})
print("redis enabled")
except RuntimeError:
print("redis disabled")
import tempfile
app.cache = Cache(app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': tempfile.gettempdir()})
@app.teardown_appcontext @app.teardown_appcontext
def close_connection(exception): def close_connection(exception):

View File

@ -1,4 +1,8 @@
{ {
"songs_baseurl": "", "songs_baseurl": "",
"assets_baseurl": "" "assets_baseurl": "",
"redis_host": "127.0.0.1",
"redis_port": 6379,
"redis_password": "",
"redis_db": 0
} }