You are here

public function Redis_Lock_Backend_Predis::lockRelease in Redis 7.2

Same name and namespace in other branches
  1. 7 lib/Redis/Lock/Backend/Predis.php \Redis_Lock_Backend_Predis::lockRelease()

Release given lock.

Parameters

string $name:

Overrides Redis_Lock_Backend_Interface::lockRelease

File

lib/Redis/Lock/Backend/Predis.php, line 106

Class

Redis_Lock_Backend_Predis
Predis lock backend implementation.

Code

public function lockRelease($name) {
  $client = Redis_Client::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
      ->del(array(
      $key,
    ));
    $client
      ->exec();
  }
  else {
    $client
      ->unwatch();
  }
}