承接 ledc/locker 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ledc/locker

最新稳定版本:v2.0.0

Composer 安装命令:

composer require ledc/locker

包简介

Webman plugin ledc/locker

README 文档

README

symfony/lock for webman

在 webman 中简化使用业务锁功能

解决以下问题:

  • 并发业务操作有时候需要锁来防止并发导致的数据插入或更新问题
  • 单独使用 symfony/lock 时一般使用 $factory->createLock('key'),此时 key 是一个字符串,不利于后期维护或多处使用

安装

compoer require ledc/locker

使用

定义一个自己的 Locker 类

比如:support\facade\Locker.php,继承 Ledc\Locker

然后在类上方加入注释(用于代码提示),举例如下:

<?php

namespace support\facade;

use Symfony\Component\Lock\LockInterface;

/**
 * @method static LockInterface order(?string $orderId = null, ?float $ttl = null, ?bool $autoRelease = null, ?string $prefix = null)
 * @method static LockInterface changeCash(?string $userId = null, ?float $ttl = null, ?bool $autoRelease = null, ?string $prefix = null)
 */
class Locker extends \Ledc\Locker
{
}

业务中使用

<?php

namespace app\controller;

use support\facade\Locker;

class User {
    public function changeCash()
    {
        $lock = Locker::changeCash($currentUserId, 5, true);
        if (!$lock->acquire()) {
            throw new \Exception('操作太频繁,请稍后再试');
        }
        try {
            // 修改用户金额
        } finally {
            $lock->release();
        }

        return 'ok';
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固