From c94874e3bee5f0e272a34e5047a7261ba6c9f7fb Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 13 Apr 2026 09:24:24 +1000 Subject: [PATCH] Add redis database index support (#11732) (#11736) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit fc06aa354a664eb147361e2312ee3565dfea77b4) Co-authored-by: Dään <12813916+hartigdan@users.noreply.github.com> --- docs/docs/start/config.md | 1 + src/backend/InvenTree/InvenTree/cache.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/docs/start/config.md b/docs/docs/start/config.md index 37688941f0..2c8fcbd4ed 100644 --- a/docs/docs/start/config.md +++ b/docs/docs/start/config.md @@ -321,6 +321,7 @@ The following cache settings are available: | INVENTREE_CACHE_PORT | cache.port | Cache server port | 6379 | | INVENTREE_CACHE_PASSWORD | cache.password | Cache server password | none | | INVENTREE_CACHE_USER | cache.user | Cache server username | none | +| INVENTREE_CACHE_DB | cache.db | Cache server database index | 0 | | INVENTREE_CACHE_CONNECT_TIMEOUT | cache.connect_timeout | Cache connection timeout (seconds) | 3 | | INVENTREE_CACHE_TIMEOUT | cache.timeout | Cache timeout (seconds) | 3 | | INVENTREE_CACHE_TCP_KEEPALIVE | cache.tcp_keepalive | Cache TCP keepalive | True | diff --git a/src/backend/InvenTree/InvenTree/cache.py b/src/backend/InvenTree/InvenTree/cache.py index 00214610cc..772d1deb03 100644 --- a/src/backend/InvenTree/InvenTree/cache.py +++ b/src/backend/InvenTree/InvenTree/cache.py @@ -50,6 +50,11 @@ def cache_user(): return cache_setting('user', None) +def cache_db(): + """Return the cache database index.""" + return cache_setting('db', 0, typecast=int) + + def is_global_cache_enabled() -> bool: """Check if the global cache is enabled. @@ -95,9 +100,11 @@ def get_cache_config(global_cache: bool) -> dict: user = cache_user() or '' if password: - redis_url = f'redis://{user}:{password}@{cache_host()}:{cache_port()}/0' + redis_url = ( + f'redis://{user}:{password}@{cache_host()}:{cache_port()}/{cache_db()}' + ) else: - redis_url = f'redis://{cache_host()}:{cache_port()}/0' + redis_url = f'redis://{cache_host()}:{cache_port()}/{cache_db()}' keepalive_options = { 'TCP_KEEPCNT': cache_setting('keepalive_count', 5, typecast=int),