Skip to content

Commit

Permalink
Support/redis config update (#1056)
Browse files Browse the repository at this point in the history
* Update Redis cache configuration with new Heroku-compatible settings

* Update version of Redis used by local dev environments
  • Loading branch information
alxbridge authored Oct 16, 2024
1 parent 3c6f794 commit bd12f56
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ services:
- ./database_dumps:/database_dumps

redis:
image: redis:6
image: redis:7.2
expose:
- 6379
logging:
Expand Down
33 changes: 29 additions & 4 deletions rca/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit bd12f56

Please sign in to comment.