Redis cache and celery, avoid overflow

This commit is contained in:
Luciano Gervasoni
2025-09-03 23:07:03 +02:00
parent 569e7d4676
commit a9074f45b5
5 changed files with 46 additions and 20 deletions

View File

@@ -97,9 +97,10 @@ DATABASES = {
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://{}:{}".format(
os.environ.get("REDIS_HOST", "localhost"),
os.environ.get("REDIS_PORT", 6379)
"LOCATION": "redis://{}:{}/{}".format(
os.environ.get("REDIS_CACHE_HOST", "localhost"),
os.environ.get("REDIS_CACHE_PORT", 6379),
2 # DB for Caching
),
"OPTIONS": {
"MEMCACHE_MAX_KEY_LENGTH": 2048,
@@ -108,13 +109,12 @@ CACHES = {
}
}
# Celery configuration
CELERY_BROKER_URL = 'redis://{}:{}/{}'.format(os.environ.get("REDIS_HOST", "localhost"), os.environ.get("REDIS_PORT", 6379), os.environ.get("REDIS_DB", 0))
CELERY_RESULT_BACKEND = 'redis://{}:{}/{}'.format(os.environ.get("REDIS_HOST", "localhost"), os.environ.get("REDIS_PORT", 6379), os.environ.get("REDIS_DB_RESULTS", 1))
CELERY_BROKER_URL = 'redis://{}:{}/{}'.format(os.environ.get("REDIS_CELERY_HOST", "localhost"), os.environ.get("REDIS_CELERY_PORT", 6379), 0)
CELERY_RESULT_BACKEND = 'redis://{}:{}/{}'.format(os.environ.get("REDIS_CELERY_HOST", "localhost"), os.environ.get("REDIS_CELERY_PORT", 6379), 1)
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_EXPIRES = 3600 # Auto clean results after 1 hour
# Celery Beat scheduler (required for django-celery-beat to work)
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers.DatabaseScheduler'