cognizo/redis-mutex

A simple Redis-backed mutex lock.

v0.0.2 2013-10-14 16:48 UTC

This package is not auto-updated.

Last update: 2024-04-23 01:29:51 UTC


README

RedisMutex is a simple Redis-backed distributed mutex for PHP.

Basic Usage

<?php

use Cognizo\RedisMutex\Lock;

if (Lock::get('myLock'))
{
    // Do something exclusively

    Lock::release('myLock');
}
else
{
    echo "Couldn't get exclusive lock!";
}

You can also wait for a lock to be released:

// Wait up to 30 seconds for 'myLock' to become available
Lock::get('myLock', 30);

Specifying the Redis connection:

define('REDIS_PATH', 'tcp://127.0.0.1:6379');

// Or

define('REDIS_HOST', '127.0.0.1');
define('REDIS_PORT', 6379);

Install

Install the cognizo/redis-mutex package with Composer.