更新时间:2022-03-07 08:48:09
Django是否在与Redis容器链接的单独容器中运行?如果是这样,您应该具有一些环境变量以及Django应该用来连接到Redis容器的Ip和端口。将BROKER_URL设置为使用redis Ip和port env vars,您就应该做生意。
Is Django running in a seperate container that is linked to the Redis container? If so, you should have some environment variables with the Ip and port that Django should use to connect to the Redis container. Set BROKER_URL to use the redis Ip and port env vars and you should be in business. Ditto for RESULT_BACKEND.
环境变量的参考文档在这里: Docker Compose文档
Reference docs for the env vars are here: Docker Compose docs
以下是一些示例代码,说明了我们如何在OfferUp的一个项目中使用自动添加的env var:
Here's some example code for how we use the automatically added env vars in one of our projects at OfferUp:
BROKER_TRANSPORT = "redis"
_REDIS_LOCATION = 'redis://{}:{}'.format(os.environ.get("REDIS_PORT_6379_TCP_ADDR"), os.environ.get("REDIS_PORT_6379_TCP_PORT"))
BROKER_URL = _REDIS_LOCATION + "/0"
CELERY_RESULT_BACKEND = _REDIS_LOCATION + "/1"