Skip to content

Commit

Permalink
work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
januabisconti committed Nov 25, 2024
1 parent dc61e65 commit a7ee081
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/SuperCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Traits/ManagesLocksAndShardsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

/**
Expand Down

0 comments on commit a7ee081

Please sign in to comment.