From a7ee0811f0ae715f90117b1ac04471619a8ac049 Mon Sep 17 00:00:00 2001 From: janua bisconti Date: Mon, 25 Nov 2024 14:43:10 +0100 Subject: [PATCH] work in progress --- src/SuperCacheManager.php | 5 +++-- src/Traits/ManagesLocksAndShardsTrait.php | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/SuperCacheManager.php b/src/SuperCacheManager.php index 30b8820..b090a2d 100644 --- a/src/SuperCacheManager.php +++ b/src/SuperCacheManager.php @@ -271,9 +271,10 @@ public function getKeys(array $patterns, ?string $connection_name = null): array * @param string $key The lock key. * @return bool True if the lock was acquired, false otherwise. */ - public function lock(string $key, ?string $connection_name = null): bool + public function lock(string $key, ?string $connection_name = null, ?int $ttl = 10): bool { - return $this->redis->getRedisConnection($connection_name)->set($key, '1', 'NX', 'EX', 10); + $result = $this->redis->getRedisConnection($connection_name)->set($key, 1, ['NX', 'EX' => $ttl]); + return $result !== false; } /** diff --git a/src/Traits/ManagesLocksAndShardsTrait.php b/src/Traits/ManagesLocksAndShardsTrait.php index 098fbb7..041e3f5 100644 --- a/src/Traits/ManagesLocksAndShardsTrait.php +++ b/src/Traits/ManagesLocksAndShardsTrait.php @@ -11,7 +11,8 @@ protected function acquireLock(string $key, ?string $connection_name = null): bo { $lockKey = 'lock:' . $key; // Tenta di acquisire il lock con un timeout di 10 secondi - return $this->redis->getRedisConnection($connection_name)->set($lockKey, '1', 'NX', 'EX', 10); + //return $this->redis->getRedisConnection($connection_name)->set($lockKey, '1', 'NX', 'EX', 10); + return $this->redis->getRedisConnection($connection_name)->set($key, 1, ['NX', 'EX' => 10]); } /**