swordev / mutex
读写并发控制
0.1.0
2020-07-27 12:07 UTC
Requires (Dev)
- phpstan/phpstan: ^0.12.9
- phpunit/phpunit: ^9.1.3
This package is not auto-updated.
Last update: 2024-10-02 07:23:05 UTC
README
读写并发控制
安装
composer require @swordev/mutex
使用
文件读写锁
use Swordev\Mutex\FileMutex; $mutex1 = new FileMutex('key'); $mutex2 = new FileMutex('key'); $mutex1->readLock(); // true $mutex2->writeLock(); // false $mutex1->unlock(); // true $mutex2->writeLock(); // true
超时
use Swordev\Mutex\FileMutex; $mutex = new FileMutex('key'); $mutex->writeLock(5000);
上下文锁
use Swordev\Mutex\FileMutex; class Foo { function method() { $mutex = new FileMutex(__CLASS__ . '|' . __FUNCTION__); $mutex->writeLock(); // ... } }
互斥锁工厂
use Swordev\Mutex\MutexFactory; $mutex = new MutexFactory::create(FileMutex::class, 'key');
开发
测试
composer run test
分析
composer run analyse
作者
Juanra GM - https://github.com/juanrgm
在MIT许可下分发。