Ejemplo n.º 1
0
<?php

require_once __DIR__ . '/../src/RedLock.php';
$servers = [['127.0.0.1', 6379, 0.01], ['127.0.0.1', 6389, 0.01], ['127.0.0.1', 6399, 0.01]];
$redLock = new RedLock($servers);
while (true) {
    $lock = $redLock->lock('test', 10000);
    if ($lock) {
        print_r($lock);
    } else {
        print "Lock not acquired\n";
    }
}
Ejemplo n.º 2
0
<?php

require_once __DIR__ . '/../src/RedLock.php';
define('LOCK_TIMEOUT', 10);
if (USE_REDIS_CLUSTER) {
    $servers = array(array('172.16.10.168', 6379), array('172.16.10.193', 6379), array('172.16.10.169', 6379));
} else {
    $servers = array(array('127.0.0.1', 6379));
}
$redLock = new RedLock($servers);
while (true) {
    $lock = $redLock->lock('test', LOCK_TIMEOUT * 1000);
    if ($lock) {
        print_r($lock);
        // Do something here
        $sleep = LOCK_TIMEOUT / 2;
        echo "Unlocking in {$sleep} seconds\n";
        sleep($sleep);
        $redLock->unlock($lock);
    } else {
        print "Lock not acquired\n";
    }
    // Buffer before next attempt
    usleep(time() % 11 * 100000);
}
Ejemplo n.º 3
0
<?php

require_once __DIR__ . '/../RedLock/RedLock.php';
//define('USE_REDIS_CLUSTER', TRUE);
define('USE_REDIS_CLUSTER', FALSE);
define('LOCK_TIMEOUT', 10);
if (USE_REDIS_CLUSTER) {
    $servers = array(array('172.16.10.168', 6379), array('172.16.10.193', 6379), array('172.16.10.169', 6379));
} else {
    $servers = array(array('127.0.0.1', 6379));
}
$redLock = new RedLock($servers);
while (true) {
    $lock = $redLock->lock('test', LOCK_TIMEOUT);
    if ($lock) {
        print_r($lock);
        // Do something here
        $sleep = LOCK_TIMEOUT / 2;
        echo "Unlocking in {$sleep} seconds\n";
        sleep($sleep);
        $redLock->unlock($lock);
    } else {
        print "Lock not acquired\n";
    }
    // Buffer before next attempt
    usleep(time() % 11 * 100000);
}