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)
相关推荐
kaizq1 小时前
AI-MCP-SQLite-SSE本地服务及CherryStudio便捷应用
python·sqlite·llm·sse·mcp·cherry studio·fastmcp
小北方城市网3 小时前
分布式锁实战指南:从选型到落地,避开 90% 的坑
java·数据库·redis·分布式·python·缓存
ohoy3 小时前
RedisTemplate 使用之Zset
java·开发语言·redis
冰冰菜的扣jio7 小时前
Redis缓存中三大问题——穿透、击穿、雪崩
java·redis·缓存
代码游侠7 小时前
应用——智能配电箱监控系统
linux·服务器·数据库·笔记·算法·sqlite
阿里巴巴P8资深技术专家7 小时前
基于 Spring AI 和 Redis 向量库的智能对话系统实践
人工智能·redis·spring
oMcLin8 小时前
如何在 AlmaLinux 9 上配置并优化 Redis 集群,支持高并发的实时数据缓存与快速查询?
数据库·redis·缓存
洛阳纸贵8 小时前
Redis
数据库·redis·缓存
挺6的还10 小时前
13.持久化
redis
沙白猿10 小时前
Redis报错:A bean with that name has already been defined in class path resource
spring boot·redis·mybatis