From b0f5c9066222d15f9112753c7d6063a4acfdb569 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Wed, 29 Apr 2026 15:10:59 +0100 Subject: [PATCH] feat: accept RedisCluster alongside Redis in Distributed lock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The lock primitive uses only single-key operations (SET NX EX, GET, and single-key Lua EVAL via runScript), all of which behave identically on \Redis and \RedisCluster — the cluster client routes by hash slot transparently. Widening the type lets clustered Dragonfly/Redis deployments use the same Distributed lock without an external client wrapper. No algorithmic changes; same TTL, same compare-and-delete release script, same correctness properties per key. Multi-master quorum guarantees (Redlock) remain out of scope — single-key locks on cluster mode have the same per-key failover semantics as single-instance Redis. --- src/Distributed.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Distributed.php b/src/Distributed.php index 74de2e7..f0a69aa 100644 --- a/src/Distributed.php +++ b/src/Distributed.php @@ -6,6 +6,7 @@ use Closure; use Redis; +use RedisCluster; use Utopia\Lock\Exception\Contention; final class Distributed implements Lock @@ -31,7 +32,7 @@ final class Distributed implements Lock private ?Closure $logger = null; public function __construct( - private readonly Redis $redis, + private readonly Redis|RedisCluster $redis, private readonly string $key, private readonly int $ttl = 600, ) {