zoukankan      html  css  js  c++  java
  • django+SQLite搭建轻量级个人博客(十三)连接redis的配置和操作

    1、setting.py

    CACHES = {
    "default": {
    "BACKEND": "django_redis.cache.RedisCache",
    "LOCATION": "redis://ip:port/0",
            "OPTIONS": {
    "CLIENT_CLASS": "django_redis.client.DefaultClient",
    "CONNECTION_POOL_KWARGS": {"max_connections": 100, 'decode_responses': True},
    "PASSWORD": "12345678", # 密码
    }
    },
      
      #可设置多个redis。。。。。。
    "redis2": {
    "BACKEND": "django_redis.cache.RedisCache",
    "LOCATION": "redis://ip:port/0",
    "OPTIONS": {
    "CLIENT_CLASS": "django_redis.client.DefaultClient",
    "CONNECTION_POOL_KWARGS": {"max_connections": 100, 'decode_responses': True},
    "PASSWORD": "12345678", # 密码
    }
    }
    }

    2、连接redis

    import django_redis
    redis = django_redis.get_redis_connection() #默认使用default,setting里面设置
    # redis = django_redis.get_redis_connection('redis2') #使用设置里面其他的redis数据库
    redis.set(token,pickle.dumps(user),const.token_expire) #pickle模块将对象转换成字符串序列,token自己定义此处省略
    模板看起来是不是太过冰冷
  • 相关阅读:
    linux基础命令之一
    Chrome 控制台使用大全
    移动端效果 — 页面引入在线视频
    移动端——简单计分表单
    JS操作cookie
    移动端页面字体——rem的使用
    Highcharts 使用总结
    CSS水平居中
    python学习 day2
    python学习 day1
  • 原文地址:https://www.cnblogs.com/xuexizongjie/p/11817193.html
Copyright © 2011-2022 走看看