refactor: update Redis configuration for caching and Celery broker
This commit is contained in:
+13
-12
@@ -271,13 +271,21 @@ if DEBUG:
|
||||
"http://127.0.0.1:8080",
|
||||
]
|
||||
|
||||
# Redis host configuration
|
||||
redis_url_str = os.environ.get("REDIS_URL", "")
|
||||
if redis_url_str.startswith("redis://"):
|
||||
# extract host from redis://host:port/db
|
||||
REDIS_HOST = redis_url_str[8:].split("/")[0].split(":")[0]
|
||||
elif redis_url_str.startswith("rediss://"):
|
||||
# extract host from rediss://host:port/db
|
||||
REDIS_HOST = redis_url_str[9:].split("/")[0].split(":")[0]
|
||||
else:
|
||||
REDIS_HOST = os.environ.get("REDIS_HOST", "127.0.0.1")
|
||||
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.memcached.PyMemcacheCache",
|
||||
"LOCATION": f'{os.environ.get("MEMCACHE_HOST", "127.0.0.1")}:11211',
|
||||
#'OPTIONS': {
|
||||
# 'server_max_value_length': 1024 * 1024 * 10
|
||||
# }
|
||||
"BACKEND": "django.core.cache.backends.redis.RedisCache",
|
||||
"LOCATION": f"redis://{REDIS_HOST}:6379/1",
|
||||
},
|
||||
"filesystem": {
|
||||
"BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
|
||||
@@ -381,13 +389,6 @@ CIMAR_USERNAME = ""
|
||||
CIMAR_PASSWORD = ""
|
||||
|
||||
# Celery settings
|
||||
redis_url_str = os.environ.get("REDIS_URL", "")
|
||||
if redis_url_str.startswith("redis://"):
|
||||
# extract host from redis://host:port/db
|
||||
REDIS_HOST = redis_url_str[8:].split("/")[0].split(":")[0]
|
||||
else:
|
||||
REDIS_HOST = os.environ.get("REDIS_HOST", "127.0.0.1")
|
||||
|
||||
CELERY_BROKER_URL = f"redis://{REDIS_HOST}:6379"
|
||||
CELERY_RESULT_BACKEND = f"redis://{REDIS_HOST}:6379"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user