diff --git a/docker-compose.yml b/docker-compose.yml index 7280fc6e4..0d8a0f8c4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -79,7 +79,7 @@ services: - ./database_dumps:/database_dumps redis: - image: redis:6 + image: redis:7.2 expose: - 6379 logging: diff --git a/rca/settings/base.py b/rca/settings/base.py index 94e34ddfe..91434808e 100644 --- a/rca/settings/base.py +++ b/rca/settings/base.py @@ -176,15 +176,40 @@ # usually use Redis in production and database backend on staging and dev. In # order to use database cache backend you need to run # "django-admin createcachetable" to create a table for the cache. - +# # Do not use the same Redis instance for other things like Celery! -if "REDIS_URL" in env: + +# Prefer the TLS connection URL over non +REDIS_URL = env.get("REDIS_TLS_URL", env.get("REDIS_URL")) + +if REDIS_URL: + connection_pool_kwargs = {} + + if REDIS_URL.startswith("rediss"): + # Heroku Redis uses self-signed certificates for secure redis conections. https://stackoverflow.com/a/66286068 + # When using TLS, we need to disable certificate validation checks. + connection_pool_kwargs["ssl_cert_reqs"] = None + + redis_options = { + "IGNORE_EXCEPTIONS": True, + "SOCKET_CONNECT_TIMEOUT": 2, # seconds + "SOCKET_TIMEOUT": 2, # seconds + "CONNECTION_POOL_KWARGS": connection_pool_kwargs, + } + CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", - "LOCATION": env["REDIS_URL"], - } + "LOCATION": REDIS_URL + "/0", + "OPTIONS": redis_options, + }, + "renditions": { + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": REDIS_URL + "/1", + "OPTIONS": redis_options, + }, } + DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS = True else: CACHES = { "default": {