You are here

public function Redis_Lock_PhpRedis::lockRelease in Redis 7.3

Release given lock.

Parameters

string $name:

Overrides Redis_Lock_BackendInterface::lockRelease

File

lib/Redis/Lock/PhpRedis.php, line 97

Class

Redis_Lock_PhpRedis
Predis lock backend implementation.

Code

public function lockRelease($name) {
  $client = $this
    ->getClient();
  $key = $this
    ->getKey($name);
  $id = $this
    ->getLockId();
  unset($this->_locks[$name]);

  // Ensure the lock deletion is an atomic transaction. If another thread
  // manages to removes all lock, we can not alter it anymore else we will
  // release the lock for the other thread and cause race conditions.
  $client
    ->watch($key);
  if ($client
    ->get($key) == $id) {
    $client
      ->multi();
    $client
      ->delete($key);
    $client
      ->exec();
  }
  else {
    $client
      ->unwatch();
  }
}