mirror of
https://github.com/inventree/InvenTree.git
synced 2025-08-09 21:30:54 +00:00
feat: Add support for cache password in Redis configuration (#10107)
* feat(cache): Add support for cache password in Redis configuration * Add cache password configuration option to documentation * Fix the complaints from CI checks
This commit is contained in:
@@ -37,6 +37,11 @@ def cache_port() -> int:
|
||||
return cache_setting('port', '6379', typecast=int)
|
||||
|
||||
|
||||
def cache_password():
|
||||
"""Return the cache password."""
|
||||
return cache_setting('password', None)
|
||||
|
||||
|
||||
def is_global_cache_enabled() -> bool:
|
||||
"""Check if the global cache is enabled.
|
||||
|
||||
@@ -77,9 +82,17 @@ def get_cache_config(global_cache: bool) -> dict:
|
||||
A dictionary containing the cache configuration options.
|
||||
"""
|
||||
if global_cache:
|
||||
# Build Redis URL with optional password
|
||||
password = cache_password()
|
||||
|
||||
if password:
|
||||
redis_url = f'redis://:{password}@{cache_host()}:{cache_port()}/0'
|
||||
else:
|
||||
redis_url = f'redis://{cache_host()}:{cache_port()}/0'
|
||||
|
||||
return {
|
||||
'BACKEND': 'django_redis.cache.RedisCache',
|
||||
'LOCATION': f'redis://{cache_host()}:{cache_port()}/0',
|
||||
'LOCATION': redis_url,
|
||||
'OPTIONS': {
|
||||
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
||||
'SOCKET_CONNECT_TIMEOUT': cache_setting(
|
||||
|
Reference in New Issue
Block a user