mmdtl/autolock
Composer 安装命令:
composer require mmdtl/autolock
包简介
Redis distributed locks in PHP
README 文档
README
AutoLock - Redis distributed locks in PHP
This library implements the RedLock algorithm introduced by @antirez
This library implements the Redis-based distributed lock manager algorithm described in this blog post.
To create a lock manager:
$pool = new \AutoLock\Pool(array( '192.168.1.1:6379', '192.168.1.2:6379', '192.168.1.3:6379', ),new \AutoLock\Drivers\PHPRedis()); $manager = new \AutoLock\Manager($pool);
To acquire a lock:
$lock = $manager->lock('distributed_lock',1000);;
Where the resource name is an unique identifier of what you are trying to lock and 1000 is the number of milliseconds for the validity time.
The returned value is false if the lock was not acquired (you may try again),
otherwise an object representing the lock is returned, you should use isExpired method
to detect whether the lock is expired now or in certain time:
$status = $lock->isExpired(); //$status will be true if the lock is expired or it will be false $status = $lock->isExpired(3600 * 1000); //$status will be true if the lock will be expired after 3600 seconds or it will be false
- validity, an integer representing the number of milliseconds the lock will be valid.
- resource, the name of the locked resource as specified by the user.
- token, a random token value which is used to safe reclaim the lock.
To release a lock:
$lock->unlock($lock)
It is possible to setup the number of retries (by default 3) and the retry delay (by default 200 milliseconds) used to acquire the lock.
The retry delay is actually chosen at random between $retryDelay / 2 milliseconds and
the specified $retryDelay value.
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-03-27