进入虚拟环境 workon django
下载 pip install redis
导包
from redis import *
r = StrictRedis(host="localhost", port=6379, db=0) #默认参数
r = StrictRedis() #简写
r.函数名参数和redis命令和参数类似.
2.django
pip install django-redis-sessions
进入django中的setting.py 添加如下配置
SESSION_ENGINE = ‘redis_sessions.session‘
SESSION_REDIS_HOST = ‘localhost‘
SESSION_REDIS_PORT = 6379
SESSION_REDIS_DB = 0
SESSION_REDIS_PASSWORD = ‘‘
SESSION_REDIS_PREFIX = ‘session‘
原文地址:https://www.cnblogs.com/yangzixiong/p/11680149.html
时间: 2024-10-08 17:50:50