diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index 061856eef7..b835ed848c 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -19,6 +19,7 @@ from open_webui.env import ( DATABASE_URL, ENV, REDIS_URL, + REDIS_KEY_PREFIX, REDIS_SENTINEL_HOSTS, REDIS_SENTINEL_PORT, FRONTEND_BUILD_DIR, @@ -211,11 +212,13 @@ class PersistentConfig(Generic[T]): class AppConfig: _state: dict[str, PersistentConfig] _redis: Optional[redis.Redis] = None + _redis_key_prefix: str def __init__( - self, redis_url: Optional[str] = None, redis_sentinels: Optional[list] = [] + self, redis_url: Optional[str] = None, redis_sentinels: Optional[list] = [], redis_key_prefix: str = "open-webui" ): super().__setattr__("_state", {}) + super().__setattr__("_redis_key_prefix", redis_key_prefix) if redis_url: super().__setattr__( "_redis", @@ -230,7 +233,7 @@ class AppConfig: self._state[key].save() if self._redis: - redis_key = f"open-webui:config:{key}" + redis_key = f"{self._redis_key_prefix}:config:{key}" self._redis.set(redis_key, json.dumps(self._state[key].value)) def __getattr__(self, key): @@ -239,7 +242,7 @@ class AppConfig: # If Redis is available, check for an updated value if self._redis: - redis_key = f"open-webui:config:{key}" + redis_key = f"{self._redis_key_prefix}:config:{key}" redis_value = self._redis.get(redis_key) if redis_value is not None: diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index d7289ea0b7..6cef23570a 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -324,6 +324,7 @@ ENABLE_REALTIME_CHAT_SAVE = ( #################################### REDIS_URL = os.environ.get("REDIS_URL", "") +REDIS_KEY_PREFIX = os.environ.get("REDIS_KEY_PREFIX", "open-webui") REDIS_SENTINEL_HOSTS = os.environ.get("REDIS_SENTINEL_HOSTS", "") REDIS_SENTINEL_PORT = os.environ.get("REDIS_SENTINEL_PORT", "26379") diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index f933703fba..cb58aec2bf 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -398,6 +398,7 @@ from open_webui.env import ( AUDIT_LOG_LEVEL, CHANGELOG, REDIS_URL, + REDIS_KEY_PREFIX, REDIS_SENTINEL_HOSTS, REDIS_SENTINEL_PORT, GLOBAL_LOG_LEVEL, @@ -577,6 +578,7 @@ app.state.instance_id = None app.state.config = AppConfig( redis_url=REDIS_URL, redis_sentinels=get_sentinels_from_env(REDIS_SENTINEL_HOSTS, REDIS_SENTINEL_PORT), + redis_key_prefix=REDIS_KEY_PREFIX, ) app.state.redis = None