![](/img/trans.png)
[英]How do I successfully connect Django to Azure Cache for Redis?
[英]Azure redis cache and Django setup
我在 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。
"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后,output:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.