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, required
ttl
- 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 throwsLockAcquiringException
on failureLockManager::createAccuired($identifier)
- creates acquired lock or throwsLockAcquiringException
LockManager::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