Django redis配置

python 复制代码
CACHES = {
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://127.0.0.1:6379/0',
        'OPTIONS': {
            'CLIENT_CLASS': 'django_redis.client.DefaultClient',
            'CONNECTION_POOL_KWARGS':{
                'decode_responses':True
            }
        }
    }
}

使用

python 复制代码
 from django_redis import get_redis_connection
    # 默认连接配置文件中的库
    redis_conn = get_redis_connection()
    #校验key是否存在
    if not redis_conn.exists(f'activation_{username}'):
        context = {
            'code': 10011,
            'error': '激活用户不存在'
        }
        return JsonResponse(context)
    rand = redis_conn.get(f'activation_{username}')
    code2 = md5(username + rand)
相关推荐
christine-rr5 小时前
linux常用命令(4)——压缩命令
linux·服务器·redis
凯子坚持 c7 小时前
精通 Redis list:使用 redis-plus-plus 的现代 C++ 实践深度解析
c++·redis·list
weixin_456904277 小时前
跨域(CORS)和缓存中间件(Redis)深度解析
redis·缓存·中间件
百锦再8 小时前
[特殊字符] Python在CentOS系统执行深度指南
开发语言·python·plotly·django·centos·virtualenv·pygame
波波烤鸭8 小时前
Redis 高可用实战源码解析(Sentinel + Cluster 整合应用)
数据库·redis·sentinel
MarkHard12316 小时前
如何利用redis使用一个滑动窗口限流
数据库·redis·缓存
island131418 小时前
【Redis#10】渐进式遍历 | 数据库管理 | redis_cli | RES
数据库·redis·bootstrap
心想事成的幸运大王18 小时前
Redis的过期策略
数据库·redis·缓存
计算机编程小央姐18 小时前
跟上大数据时代步伐:食物营养数据可视化分析系统技术前沿解析
大数据·hadoop·信息可视化·spark·django·课程设计·食物
诗句藏于尽头19 小时前
Django模型与数据库表映射的两种方式
数据库·python·django