2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-05-09 03:03:41 +00:00

Add redis database index support (#11732) (#11736)

(cherry picked from commit fc06aa354a)

Co-authored-by: Dään <12813916+hartigdan@users.noreply.github.com>
This commit is contained in:
github-actions[bot]
2026-04-13 09:24:24 +10:00
committed by GitHub
parent 72cb873d8d
commit c94874e3be
2 changed files with 10 additions and 2 deletions
+1
View File
@@ -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 |
+9 -2
View File
@@ -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),