Skip to content

Provides quick integration with Redis based symfony/lock

Notifications You must be signed in to change notification settings

mSprunskas/lib-lock-bundle

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lib-lock-bundle Build Status

Provides quick integration with symfony/lock

Installation

  • Install package
composer require paysera/lib-lock-bundle
  • Enable bundle
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...
            new Paysera\Bundle\LockBundle\PayseraLockBundle(),
        ];

        // ...
    }
}

Configuration

paysera_lock:
    ttl: 5 # integer, optional
    redis_client: # service id, required

ttl - time for locks TTL in seconds, default 5 seconds.

redis_client - service id for any Redis client service supported by symfony/lock

Usage

  • LockManager::createLock($identifier) - creates lock but not acquires it
  • LockManager::acquire($lock) - acquires lock or throws LockAcquiringException on failure
  • LockManager::createAccuired($identifier) - creates acquired lock or throws LockAcquiringException
  • LockManager::release($lock) - releases lock

Example

$lock = $this->lockManager->createLock($identifier);
try {
    $this->lockManager->acquire($lock);
    
    // do something after aquiring lock
} catch (LockAcquiringException $exception) {
    throw new Exception('...');
} finally {
    $lock->release();
}

OR

try {
    $lock = $this->lockManager->createAcquired($identifier);
} catch (LockAcquiringException $exception) {
    throw new Exception('...');
}

// do rest

About

Provides quick integration with Redis based symfony/lock

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%