https://github.com/paysera/lib-lock-bundle
Provides quick integration with Redis based symfony/lock
https://github.com/paysera/lib-lock-bundle
Last synced: 5 months ago
JSON representation
Provides quick integration with Redis based symfony/lock
- Host: GitHub
- URL: https://github.com/paysera/lib-lock-bundle
- Owner: paysera
- Created: 2018-10-09T06:58:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-02T08:11:20.000Z (about 1 year ago)
- Last Synced: 2024-12-07T21:14:22.951Z (6 months ago)
- Language: PHP
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 4
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# lib-lock-bundle [](https://travis-ci.org/paysera/lib-lock-bundle)
Provides quick integration with `symfony/lock`
### Installation
- Install package
```bash
composer require paysera/lib-lock-bundle
```
- Enable bundle
```php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
// ...
new Paysera\Bundle\LockBundle\PayseraLockBundle(),
];// ...
}
}
```### Configuration
```yaml
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](https://symfony.com/doc/master/components/lock.html#lock-store-redis)
### Usage
* `LockManager::createLock($identifier)` - creates lock **but not acquires it**
* `LockManager::acquire($lock)` - acquires lock or throws `LockAcquiringException` on failure
* `LockManager::createAccuired($identifier)` - creates **acquired** lock or throws `LockAcquiringException`
* `LockManager::release($lock)` - releases lock#### Example
```php
$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
```php
try {
$lock = $this->lockManager->createAcquired($identifier);
} catch (LockAcquiringException $exception) {
throw new Exception('...');
}// do rest
```