@StrGlee
2016-10-20T10:17:39.000000Z
字数 794
阅读 1343
pip install flask-redis
Or if you must use easy_install:
alias easy_install="pip install $1"easy_install flask-redis
Your configuration should be declared within your Flask config. Set the URL of your database like this:
REDIS_URL = "redis://:password@localhost:6379/0"# orREDIS_URL = "unix://[:password]@/path/to/socket.sock?db=0"
from flask import Flaskfrom flask.ext.redis import FlaskRedisapp = Flask(__name__)redis_store = FlaskRedis(app)
or
from flask import Flaskfrom flask.ext.redis import FlaskRedisredis_store = FlaskRedis()def create_app():app = Flask(__name__)redis_store.init_app(app)return app
from ..configs import redis_store@app.route('/')def index():potato = redis_store.get('potato', 'None')if potato is None:potato = 'potato'redis_store.set('potato',potato)return potato