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)
相关推荐
goehou19 小时前
Redis 挂掉之后,数据能恢复到哪一步
redis·持久化·aof·rdb
飞奔的瓜牛1 天前
运维工程师 Redis 日常巡检清单与实战注意事项
运维·数据库·redis
IT规划师1 天前
Redis 核心机制 | 发布订阅:Pub_Sub 与 Sharded PubSub
redis·.net
Flynn Liang1 天前
AI Agent Redis 生产踩坑实录:13 类故障的根因、复现与调优
数据库·人工智能·redis·缓存·ai agent·故障分析
Flynn Liang2 天前
RAG 检索性能提升:Redis 向量 + 全文 + 元数据过滤的混合检索实战
数据库·人工智能·redis·缓存·rag·ai agent·智能体
zhoulcc2 天前
Redis 写命令报 MISCONF 错误?RDB 持久化失败的根因定位与彻底修复
redis·持久化·故障排查·rdb·misconf
3095566663 天前
股票数据落库前的去重与主键设计:一次 SQLite 写入实录
java·开发语言·jvm·数据库·redis·python·sqlite