• 以组件的方式,添加redis_cache


    settings.py中文件内设置如下:

      

    CACHES = {
    'default':{
    'BACKEND':'django_redis.cache.RedisCache',
    'LOCATION':'redis://127.0.0.1:6379',
    'OPTIONS':{
    'CLIENT_CLASS':'django_redis.client.DefaultClient',
    'CONNECTION_POOL_KWARGS':{'max_connections':1000}
    # 'PASSWORD':"密码"
    }
    },
    'sniffcpcssocks':{
    'BACKEND':'django_redis.cache.RedisCache',
    'LOCATION':'redis://127.0.0.1:6379',
    'OPTIONS':{
    'CLIENT_CLASS':'django_redis.client.DefaultClient',
    'CONNECTION_POOL_KWARGS':{'max_connections':1000}
    # 'PASSWORD':"密码"
    }
    }
    }

    views.py文件中导入模块

    from django_redis import get_redis_connection
    from django.views.decorators.cache import cache_page

    def showredispool():

    conn = get_redis_connection('sniffcpcssocks')

    conn.hset('name','pwd','nickname')

    return HttpResponse('....')

    from django.views.decorators.cache import cache_page
    #此乃装饰器方法设置缓存的默认生命周期的方法
    @cache_page(60*15)
    # 缓存存在时间60秒*15
    def showredispool(request):

    conn = get_redis_connection('sniffcpcssocks')

    conn.hset('name','pwd','nickname')

    return HttpResponse('....')


  • 相关阅读:
    mmap和MappedByteBuffer
    Linux命令之TOP
    Linux命令之ss
    MySql Cluster
    HttpClient配置
    注释驱动的 Spring cache 缓存介绍
    Spring AOP 实现原理与 CGLIB 应用
    AspectJ本质剖析
    B树
    imagick-3.1.0RC2 安装错误
  • 原文地址:https://www.cnblogs.com/saintdingspage/p/8974625.html
Copyright © 2020-2023  润新知