arnapou/lock 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

arnapou/lock

最新稳定版本:v1.4.0

Composer 安装命令:

composer require arnapou/lock

包简介

Library - Simple lock interface and adapters.

README 文档

README

pipeline coverage

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

DateRef8.58.48.3
25/10/20251.4.x, main×××
25/11/20241.3.x××
09/01/20241.0 - 1.2×

统计信息

  • 总下载量: 182
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-05