标签:div 链接 color val cat 取数 redis mobile install
pip install django-redis
# 设置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保存到redis SESSION_ENGINE = "django.contrib.sessions.backends.cache" SESSION_CACHE_ALIAS = "session"
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,"_")
标签:div 链接 color val cat 取数 redis mobile install
原文地址:https://www.cnblogs.com/jalen-123/p/13168634.html