2017 © Pedro Peláez
 

library redis-mutex

image

kelunik/redis-mutex

  • Monday, July 24, 2017
  • by kelunik
  • Repository
  • 0 Watchers
  • 2 Stars
  • 253 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 4 Versions
  • 5 % Grown

The README.md

Redis Mutex Build Status

Distributed mutual exclusion built upon the Amp concurrency framework and Redis., (*1)

Basic Example

$mutex = new Mutex(...);

// ...

try {
    $token = bin2hex(random_bytes(16));
    yield $mutex->lock($sessionId, $token);

    // Code here will only be executed in one client at a time.
    // If it takes longer than your specified TTL, you have to
    // renew the lock, see next example.

    yield $mutex->unlock($sessionId, $token);
} catch (MutexException $e) {
    // ...
}

Renew Example

$mutex = new Mutex(...);
$locks = [];

Loop::repeat(1000, function () use ($mutex, $locks) {
    foreach ($locks as $id => $token) {
        $mutex->renew($id, $token);
    }
});

// ...

try {
    $token = bin2hex(random_bytes(16));
    yield $mutex->lock($sessionId, $token);
    $locks[$sessionId] = $token;

    // Code here will only be executed in one client at a time.
    // Your lock will automatically be renewed by the reactor
    // repeat above. Don't do blocking things here (you should never
    // do that with Amp anyway), otherwise the reactor will not
    // be able to schedule the renewal.

    unset($locks[$sessionId]);
    yield $mutex->unlock($sessionId, $token);
} catch (MutexException $e) {
    // ...
}

The Versions

24/07 2017

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

24/07 2017

v0.2.0

0.2.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

23/02 2016

v0.1.0

0.1.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

23/02 2016

0.1.x-dev

0.1.9999999.9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires