Exemplo n.º 1
0
$HOST_PORT = isset($args["p"]) ? (int) $args["p"] : (isset($args["port"]) ? (string) $args["port"] : 3000);
echo colorize("Connecting to the host ≻", 'black', true);
$start = __LINE__;
$config = array("hosts" => array(array("addr" => $HOST_ADDR, "port" => $HOST_PORT)));
$db = new Aerospike($config, false);
if (!$db->isConnected()) {
    echo fail("Could not connect to host {$HOST_ADDR}:{$HOST_PORT} [{$db->errorno()}]: {$db->error()}");
    exit(1);
}
echo success();
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Ensuring that a record is put at test.users with PK=1234 ≻", 'black', true);
$start = __LINE__;
$key = $db->initKey("test", "users", 1234);
$put_vals = array("email" => "*****@*****.**", "name" => "Perceptron");
$status = $db->put($key, $put_vals);
if ($status == Aerospike::OK) {
    echo success();
} else {
    echo standard_fail($db);
}
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Ensuring that a record is put at test.users with PK=2345 ≻", 'black', true);
$start = __LINE__;
$key = $db->initKey("test", "users", 2345);
$put_vals = array("email" => "*****@*****.**", "name" => "Roberto");
$status = $db->put($key, $put_vals);
echo colorize("Connecting to the host ≻", 'black', true);
$start = __LINE__;
$config = array("hosts" => array(array("addr" => $HOST_ADDR, "port" => $HOST_PORT)));
$db = new Aerospike($config, false);
if (!$db->isConnected()) {
    echo fail("Could not connect to host {$HOST_ADDR}:{$HOST_PORT} [{$db->errorno()}]: {$db->error()}");
    exit(1);
}
echo success();
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Writing a record in test.characters with PK=1234 ≻", 'black', true);
$start = __LINE__;
$digest = $db->getKeyDigest("test", "characters", 1234);
$key = $db->initKey("test", "characters", $digest, true);
$put_vals = array("email" => "*****@*****.**", "name" => "Perceptron");
$status = $db->put($key, $put_vals);
if ($status == Aerospike::OK) {
    echo success();
} else {
    echo standard_fail($db);
}
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Getting the record ≻", 'black', true);
$start = __LINE__;
$status = $db->get($key, $record);
if ($status == Aerospike::OK) {
    echo success();
Exemplo n.º 3
0
echo colorize("Connecting to the host ≻", 'black', true);
$start = __LINE__;
$config = array("hosts" => array(array("addr" => $HOST_ADDR, "port" => $HOST_PORT)));
$db = new Aerospike($config, false);
if (!$db->isConnected()) {
    echo fail("Could not connect to host {$HOST_ADDR}:{$HOST_PORT} [{$db->errorno()}]: {$db->error()}");
    exit(1);
}
echo success();
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Ensuring that a series of record is put at test.users ≻", 'black', true);
$start = __LINE__;
for ($i = 123; $i <= 133; $i++) {
    $key = $db->initKey("test", "users", $i);
    $put_vals = array("email" => "me.{$i}@example.com", "name" => "User {$i}");
    $status = $db->put($key, $put_vals);
}
if ($status == Aerospike::OK) {
    echo success();
} else {
    echo standard_fail($db);
}
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Buffering records from a scan ≻", 'black', true);
$start = __LINE__;
$processed = 0;
$result = array();
Exemplo n.º 4
0
$config = array("hosts" => array(array("addr" => $HOST_ADDR, "port" => $HOST_PORT)));
$db = new Aerospike($config, false);
if (!$db->isConnected()) {
    echo fail("Could not connect to host {$HOST_ADDR}:{$HOST_PORT} [{$db->errorno()}]: {$db->error()}");
    exit(1);
}
echo success();
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Ensuring that records are put at test.characters with PKs=4-10 ≻", 'black', true);
$start = __LINE__;
$characters = array("*****@*****.**" => 162, "*****@*****.**" => 40, "*****@*****.**" => 39, "*****@*****.**" => 34, "*****@*****.**" => 173, "*****@*****.**" => 1055);
$i = 4;
foreach ($characters as $email => $age) {
    $key = $db->initKey("test", "characters", $i++);
    $put_vals = array("email" => $email, "age" => $age);
    $status = $db->put($key, $put_vals);
    if ($status == Aerospike::OK) {
        echo success();
    } else {
        echo standard_fail($db);
    }
}
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Creating a secondary index on the 'age' bin of test.characters ≻", 'black', true);
$start = __LINE__;
$status = $db->addIndex("test", "characters", "age", "test_character_age_idx", Aerospike::INDEX_TYPE_DEFAULT, Aerospike::INDEX_NUMERIC);
if ($status == Aerospike::OK) {
$HOST_PORT = isset($args["p"]) ? (int) $args["p"] : (isset($args["port"]) ? (string) $args["port"] : 3000);
echo colorize("Connecting to the host ≻", 'black', true);
$start = __LINE__;
$config = array("hosts" => array(array("addr" => $HOST_ADDR, "port" => $HOST_PORT)));
$db = new Aerospike($config, false);
if (!$db->isConnected()) {
    echo fail("Could not connect to host {$HOST_ADDR}:{$HOST_PORT} [{$db->errorno()}]: {$db->error()}");
    exit(1);
}
echo success();
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Adding a record to test.shows with PK='futurama' ≻", 'black', true);
$start = __LINE__;
$key = $db->initKey("test", "shows", "futurama");
$futurama = array("channel" => array("Fox" => array(1999, 2000, 2001, 2002), "Comedy Central" => array(2008, 2009, 2010, 2011, 2012)), "creator" => array("Matt Groening", "David X. Cohen"), "show" => "Futurama");
$options = array(Aerospike::OPT_POLICY_KEY => Aerospike::POLICY_KEY_SEND);
$status = $db->put($key, $futurama, 0, $options);
if ($status === Aerospike::OK) {
    echo success();
} else {
    echo standard_fail($db);
}
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Instantiating an LList representing bin 'characters' of the given record ≻", 'black', true);
$start = __LINE__;
require_once realpath(__DIR__ . '/../../autoload.php');
$characters = new \Aerospike\LDT\LList($db, $key, 'characters');
$db = new Aerospike($config, false);
if (!$db->isConnected()) {
    echo fail("Could not connect to host {$HOST_ADDR}:{$HOST_PORT} [{$db->errorno()}]: {$db->error()}");
    exit(1);
}
echo success();
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Adding characters with PK=1-4 ≻", 'black', true);
$start = __LINE__;
$characters = array(1 => "Philip J. Fry", 2 => "Tarunga Leela", 3 => "Bender Bending Rodriguez", 4 => "Professor Hubert J. Farnsworth");
foreach ($characters as $id => $character) {
    $new_key = "key{$id}";
    var_dump($new_key);
    ${$new_key} = $db->initKey("test", "characters", $id);
    $db->put(${$new_key}, array("id" => $id, "name" => $character));
}
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Getting the record metadata of keys 1-4 ≻", 'black', true);
$start = __LINE__;
$keys = array($key1, $key2, $key3, $key4);
$res = $db->existsMany($keys, $metadata);
if ($res == AEROSPIKE::OK) {
    echo success();
    var_dump($metadata);
} else {
    echo standard_fail($db);
}
    echo "php read-write-mix.php [--host=HOST] [--port=PORT] [--write-every=WRITE EVERY Nth RECORD] [--num-ops=RECORDS]\n";
    exit(1);
}
$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);
Exemplo n.º 8
0
$HOST_PORT = isset($args["p"]) ? (int) $args["p"] : (isset($args["port"]) ? (string) $args["port"] : 3000);
echo colorize("Connecting to the host ≻", 'black', true);
$start = __LINE__;
$config = array("hosts" => array(array("addr" => $HOST_ADDR, "port" => $HOST_PORT)));
$db = new Aerospike($config, false);
if (!$db->isConnected()) {
    echo fail("Could not connect to host {$HOST_ADDR}:{$HOST_PORT} [{$db->errorno()}]: {$db->error()}");
    exit(1);
}
echo success();
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Adding a record to test.vehicles with PK=M4G000 ≻", 'black', true);
$start = __LINE__;
$key = $db->initKey("test", "vehicles", "M4G000");
$vehicle = array("make" => "Mazda", "model" => "CX-3", "year" => 2014, "color" => "red");
$options = array(Aerospike::OPT_POLICY_KEY => Aerospike::POLICY_KEY_SEND);
$status = $db->put($key, $vehicle, 0, $options);
if ($status === Aerospike::OK) {
    echo success();
} else {
    echo standard_fail($db);
}
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Instantiating an LList representing bin 'rental_history' of the given record ≻", 'black', true);
$start = __LINE__;
require_once realpath(__DIR__ . '/../../autoload.php');
$rental_history = new \Aerospike\LDT\LList($db, $key, 'rental_history');
Exemplo n.º 9
0
    exit(1);
}
$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);
$log = $args["_args"][0];
$pid = getmypid();
echo "rw-worker.php launched with process ID {$pid}\n";
$config = array("hosts" => array(array("addr" => $addr, "port" => $port)));
$db = new Aerospike($config, false);
if (!$db->isConnected()) {
    file_put_contents($log, "{$pid}|0|0|0|0|0|0|0\n", FILE_APPEND);
    exit(1);
}
$key = $db->initKey("test", "rw-performance", $pid);
$writes = 0;
$write_fails = 0;
$reads = 0;
$read_fails = 0;
$begin = microtime(true);
$kv = array('v' => 0);
$res = $db->put($key, $kv);
if ($res !== Aerospike::OK) {
    $end = microtime(true);
    $delta = $end - $begin;
    $tps = 1 / $delta;
    file_put_contents($log, "{$pid}|1|{$delta}|{$tps}|0|0|1|1\n", FILE_APPEND);
    exit(2);
}
$writes++;
$HOST_PORT = isset($args["p"]) ? (int) $args["p"] : (isset($args["port"]) ? (string) $args["port"] : 3000);
echo colorize("Connecting to the host ≻", 'black', true);
$start = __LINE__;
$config = array("hosts" => array(array("addr" => $HOST_ADDR, "port" => $HOST_PORT)));
$db = new Aerospike($config, false);
if (!$db->isConnected()) {
    echo fail("Could not connect to host {$HOST_ADDR}:{$HOST_PORT} [{$db->errorno()}]: {$db->error()}");
    exit(1);
}
echo success();
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Adding a record to test.numbers with PK='primes' ≻", 'black', true);
$start = __LINE__;
$key = $db->initKey("test", "numbers", "primes");
$primes = array("types" => 1);
$options = array(Aerospike::OPT_POLICY_KEY => Aerospike::POLICY_KEY_SEND);
$status = $db->put($key, $primes, 0, $options);
if ($status === Aerospike::OK) {
    echo success();
} else {
    echo standard_fail($db);
}
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
echo colorize("Instantiating an LList representing centered triangular primes ≻", 'black', true);
$start = __LINE__;
require_once realpath(__DIR__ . '/../../autoload.php');
$tri_primes = new \Aerospike\LDT\LList($db, $key, 'triangular');
Exemplo n.º 11
0
    }
});
$app->get('/nonpersistent', function () {
    $config = array("hosts" => array(array("addr" => "127.0.0.1", "port" => "3000")));
    $db = new Aerospike($config, false);
    if (!$db->isConnected()) {
        echo "Aerospike failed to connect[{$db->errorno()}]: {$db->error()}\n";
        exit(1);
    } 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++) {
Exemplo n.º 12
0
     }
     // otherwise, mark it as raw
     return "r||" . $val;
 });
 class edu_course
 {
     public $course_name;
     public $duration;
     function __construct($name, $years)
     {
         $this->course_name = $name;
         $this->duration = $years;
     }
 }
 $BTech = new edu_course("B.Tech", 4);
 $key = $db->initKey("test", "demo", "example_key");
 $put_vals = array("education" => array("degree" => $BTech, "score" => 99.98999999999999, "passed" => TRUE));
 // will ensure a record exists at the given key with the specified bins using the registered serializer callback
 $res = $db->put($key, $put_vals, 100, array(Aerospike::OPT_SERIALIZER => Aerospike::SERIALIZER_USER));
 if ($res == Aerospike::OK) {
     echo "Record written.\n";
     // get the record using the registered deserializer callback
     $res = $db->get($key, $record);
     if ($res == Aerospike::OK) {
         var_dump($record);
     } elseif ($res == Aerospike::ERR_RECORD_NOT_FOUND) {
         echo "A user with key " . $key['key'] . " does not exist in the database\n";
     } else {
         echo "[{$db->errorno()}] " . $db->error();
     }
 } else {