flask-redis
安装
pip install flask-redis
配置
- redis数据库链接格式
REDIS_URL = "redis://:password@localhost:6379/0"
- 导入模块
from flask_redis import FlaskRedis
- 导入数据库配置链接
REDIS_URL = "redis://:password@localhost:6379/0"
app.config["REDIS_URL"] = REDIS_URL
- 实例化对象并初始化
redis_client = FlaskRedis()
redis_client.init_app(app)
- 设置并获取值
@app.route('/get')
def redis_get():return redis_client.get('Hello World!')@app.route('/')
def redis_set():redis_client['Hello World!'] = 'Hello World!'return "设置redis值"