Skip to content

Latest commit

 

History

History
129 lines (105 loc) · 3.77 KB

apiref_kv.md

File metadata and controls

129 lines (105 loc) · 3.77 KB

Key-Value Methods

public string Aerospike::getKeyDigest (string $ns, string $set, string|int $pk)
public array initKey ( string $ns, string $set, int|string $pk [, boolean $is_digest = false ] )
public string getKeyDigest ( string $ns, string $set, int|string $pk )
public int Aerospike::put ( array $key, array $bins [, int $ttl = 0 [, array $options ]] )
public int Aerospike::get ( array $key, array &$record [, array $filter [, array $options ]] )
public int Aerospike::remove ( array $key [, array $options ] )
public int Aerospike::removeBin ( array $key, array $bins [, array $options ] )
public int Aerospike::exists ( array $key, array &$metadata [, array $options ] )
public int Aerospike::getMetadata ( array $key, array &$metadata [, array $options ] )
public int Aerospike::touch ( array $key, int $ttl = 0 [, array $options ] )
public int Aerospike::increment ( array $key, string $bin, int $offset [, array $options ] )
public int Aerospike::append ( array $key, string $bin, string $value [, array $options ] )
public int Aerospike::prepend ( array $key, string $bin, string $value [, array $options ] )
public int Aerospike::operate ( array $key, array $operations [, array &$returned ] )
public int Aerospike::getMany ( array $keys, array &$records [, array $filter [, array $options]] )
public int Aerospike::existsMany ( array $keys, array &$metadata [, array $options ] )
public static Aerospike::setSerializer ( callback $serialize_cb )
public static Aerospike::setDeserializer ( callback $unserialize_cb )

Example

<?php

$config = array("hosts"=>array(array("addr"=>"localhost", "port"=>3000)));
$db = new Aerospike($config);
if (!$db->isConnected()) {
   echo "Aerospike failed to connect[{$db->errorno()}]: {$db->error()}\n";
   exit(1);
}

$key = $db->initKey("test", "users", 1234);
$bins = array("email" => "[email protected]", "name" => "Hey There");
// attempt to 'CREATE' a new record at the specified key
$status = $db->put($key, $bins, 0, array(Aerospike::OPT_POLICY_EXISTS => Aerospike::POLICY_EXISTS_CREATE));
if ($status == Aerospike::OK) {
    echo "Record written.\n";
} elseif ($status == Aerospike::ERR_RECORD_EXISTS) {
    echo "The Aerospike server already has a record with the given key.\n";
} else {
    echo "[{$db->errorno()}] ".$db->error();
}

// check for the existance of the given key in the database, then fetch it
if ($db->exists($key, $foo) == Aerospike::OK) {
    $status = $db->get($key, $record);
    if ($status == Aerospike::OK) {
        var_dump($record);
    }
}

// filtering for specific keys
$status = $db->get($key, $record, array("email"), Aerospike::POLICY_RETRY_ONCE);
if ($status == Aerospike::OK) {
    echo "The email for this user is ". $record['bins']['email']. "\n";
    echo "The name bin should be filtered out: ".var_export(is_null($record['bins']['name']), true). "\n";
}
?>