예제 #1
0
 /**
  * @param string $filename
  * @param int $timeout
  * @return mixed
  */
 public function lock($filename, $timeout)
 {
     $key = $this->translator->toLockFile($filename);
     $lock = $this->redLock->lock($key, $timeout);
     if ($lock === FALSE) {
         return NULL;
     }
     return $lock;
 }
예제 #2
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));
 }
예제 #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";
    }
}