@StrGlee
2016-10-20T18:17:39.000000Z
字数 794
阅读 1106
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"
# or
REDIS_URL = "unix://[:password]@/path/to/socket.sock?db=0"
from flask import Flask
from flask.ext.redis import FlaskRedis
app = Flask(__name__)
redis_store = FlaskRedis(app)
or
from flask import Flask
from flask.ext.redis import FlaskRedis
redis_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