环境安装

mac下安装redis

  1. brew install redis

调试代码(加Flask)

  1. #coding:utf-8
  2. from flask import Flask,request
  3. import redis
  4. app = Flask(__name__)
  5. @app.route("/")
  6. def hello():
  7. s = request.args.get('name', '')
  8. return s
  9. @app.route("/setredis")
  10. def setredis():
  11. s = request.args.get('name', '')
  12. r.set('name', s) #添加
  13. return("OK") #获取
  14. @app.route("/readredis")
  15. def redisread():
  16. return(r.get('name')) #获取
  17. if __name__ == '__main__':
  18. # 使用零号数据库
  19. r = redis.Redis(host='localhost', port=6379,db=0)
  20. app.run(host='0.0.0.0',port=80)

Redis启动