/**
  * This method is called after the last test of this test class is run.
  */
 public static function tearDownAfterClass()
 {
     if (self::$aerospike->isConnected()) {
         foreach (self::$keys as $key) {
             // TODO: check existence of $key in Aerospike.
             self::$aerospike->remove($key);
         }
         self::$aerospike->close();
     }
     parent::tearDownAfterClass();
 }
    $end1 = strpos($response1, ';', $start1);
    $len1 = $end1 - $start1;
    $cluster_key1 = substr($response1, $start1, $len1);
    $start2 = strpos($response2, 'cluster_key=') + 12;
    $end2 = strpos($response2, ';', $start2);
    $len2 = $end2 - $start2;
    $cluster_key2 = substr($response2, $start2, $len2);
    return $cluster_key1 == $cluster_key2;
}
$config = array("hosts" => array(array("addr" => AEROSPIKE_CONFIG_NAME, "port" => AEROSPIKE_CONFIG_PORT)));
$db = new Aerospike($config, false);
if (defined('AEROSPIKE_CONFIG_NAME2') && defined('AEROSPIKE_CONFIG_PORT2')) {
    $config['hosts'][] = array("addr" => AEROSPIKE_CONFIG_NAME2, "port" => AEROSPIKE_CONFIG_PORT2);
}
echo "Waiting on the Aerospike cluster..";
$keep_waiting = true;
while ($keep_waiting) {
    $host1_status = $db->info("statistics", $host1_response, $config['hosts'][0]);
    $host2_status = $db->info("statistics", $host2_response, $config['hosts'][1]);
    if ($host1_status === Aerospike::OK && $host2_status === Aerospike::OK) {
        if (servers_present($host1_response, $host2_response)) {
            $keep_waiting = false;
            break;
        }
    }
    echo ".";
    sleep(1);
}
echo "OK\n";
$db->close();
Exemplo n.º 3
0
    } else {
        echo "Connected to the Aerospike Database";
        echo "<h1>Welcome!</h1>";
    }
});
$app->post('/put', function () use($db) {
    if ($db->isConnected()) {
        $key = $db->initKey("test", "demo", "key1");
        $record = array("name" => "John", "age" => 32);
        $status = $db->put($key, $record);
        if ($status != Aerospike::OK) {
            echo "Single put failed";
        } else {
            echo "Record has been successfully written to the Database\n";
        }
        $db->close();
    } else {
        echo "Aerospike DB connection is not established\n";
    }
});
$app->post('/multiput', function () use($db) {
    if ($db->isConnected()) {
        for ($i = 0; $i < 100; $i++) {
            $key = $db->initKey("test", "demo", "key" . $i);
            $record = array("name" => "name" . $i, "age" => $i);
            $status = $db->put($key, $record);
            if ($status != Aerospike::OK) {
                echo "\nMultiput failed at " . $i . "th record";
                break;
            }
        }