eleme/rlock

redis lock

v0.3.2 2014-11-15 03:48 UTC

This package is not auto-updated.

Last update: 2024-11-09 17:09:03 UTC


README

Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight Stable Status

Redis lock for some atomic opration.

Install With Composer:

"require": {
    "eleme/rlock": "~0.3"
}

Usage

Rlock

<?php

use Eleme\Rlock\Lock;
use Predis\Client;

require_once(__DIR__.'/../vendor/autoload.php');

$redis = new Client();

$lock1 = new Lock($redis, 'lock1');
$lock1->acquire();
// release it by manually or it will be autoreleased.
$lock1->release();


// pass some options like timeout and interval.
$lock2 = new Lock($redis, 'lock2', array('timeout' => 5000, 'interval' => 500));
echo $lock2->acquire() ? 'true' : 'false', "\n";

// sometimes you may need a non-block lock.
$lock3 = new Lock($redis, 'lock3', array('blocking' => false));
echo $lock3->acquire() ? 'true' : 'false', "\n";
$lock4 = new Lock($redis, 'lock3', array('blocking' => false));
echo $lock4->acquire() ? 'true' : 'false', "\n";

Factory

<?php

use Eleme\Rlock\Factory;
use Predis\Client;

require_once(__DIR__.'/../vendor/autoload.php');

$factory = new Factory(new Client);
$lock = $factory->make('test');

Extended Predis

<?php

use Eleme\Rlock\Predis;

require_once(__DIR__.'/../vendor/autoload.php');

$redis = new Predis();
$lock = $redis->lock('lock1');
echo $lock->acquire() ? 'true' : 'fasel', "\n";

Laravel

Service Provider

'Eleme\Rlock\Provider\Laravel\RlockServiceProvider'

Facade

'Rlock' => 'Eleme\Rlock\Provider\Laravel\Facade'