public function Redis_Lock_Backend_PhpRedis::lockRelease in Redis 7.2
Same name and namespace in other branches
- 7 lib/Redis/Lock/Backend/PhpRedis.php \Redis_Lock_Backend_PhpRedis::lockRelease()
Release given lock.
Parameters
string $name:
Overrides Redis_Lock_Backend_Interface::lockRelease
File
- lib/
Redis/ Lock/ Backend/ PhpRedis.php, line 97
Class
- Redis_Lock_Backend_PhpRedis
- 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
->delete($key);
$client
->exec();
}
else {
$client
->unwatch();
}
}