Skip to content

Commit

Permalink
Go back to using django-redis (#4931)
Browse files Browse the repository at this point in the history
We are seeing 500 errors with Django RedisCache when the redis connection fails.
Go back to using django-redis using IGNORE_EXCEPTIONS until we can resolve the
problem with Django RedisCache.
  • Loading branch information
samdoran authored Feb 21, 2024
1 parent 014f0fa commit cb49aa3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ django-environ = ">=0.4"
django-extensions = ">=2.2"
django-filter = ">=2.2"
django-prometheus = ">=1.1"
django-redis = ">=4.10"
django-tenants = ">=3.4"
djangorestframework = ">=3.14.0"
djangorestframework-csv = ">=2.1"
Expand Down
10 changes: 9 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion koku/koku/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.core.cache import caches
from django.core.cache.backends.dummy import DummyCache
from django.core.cache.backends.locmem import LocMemCache
from django.core.cache.backends.redis import RedisCache
from django_redis.cache import RedisCache
from redis import Redis

from api.common import log_json
Expand Down
20 changes: 12 additions & 8 deletions koku/koku/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,29 +237,33 @@
else:
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}",
"KEY_FUNCTION": "django_tenants.cache.make_key",
"REVERSE_KEY_FUNCTION": "django_tenants.cache.reverse_key",
"TIMEOUT": 3600, # 1 hour default
"TIMEOUT": 3_600, # 1 hour default
"OPTIONS": {
"health_check_interval": REDIS_HEALTH_CHECK_INTERVAL,
"retry_on_timeout": REDIS_RETRY_ON_TIMEOUT,
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"IGNORE_EXCEPTIONS": True,
"MAX_ENTRIES": 1_000,
"CONNECTION_POOL_CLASS_KWARGS": REDIS_CONNECTION_POOL_KWARGS,
},
},
"rbac": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": f"redis://{REDIS_HOST}:{REDIS_PORT}/1",
"TIMEOUT": ENVIRONMENT.get_value("RBAC_CACHE_TIMEOUT", default=300),
"OPTIONS": {
"health_check_interval": REDIS_HEALTH_CHECK_INTERVAL,
"retry_on_timeout": REDIS_RETRY_ON_TIMEOUT,
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"IGNORE_EXCEPTIONS": True,
"MAX_ENTRIES": 1_000,
"CONNECTION_POOL_CLASS_KWARGS": REDIS_CONNECTION_POOL_KWARGS,
},
},
"worker": {
"BACKEND": "django.core.cache.backends.db.DatabaseCache",
"LOCATION": "worker_cache_table",
"TIMEOUT": 86400, # 24 hours
"TIMEOUT": 86_400, # 24 hours
},
}

Expand Down

0 comments on commit cb49aa3

Please sign in to comment.