tokenly/laravel-record-lock

v1.2.0 2018-11-05 16:02 UTC

This package is not auto-updated.

Last update: 2024-09-20 21:01:58 UTC


README

一个用于在应用程序中创建共享锁的 Laravel 库。需要 MySQL 数据库连接。

安装

使用 composer 添加 Laravel 包

composer require tokenly/laravel-record-lock

添加服务提供者(仅限 Laravel <= 5.4)

将以下内容添加到应用程序配置中的 providers 数组

Tokenly\RecordLock\Provider\RecordLockServiceProvider::class

使用方法

use Tokenly\RecordLock\Facade\RecordLock;

$lock_id = 'plant-garden-once';
$planted = RecordLock::acquireAndExecute($lock_id, function() {
    // plant the garden
    //   only one process should do this at a time
    //   other processes will block until this is complete
    sleep(1);

    return true;
});