Example #1
0
 public function testLockMultiple()
 {
     $redlock = new RedLock($this->servers);
     $resource = "my_test_resource" . time();
     $lockA = $redlock->lock($resource, 1000);
     $lockB = $redlock->lock($resource, 1000);
     $lockC = $redlock->lock($resource, 1000);
     $this->assertInternalType("array", $lockA);
     $this->assertFalse($lockB);
     $this->assertFalse($lockC);
     $this->assertTrue($redlock->unlock($lockA));
     $lockA = $redlock->lock($resource, 1000);
     $lockB = $redlock->lock($resource, 1000);
     $this->assertInternalType("array", $lockA);
     $this->assertFalse($lockB);
     $this->assertTrue($redlock->unlock($lockA));
 }
Example #2
0
 /**
  * @param mixed $lock
  * @return bool
  * @throws \Exception
  */
 public function unlock($lock)
 {
     return $this->redLock->unlock($lock);
 }
Example #3
0
<?php

use Predis\Client;
use RedLock\RedLock;
require_once __DIR__ . '/../src/RedLock.php';
require_once __DIR__ . '/../vendor/autoload.php';
$RedLock = new RedLock([new Client(['host' => '127.0.0.1', 'port' => 6379, 'timeout' => 0.01]), new Client(['host' => '127.0.0.1', 'port' => 6380, 'timeout' => 0.01]), new Client(['host' => '127.0.0.1', 'port' => 6381, 'timeout' => 0.01])]);
while (true) {
    $lock = $RedLock->lock('test', 10000);
    if ($lock) {
        print_r($lock);
    } else {
        print "Lock not acquired\n";
    }
}