From 8bf9a8c2785073f7dfdc5bad72165eed9320ed4a Mon Sep 17 00:00:00 2001 From: Jelmer Draaijer Date: Mon, 21 Oct 2024 22:07:25 +0200 Subject: [PATCH] Add a default for REDIS_URL and add it as a variable to the settings --- {{cookiecutter.project_slug}}/config/settings/base.py | 6 ++++-- {{cookiecutter.project_slug}}/config/settings/production.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/base.py b/{{cookiecutter.project_slug}}/config/settings/base.py index ec7c500a..97a4c42b 100644 --- a/{{cookiecutter.project_slug}}/config/settings/base.py +++ b/{{cookiecutter.project_slug}}/config/settings/base.py @@ -282,6 +282,8 @@ LOGGING = { "root": {"level": "INFO", "handlers": ["console"]}, } +REDIS_URL = env("REDIS_URL", default="redis://{% if cookiecutter.use_docker == 'y' %}redis{%else%}localhost{% endif %}:6379/0") + {% if cookiecutter.use_celery == 'y' -%} # Celery # ------------------------------------------------------------------------------ @@ -289,9 +291,9 @@ if USE_TZ: # https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-timezone CELERY_TIMEZONE = TIME_ZONE # https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-broker_url -CELERY_BROKER_URL = env("REDIS_URL") +CELERY_BROKER_URL = REDIS_URL # https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-result_backend -CELERY_RESULT_BACKEND = CELERY_BROKER_URL +CELERY_RESULT_BACKEND = REDIS_URL # https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-extended CELERY_RESULT_EXTENDED = True # https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-backend-always-retry diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 6349e17b..d6a9b63d 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -16,6 +16,7 @@ from sentry_sdk.integrations.redis import RedisIntegration from .base import * # noqa: F403 from .base import DATABASES from .base import INSTALLED_APPS +from .base import REDIS_URL {%- if cookiecutter.use_drf == "y" %} from .base import SPECTACULAR_SETTINGS {%- endif %} @@ -37,7 +38,7 @@ DATABASES["default"]["CONN_MAX_AGE"] = env.int("CONN_MAX_AGE", default=60) CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", - "LOCATION": env("REDIS_URL"), + "LOCATION": REDIS_URL, "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", # Mimicing memcache behavior.