tp5er/think-lock

thinkphp lock

dev-main 2024-05-06 07:58 UTC

This package is auto-updated.

Last update: 2024-12-06 09:19:10 UTC


README

composer require tp5er/think-lock

使用

<?php

namespace app\controller;

use app\BaseController;
use tp5er\think\lock\facade\Locker;

class Index extends BaseController
{
    public function index()
    {
        $lock = Locker::lock("index");
        if (!$lock->acquire()) {
            throw new \Exception('操作太频繁,请稍后再试');
        }
        try {
            //TODO 业务操作
        } finally {
            $lock->release();
        }
    }
}

更多操作参考:symfony/lock 文档