Provides quick integration with symfony/lock
- Install package
composer require paysera/lib-lock-bundle- Enable bundle
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
// ...
new Paysera\Bundle\LockBundle\PayseraLockBundle(),
];
// ...
}
}paysera_lock:
ttl: 5 # integer, optional
redis_client: # service id, requiredttl - time for locks TTL in seconds, default 5 seconds.
redis_client - service id for any Redis client service supported by symfony/lock
LockManager::createLock($identifier)- creates lock but not acquires itLockManager::acquire($lock)- acquires lock or throwsLockAcquiringExceptionon failureLockManager::createAccuired($identifier)- creates acquired lock or throwsLockAcquiringExceptionLockManager::release($lock)- releases lock
$lock = $this->lockManager->createLock($identifier);
try {
$this->lockManager->acquire($lock);
// do something after aquiring lock
} catch (LockAcquiringException $exception) {
throw new Exception('...');
} finally {
$lock->release();
}OR
try {
$lock = $this->lockManager->createAcquired($identifier);
} catch (LockAcquiringException $exception) {
throw new Exception('...');
}
// do rest