使用Elastic BeanStalk + Django设置ElastiCache Redis [英] Setting up ElastiCache Redis with Elastic BeanStalk + Django
问题描述
另一个stackoverflow answer 说,您需要进行设置一个lasticache.config文件,以使用ElastiCache自动创建Redis服务器.
Another stackoverflow answer says you need to set up a elasticache.config file to create Redis servers with ElastiCache automatically.
但是,我可以仅在AWS(Elasticache)上创建Redis实例并将其端点添加到Django设置中吗?例如,使用 Django-redis :
However, can I just create a Redis instance on AWS (Elasticache) and add its endpoint into Django settings? Eg, with Django-redis:
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://<REDIS AWS ENDPOINT AND PORT HERE>",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
}
}
我怀疑以上情况可能会导致多个beantalk服务器实例出现问题.鉴于此,鉴于有一个显式编写的用于与AWS Elasticache for Memcache接口的Django包,我很想使用MemCache而不是Redis:
I suspect the above could cause trouble with multiple beanstalk server instances. Given this, I am tempted to use MemCache and not Redis, given that there is a Django package written explicitly for interfacing with AWS Elasticache for Memcache: django-elasticache.
谢谢, 安迪.
推荐答案
简短答案:是.
长答案:我还没有使用过Elastic Beanstalk,但是我可以确认,如果您在ElastiCache中创建Redis 实例(即:禁用集群模式),则可以在django-redis
下正常工作.只需将primary_endpoint
插入您发布的Django配置中即可.
Long answer: I have not used Elastic Beanstalk, however I can confirm that if you create a Redis instance (that is: cluster mode disabled) in ElastiCache it will work fine with django-redis
. Just insert the primary_endpoint
into the Django config you posted.
如果您打算使用只读副本,请按以下步骤进行设置:
N.B. If you plan to use read replicas, set it up like this:
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": [
"redis://<MASTER ENDPOINT>",
"redis://<SLAVE ENDPOINT>",
]
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
}
}
但是,如果启动Redis 集群,则不能使用香草django-redis
.您必须按照redis-py-cluster
https://github.com/niwinz/django-redis/issues/208#issuecomment-352585533"rel =" noreferrer>在这篇文章中.复制到这里:
If you spin up a Redis cluster however, you cannot use vanilla django-redis
. You'll have to use use redis-py-cluster
with it as described in this post. Replicated here:
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://XXX.YYY.ZZZ.cache.amazonaws.com/0',
'OPTIONS': {
'REDIS_CLIENT_CLASS': 'rediscluster.RedisCluster',
'CONNECTION_POOL_CLASS': 'rediscluster.connection.ClusterConnectionPool',
'CONNECTION_POOL_KWARGS': {
'skip_full_coverage_check': True # AWS ElasticCache has disabled CONFIG commands
}
}
}
}
这篇关于使用Elastic BeanStalk + Django设置ElastiCache Redis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!