【问题标题】:Azure redis cache and Django setupAzure redis 缓存和 Django 设置
【发布时间】:2022-11-25 12:24:26
【问题描述】:

我在 Django 中使用 django-redis 添加 Azure redis 缓存,但我遇到了连接问题,我添加了密钥密码和主机名以及端口,但没有成功,我收到此错误:

django_redis.exceptions.ConnectionInterrupted: Redis ConnectionError: Error while reading from myhostname.net:6380 : (104, 'Connection reset by peer')

我尝试阅读现有的答案但没有运气。

这是我在 Django settings.py 中的内容:

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": os.getenv('REDIS_URL'),
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
            'SSL': True,
            "PASSWORD": os.getenv('REDIS_PASSWORD'),
        }
    }
}

REDIS_URL 是这样的:

REDIS_URL=rediss://myhostname.net:6380

以及REDIS_PASSWORD提供的密码。

我可能遗漏了什么,我正在 Digitalocean 上测试它,我激活了 SSL。

【问题讨论】:

    标签: django redis digital-ocean azure-redis-cache


    【解决方案1】:
    • 使用以下格式的 Location 标签时,我没有收到连接错误
    "LOCATION":'rediss://:<Your password>@<name of the redis in azure>.redis.cache.windows.net:6380/0'
    

    完整代码:

    CACHES = {
        'default':{
                    'BACKEND':'django_redis.cache.RedisCache',
                    "LOCATION":'rediss://:<Your password>@<name of the redis in azure>.redis.cache.windows.net:6380/0',
                    'OPTION':{
                                'CLIENT_CLASS': 'django_redis.client.DefaultClient',
                                'PASSWORD':'<Your password>',
                                'SSL': True
                            }
                }
    }
    

    启动Django app后,输出:

    【讨论】:

      猜你喜欢
      • 2014-07-14
      • 2022-01-10
      • 2015-05-21
      • 1970-01-01
      • 2017-01-24
      • 1970-01-01
      • 2015-04-29
      • 2016-09-10
      • 2019-05-17
      相关资源
      最近更新 更多