$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');
if ($characters->errorno() === Aerospike::OK) {
    echo success();
} else {
Ejemplo n.º 2
0
$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);
if ($status == Aerospike::OK) {
    echo success();
Ejemplo n.º 3
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("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');
if ($rental_history->errorno() === Aerospike::OK) {
    echo success();
} else {
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);
}
if (isset($args['a']) || isset($args['annotate'])) {
Ejemplo n.º 5
0
$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", "write");
$write_fails = 0;
$writes = 0;
$kv = array("v" => 0);
$begin = microtime(true);
echo colorize("Write {$total_ops} records ≻", 'black', true);
for ($num_ops = 1; $num_ops <= $total_ops; $num_ops++) {
    $kv['v']++;
    $key['key'] = 'write-' . $kv['v'];
    $res = $db->put($key, $kv);
    $writes++;
    if ($res !== Aerospike::OK) {
        $write_fails++;
        // roll back the test value
        $kv['v']--;
    }
}
$end = microtime(true);
if ($write_fails == 0) {
    echo success();
} else {
    echo standard_fail($db);
}
echo colorize("{$writes} sequential writes\n", 'green', true);
$color = $write_fails > 0 ? 'red' : 'green';
$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');
if ($tri_primes->errorno() === Aerospike::OK) {
    echo success();
} else {
Ejemplo n.º 7
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++) {
            $key = $db->initKey("test", "demo", "key" . $i);
            $record = array("name" => "name" . $i, "age" => $i);
$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("Creating a new record in test.characters at PK=1, only if none exists ≻", 'black', true);
$start = __LINE__;
$needs_force = false;
$key = $db->initKey("test", "characters", 1);
$put_vals = array("title" => "Professor", "name" => "Hubert J. Farnsworth", "age" => 150, "is_senior" => true, "positions" => array("Inventor", "Founder", "Lecturer", "Scientist", "Hyper Yeti"));
$status = $db->put($key, $put_vals, 300, array(Aerospike::OPT_POLICY_EXISTS => Aerospike::POLICY_EXISTS_CREATE));
if ($status == Aerospike::OK) {
    echo success();
} elseif ($status == Aerospike::ERR_RECORD_EXISTS) {
    echo fail("There already is a record at PK={$key['key']} in the set test.characters");
    $needs_force = true;
} else {
    echo standard_fail($db);
    $needs_force = true;
}
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
if ($needs_force) {
    echo colorize("Retrying to insert a record in test.characters at PK=1 using Aerospike::POLICY_EXISTS_IGNORE ≻", 'black', true);
    $start = __LINE__;
Ejemplo n.º 9
0
    });
    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 {
        echo "[{$db->errorno()}] " . $db->error();
    }
}