/**
  * 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();
 }
}
$addr = isset($args["h"]) ? (string) $args["h"] : (isset($args["host"]) ? (string) $args["host"] : "localhost");
$port = isset($args["p"]) ? (int) $args["p"] : (isset($args["port"]) ? (string) $args["port"] : 3000);
$total_ops = isset($args["n"]) ? (int) $args["n"] : (isset($args["num-ops"]) ? (string) $args["num-ops"] : 100000);
$write_every = isset($args["w"]) ? (int) $args["w"] : (isset($args["write-every"]) ? (string) $args["write-every"] : 10);
echo colorize("Connecting to the host ≻", 'black', true);
$config = array("hosts" => array(array("addr" => $addr, "port" => $port)));
$db = new Aerospike($config);
if (!$db->isConnected()) {
    echo fail("Could not connect to host {$addr}:{$port} [{$db->errorno()}]: {$db->error()}");
    exit(1);
}
echo success();
$key = $db->initKey("test", "performance", "read-write");
echo colorize("Clear out the record that may exist at test.performance with PK=1 ≻", 'black', true);
$res = $db->remove($key);
if ($res == Aerospike::OK) {
    echo success();
} else {
    echo standard_fail($db);
}
$write_fails = 0;
$writes = 1;
$reads = 0;
$read_fails = 0;
$kv = array("v" => 1);
echo colorize("Initialize the record used for the serial put/get performance test ≻", 'black', true);
$begin = microtime(true);
$res = $db->put($key, $kv);
if ($res == Aerospike::OK) {
    echo success();
Exemplo n.º 3
0
    }
});
$app->put('/append', function () use($db) {
    if ($db->isConnected()) {
        $key = $db->initKey("test", "demo", "key_append");
        $record = array("name" => "John", "age" => 32);
        $status = $db->put($key, $record);
        $status = $db->append($key, 'name', ' Watson', array(Aerospike::OPT_WRITE_TIMEOUT => 1000));
        if ($status != Aerospike::OK) {
            echo "\nAppend operation failed";
        } else {
            echo "\nValue appended successfully";
            $db->get($key, $record);
            var_dump($record);
        }
        $db->remove($key);
        $db->close();
    } else {
        echo "Aerospike DB connection is not established";
    }
});
$app->put('/multiappend', function () use($db) {
    if ($db->isConnected()) {
        for ($i = 0; $i < 100; $i++) {
            $key = $db->initKey("test", "demo", "key" . $i);
            $status = $db->append($key, 'name', ' World', array(Aerospike::OPT_WRITE_TIMEOUT => 1000));
            if ($status != Aerospike::OK) {
                echo "\nAppend failed at " . $i . "th record";
            }
        }
        $db->close();