Skip to content

Latest commit

 

History

History
73 lines (54 loc) · 2.02 KB

aerospike_exists.md

File metadata and controls

73 lines (54 loc) · 2.02 KB

Aerospike::exists

Aerospike::exists - check if a record exists in the Aerospike database

Description

public int Aerospike::exists ( array $key, array &$metadata [, array $options ] )

Aerospike::exists() will check if a record with a given key exists in the database. If such a key exists its metadata will be returned in the metadata variable, otherwise it will be NULL.

Parameters

key the key under which the record can be found. An array with keys ['ns','set','key'] or ['ns','set','digest'].

metadata filled by an array of metadata.

options including

Return Values

Returns an integer status code. Compare to the Aerospike class status constants. When non-zero the Aerospike::error() and Aerospike::errorno() methods can be used.

Examples

<?php

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

$key = $client->initKey("test", "users", 1234);
$status = $client->exists($key, $metadata);
if ($status == Aerospike::OK) {
    var_dump($metadata);
} elseif ($status == Aerospike::ERR_RECORD_NOT_FOUND) {
    echo "A user with key ". $key['key']. " does not exist in the database\n";
} else {
    echo "[{$client->errorno()}] ".$client->error();
}

?>

We expect to see:

array(2) {
  ["generation"]=>
  int(4)
  ["ttl"]=>
  int(1337)
}

or

A user with key 1234 does not exist in the database.