django 框架中应用 redis 集群(亲测)

淩亂°似流年 2023-10-06 11:37 137阅读 0赞
  1. 在 setting.py 中添加 :

    CACHES = {

    1. 'default': {
    2. 'BACKEND': 'django_redis.cache.RedisCache',
    3. 'LOCATION': redis主机ip + ':' + 端口号,
    4. "OPTIONS": {
    5. "CLIENT_CLASS": "django_redis.client.DefaultClient",
    6. },
    7. },

    }

  1. 2. redis 主机中的配置修改:
  2. bind 127.0.0.1 ===》 bind 主机ip
  3. 3. 重启redis
  4. ps aux | grep redis
  5. kill -9 redis-pid
  6. redis-server redis.conf
  7. 4. redis 客户端的连接
  8. redis-cli -h redis主机ip -p 端口号
  9. 5. django 中,redis 原生客户端的使用:
  10. from django_redis import get_redis_connection
  11. con = get_redis_connection("default")
  12. con.set('key' 'value', 2*60) # 2 分钟超时
  13. con.get('key')

转载于:https://www.cnblogs.com/shihaokiss/p/8466915.html

来源:https://blog.csdn.net/weixin_34161032/article/details/94210359

发表评论

表情:
评论列表 (有 0 条评论,137人围观)

还没有评论,来说两句吧...

相关阅读