环境安装
mac下安装redis
brew install redis
调试代码(加Flask)
#coding:utf-8
from flask import Flask,request
import redis
app = Flask(__name__)
@app.route("/")
def hello():
s = request.args.get('name', '')
return s
@app.route("/setredis")
def setredis():
s = request.args.get('name', '')
r.set('name', s) #添加
return("OK") #获取
@app.route("/readredis")
def redisread():
return(r.get('name')) #获取
if __name__ == '__main__':
# 使用零号数据库
r = redis.Redis(host='localhost', port=6379,db=0)
app.run(host='0.0.0.0',port=80)