mingalevme / illuminate-lock by mingalevme

Laravel/Lumen decorator fot symfony/lock component
644
0
1
Package Data
Maintainer Username: mingalevme
Maintainer Contact: mingalevme@gmail.com (Mingalev Mikhail)
Package Create Date: 2017-11-17
Package Last Update: 2017-11-21
Language: PHP
License: MIT
Last Refreshed: 2024-12-15 15:12:24
Package Statistics
Total Downloads: 644
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 0
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

illuminate-lock

Laravel/Lumen decorator for symfony/lock component

Supports drivers:

  • Flock
  • Memcached
  • Redis
  • Semaphore
  • Combined
  • RetryTillSave

Installation

  1. composer require mingalevme/illuminate-lock.

  2. Register the appropriate service provider \Mingalevme\Illuminate\Lock\LaravelLockServiceProvider::class or \Mingalevme\Illuminate\Lock\LumenLockServiceProvider::class.

  3. (Optionally) Add alias to your bootstrap file:

'Lock' => Mingalevme\Illuminate\Lock\Facades\Lock::class,
  1. (Optionally) For Larvel run
php artisan vendor:publish --provider="Mingalevme\Illuminate\Lock\LaravelLockServiceProvider" --tag="config"

to publish the config file.

  1. (Optionally) For Lumen copy /vendor/mingalevme/illuminate-lock/config/lock.php to /config/lock.php.

  2. Now you are able to use the library:

<?php

use Mingalevme\Illuminate\Lock\Facades\Lock;

$lock = Lock::createLock('resource-id');

if ($lock->acquire()) {
    echo "Resource has been locked";
} else {
    echo "Could not get lock";
}

or

<?php

use Mingalevme\Illuminate\Lock\Facades\Lock;

$lock = Lock::store('redis')->createLock('resource-id');

if ($lock->acquire()) {
    echo "Resource has been locked";
} else {
    echo "Could not get lock";
}