flask-session
flask-session
通过这种方式可以把session存入redis。
from flask import Flask,session
from redis import Redis
from flask_session import Session
app = Flask(__name__)
app.config['SESSION_TYPE'] = 'redis'
app.config['SESSION_REDIS'] = Redis(host='127.0.0.1',port='6379')
Session(app)
@app.route('/')
def hello_world():
session['name']='jason'
return 'Hello World!'
@app.route("/index")
def index():
print(session['name'])
return "ok"
if __name__ == '__main__':
app.run()