[Azure Cache for Redis]Python Djange-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')

科技资讯 投稿 5700 0 评论

[Azure Cache for Redis]Python Djange-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')

问题描述

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://xxxxxxxxx.redis.cache.chinacloudapi.cn:6380/1",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    }
}

但是当部署到AKS中后,发现一直报错 [ERROR][testdjangeredis.py:109]Error while reading from xxxxxxxxx.redis.cache.chinacloudapi.cn:6380 : (104, 'Connection reset by peer'

问题解答

查看Django-redis的官方文档,对 cache backend 中Location的介绍为:

    redis://[:password]@localhost:6379/0
  1. rediss://[:password]@localhost:6380/0
  2. unix://[:password]@/path/to/socket.sock?db=0

支持三种 URL scheme :

    redis://: 普通的 TCP 套接字连接
  • rediss://: SSL 包裹的 TCP 套接字连接
  • unix://: Unix 域套接字连接
    db 查询参数, 例如: redis://localhost?db=0
  • 如果使用 redis:// scheme, 可以直接将数字写在路径中, 例如: redis://localhost/0

 

为了解决以上问题,直接修改Location设置为:rediss://xxxxxxxxx.redis.cache.chinacloudapi.cn:6380/1 即可!

CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": "rediss://xxxxxxxxx.redis.cache.chinacloudapi.cn:6380/1", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", } } }

 

附录一:在机器人ChatGPT中寻求 djange_redis 配置答案

问题一:如何配置djange_redis:

 

问题二:如何设置Djange_redis的超时时间

问题三:如何设置djange_redis的keep_alive

 

问题四:如何启用djange_redis SSL

 

问题五:启用django-redis的SSL并通过6380端口连接示例

 

参考资料

https://django-redis-chs.readthedocs.io/zh_CN/latest/index.html

 

编程笔记 » [Azure Cache for Redis]Python Djange-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')

赞同 (26) or 分享 (0)
游客 发表我的评论   换个身份
取消评论

表情
(0)个小伙伴在吐槽