paysera / lib-lock-bundle
Provides utilities to organize Locks in your system
Installs: 15 183
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 7
Open Issues: 2
Type:symfony-bundle
Requires
- php: >=7.1
- symfony/config: ^3.0 || ^4.0 || ^5.0
- symfony/console: ^4.4 || ^5.3 || ^6.0
- symfony/dependency-injection: ^3.0 || ^4.0 || ^5.0
- symfony/http-kernel: ^3.0 || ^4.0 || ^5.0
- symfony/lock: ^v3.4 || ^4.4 || ^5.4
- symfony/yaml: ^4.0 || ^5.0 || ^6.0 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^6.0 || ^7.0 || ^8.0
- predis/predis: ^1.1
- snc/redis-bundle: ^2.1 || ^3.0 || ^4.0
Suggests
- predis/predis: To store locks in Redis
This package is auto-updated.
Last update: 2024-11-02 09:25:00 UTC
README
Provides quick integration with symfony/lock
Installation
- Install package
composer require paysera/lib-lock-bundle
- Enable bundle
class AppKernel extends Kernel { public function registerBundles() { $bundles = [ // ... new Paysera\Bundle\LockBundle\PayseraLockBundle(), ]; // ... } }
Configuration
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
Usage
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
Example
$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