paysera/lib-lock-bundle
Composer 安装命令:
composer require paysera/lib-lock-bundle
包简介
Provides utilities to organize Locks in your system
README 文档
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 throwsLockAcquiringExceptionon failureLockManager::createAccuired($identifier)- creates acquired lock or throwsLockAcquiringExceptionLockManager::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
统计信息
- 总下载量: 15.37k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-10