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)
相关推荐
IT大白鼠3 天前
Redis 系列 · 第 01 篇——认知入门:Redis 是什么
redis·nosql
彧azz3 天前
Linux 环境下 Redis 学习总结:数据类型、持久化、锁、事务、主从与缓存问题
linux·redis·笔记·学习·面试
kybs19913 天前
全球灾害数据分析可视化 毕业设计-附源码66794
vue.js·spring boot·mysql·安全·django·c#·asp.net
醇氧3 天前
Python`__pycache__` 被 Git 跟踪的排查与解决
python·django
lbb 小魔仙3 天前
OpenClaw + cpolar 实战:远程 NAS、分享小游戏、RDP,再配置公网 AI 入口
数据库·人工智能·redis·oracle·prometheus
夕除3 天前
redis--018
redis
两锭子3 天前
Redis基础
redis
烟沙九洲3 天前
Redis 缓存穿透、缓存击穿、缓存雪崩
数据库·redis
字节探索3 天前
Redis 只会当缓存用?这 10 大实战场景,让你的系统快到飞起
redis·后端
于樱花森上飞舞3 天前
【Redis】哨兵详解
java·开发语言·数据库·redis