mingalevme/illuminate-lock

Laravel/Lumen decorator fot symfony/lock component

1.0.4 2017-11-21 09:58 UTC

This package is auto-updated.

Last update: 2024-10-08 01:38:33 UTC


README

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";
}