mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[GH-ISSUE #16157] issue: Backend cannot connect to Redis in cluster mode #33335
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @erhhung on GitHub (Jul 30, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/16157
Check Existing Issues
Installation Method
Other
Open WebUI Version
v0.6.18
Ollama Version (if applicable)
No response
Operating System
Docker image: Debian 12
Browser (if applicable)
No response
Confirmation
README.md.Expected Behavior
Open WebUI backend currently supports connections to Redis in two modes only:
Single non-HA instance, either using the default deployment (by Helm chart) or explicitly referenced by the
REDIS_URLandWEBSOCKET_REDIS_URLenvironment variables.In this mode, the actual client classes used from the
redis-pypackage isredis.Redisandredis.asyncio.client.Redis.HA mode using Sentinels, either deployed alongside Open WebUI by the
redis-clustersubchart or explicitly referenced by the sameREDIS_URLvariables as above as well asREDIS_SENTINEL_HOSTSandWEBSOCKET_SENTINEL_HOSTS.In this mode, the actual client classes used (see
/backend/open_webui/utils/redis.py) isredis.sentinel.Sentinelandredis.asyncio.sentinel.Sentinel.It does NOT currently support the third mode, clustering (using sharding), whereby proper support on the client side is provided by the
redis.cluster.RedisClusterandredis.asyncio.cluster.RedisClusterclasses.Without using the proper client classes when connecting to Redis deployed in cluster mode, websocket cannot successfully connect.
Actual Behavior
The server throws a
redis.exceptions.MovedErrorexception.Steps to Reproduce
REDIS_URLandWEBSOCKET_REDIS_URLenvironment variables. The host specified in the URL can be any host in the cluster.Logs & Screenshots
Additional Information
No response
@tjbck commented on GitHub (Aug 4, 2025):
Addressed
@sanchitbhavsar commented on GitHub (Aug 13, 2025):
@erhhung how should be the
REDIS_KEY_PREFIXdefined in the cluster mode. I am running on single node currently and I add kez variable for this{open-webui}but I believe in cluster we have key-value pair to be passed. Could you please let me know, thanks.@rgaricano commented on GitHub (Aug 13, 2025):
https://github.com/open-webui/open-webui/discussions/15834
@sanchitbhavsar commented on GitHub (Aug 13, 2025):
@rgaricano so this should work
{open-webui}:config:*correct?@rgaricano commented on GitHub (Aug 13, 2025):
I think so, but I don't know so much about redis clustering.
I think that when clustering the difference is in the redis-url, and then it's needed that redis request is in "cluster mode" to discover the host. That funcionality was added recently.
Sure that Erhhung can respond, but ask it in the refered thread too, there are people that have differents redis deployments with deep knowledge about.
@erhhung commented on GitHub (Aug 19, 2025):
@sanchitbhavsar If you have a Redis HA setup with more than one host, OR sharing Redis between multiple Open WebUI instances, you shouldn't set
REDIS_KEY_PREFIXto the same{open-webui}value, i.e., use Redis's curly braces hash tag feature, as that would always use "open-webui" to hash to the same one slot—you'd use different prefixes for each Open WebUI instance so that they act as namespaces, and let the key hashing mechanism distribute storage across all nodes—the reason why you even have a cluster.EDIT: I'm not sure if Open WebUI is using multi-key operations like
MGET,MSET,EVAL,MULTI/EXEC, which would require that all keys to hash to the same slot. If it is, then the safe bet would be to use prefixes like{open-webui-1}and{open-webui-2}for your instances.In cluster mode, you point
REDIS_URLto just one of the hosts in the cluster, known as the seed host. The Redis client will then issue theCLUSTER SLOTScommand on initial connection to discover additional hosts (primaries and replicas) and the slot ranges assigned to each host. The Redis client will then know which host to directly talk to to get a value based on the hash slot it computed. If the seed host becomes unavailable but you still have replicas, then the client will retry requests on a replica if necessary.@sanchitbhavsar commented on GitHub (Aug 21, 2025):
@erhhung I am having issues with cluster mode, check: https://github.com/open-webui/open-webui/discussions/15834#discussioncomment-14175756
looking at the implementation on how keys are handle in openwebui,
438e5d966f/backend/open_webui/socket/utils.py (L182-L185)438e5d966f/backend/open_webui/socket/main.py (L134-L137)Should pass this key as prefix would work?
REDIS_KEY_PREFIX="{open-webui}:"with semicolon but without*@rgaricano commented on GitHub (Aug 22, 2025):
https://github.com/open-webui/open-webui/discussions/15834#discussioncomment-14179446
@AlbertDoesProgramming commented on GitHub (Aug 27, 2025):
So just to add on to this discussion. I'm wondering why in
open_webui/socket/main.py, the RedisLock doesn't also use the REDIS_KEY_PREFIX?I'm using ACLs to manage my redis security framework, and I want to gate OWUI access to redis behind access to keys with a certain shape, for example: ~open-webui-1:*. But the prefix isn't added to the name of the the RedisLock, and so when the lock fires, it throws because the key this creates would be out of scope.
Here's the code in question:
Is there a good reason not to include the prefix against the lock name? I have a workaround right now I think, but I was under the impression that the prefix really would end up everywhere.
@rgaricano commented on GitHub (Aug 27, 2025):
Yes, without change RedisLock Class, is a solution,
Replace
lock_name=f"{REDIS_KEY_PREFIX}:usage_cleanup_lock",in
df2428b356/backend/open_webui/socket/main.py (L118)I search about and seem that it's the only place where the prefix could be necessary, all others seem that are properly managed.
@AlbertDoesProgramming commented on GitHub (Aug 27, 2025):
Yeah it seems to me a natural change to make. That said, I am curious about why it wasn't addressed in the previous change to add the prefix - this makes me think there's some sort of important reason for not doing it that I can't imagine haha!
@AlbertDoesProgramming commented on GitHub (Aug 27, 2025):
issue raised for this
@rgaricano commented on GitHub (Aug 27, 2025):
& solved & merged
@AlbertDoesProgramming commented on GitHub (Aug 28, 2025):
Thank you! ❤️
@AlbertDoesProgramming commented on GitHub (Aug 29, 2025):
Fwiw I've spotted another area where I think the same issue occurs but for tools.py and raised that here: issue-17032