function PostgreSqlStore::save
Overrides PersistingStoreInterface::save
File
-
vendor/
symfony/ lock/ Store/ PostgreSqlStore.php, line 70
Class
- PostgreSqlStore
- PostgreSqlStore is a PersistingStoreInterface implementation using PostgreSql advisory locks.
Namespace
Symfony\Component\Lock\StoreCode
public function save(Key $key) : void {
// prevent concurrency within the same connection
$this->getInternalStore()
->save($key);
$lockAcquired = false;
try {
$sql = 'SELECT pg_try_advisory_lock(:key)';
$stmt = $this->getConnection()
->prepare($sql);
$stmt->bindValue(':key', $this->getHashedKey($key));
$result = $stmt->execute();
// Check if lock is acquired
if (true === $stmt->fetchColumn()) {
$key->markUnserializable();
// release sharedLock in case of promotion
$this->unlockShared($key);
$lockAcquired = true;
return;
}
} finally {
if (!$lockAcquired) {
$this->getInternalStore()
->delete($key);
}
}
throw new LockConflictedException();
}