python项目_redis使用,,1.下载安装djan
python项目_redis使用,,1.下载安装djan
1.下载安装django-redis
pip install django-redis
2.settings.dev中添加配置
# 设置redis缓存CACHES = { # 默认缓存 "default": { "BACKEND": "django_redis.cache.RedisCache", # 项目上线时,需要调整这里的路径 "LOCATION": "redis://127.0.0.1:6379/0", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", } }, # 提供给xadmin或者admin的session存储 "session": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": "redis://127.0.0.1:6379/1", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", } }, # 提供存储短信验证码 "sms_code":{ "BACKEND": "django_redis.cache.RedisCache", "LOCATION": "redis://127.0.0.1:6379/2", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", } }}# 设置xadmin用户登录时,登录信息session保存到redisSESSION_ENGINE = "django.contrib.sessions.backends.cache"SESSION_CACHE_ALIAS = "session"
3.使用redis
from django_redis import get_redis_connection// 链接redis数据库redis_conn = get_redis_connection("default")
redis_sms = redis_conn.get("sms_%s" % mobile) #从redis中获取数据,或者删除数据等操作
# 3. 保存短信验证码到redis ,将数据保存到redis中
redis_conn.setex("sms_%s" % mobile, constants.SMS_EXPIRE_TIME, sms_code)
redis_conn.setex("mobile_%s" % mobile, constants.SMS_INTERVAL_TIME,"_")
python项目_redis使用
相关内容
- python常见命令,python代码命令大全,http://www
- windows下手动安装pyinstaller(python2.7),,1、首先,安装py
- pythonlinux配置环境变量,,虚拟环境为什么要装虚
- python-??????????????????,,?????????
- python——文件处理,,1.文件处理f =
- Python初学心得体会,,初学程序编程对于一个
- python 将一个列表乱序,,import ran
- python_读取 doc,docx,pdf,,#!/usr/bin
- Linux 安装Python3,,编译安装python
- Python-手动安装第三方包,,Python 安装第
评论关闭