You are here

public function Predis::release in Redis 8

Releases the given lock.

Parameters

string $name:

Overrides LockBackendInterface::release

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

File

src/Lock/Predis.php, line 102

Class

Predis
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) {
    $pipe = $this->client
      ->pipeline();
    $pipe
      ->del([
      $key,
    ]);
    $pipe
      ->execute();
  }
  else {
    $this->client
      ->unwatch();
  }
}