arnapou/lock
最新稳定版本:v1.4.0
Composer 安装命令:
composer require arnapou/lock
包简介
Library - Simple lock interface and adapters.
README 文档
README
This library helps you to manage basic locks for async processes or race condition problems.
Installation
composer require arnapou/lock
packagist 👉️ arnapou/lock
Introduction
This library provides basic lock interfaces and adapters.
It mainly follows the KISS principle.
If you need advanced features, go look at symfony/lock or other equivalent libraries.
Here, the goal is minimalist code for 90% of needs.
Basic usage
$locker = new \Arnapou\Lock\Adapter\RedisLocker(
redis: $redis,
autorelease: true,
defaultTtl: 60,
namespace: 'project:locks:'
);
if ($locker->acquire('my_lock')) {
// do your process
$locker->release('my_lock');
} else {
// delay or report an error
}
Decorators
We can enhance the behaviour for instance with a retry mechanism :
$waitingLocker = new \Arnapou\Lock\Decorator\WaitingLocker(
internal: $redisLocker,
maxTotalWaitSeconds: 1.0,
minLoopWaitMilliseconds: 20,
maxLoopWaitMilliseconds: 150
);
if ($locker->acquire('my_lock')) {
// do your process
$locker->release('my_lock');
} else {
// delay or report an error
}
Php versions
| Date | Ref | 8.5 | 8.4 | 8.3 |
|---|---|---|---|---|
| 25/10/2025 | 1.4.x, main | × | × | × |
| 25/11/2024 | 1.3.x | × | × | |
| 09/01/2024 | 1.0 - 1.2 | × |
统计信息
- 总下载量: 182
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-05