You are here

public function PhpRedis::release in Redis 8

Releases the given lock.

Parameters

string $name:

Overrides LockBackendInterface::release

1 call to PhpRedis::release()
PhpRedis::releaseAll in src/Lock/PhpRedis.php
Releases all locks for the given lock token identifier.

File

src/Lock/PhpRedis.php, line 113

Class

PhpRedis
Predis lock backend implementation.

Namespace

Drupal\redis\Lock

Code

public function release($name) {
  $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.
  $this->client
    ->watch($key);
  if ($this->client
    ->get($key) == $id) {
    $this->client
      ->multi();
    $this->client
      ->del($key);
    $this->client
      ->exec();
  }
  else {
    $this->client
      ->unwatch();
  }
}