当前位置: 首页 > 工具软件 > flask-session > 使用案例 >

flask-session session_id 和key与value的在redis的保存方式

乐正意智
2023-12-01

实验代码:

# -*- coding: utf-8 -*-

"""
    Hello
    ~~~~~


    Flask-Session demo.


    :copyright: (c) 2014 by Shipeng Feng.
    :license: BSD, see LICENSE for more details.
"""
from flask import Flask, session
from flask.ext.session import Session




SESSION_TYPE = 'redis'




app = Flask(__name__)
app.config.from_object(__name__)
Session(app)




@app.route('/set/')
def set():
    session['key1'] = 'value1'
    session['key2'] = 'value2'
    return 'ok'




@app.route('/get/')
def get():
    return session.get('key1', 'not set')+session.get('key2', 'not set')




if __name__ == "__main__":

    app.run(host='0.0.0.0',threaded=True,debug=True)

-----------------------------------------------------------------------

用redis-cli观察


 类似资料: