Skip to content

Latest commit

 

History

History
55 lines (44 loc) · 1.59 KB

apiref_streams.md

File metadata and controls

55 lines (44 loc) · 1.59 KB

Query and Scan Methods

public int Aerospike::query ( string $ns, string $set, array $where, callback $record_cb [, array $bins [, array $options ]] )
public int Aerospike::scan ( string $ns, string $set, callback $record_cb [, array $bins [, array $options ]] )
public array Aerospike::predicateEquals ( string $bin, int|string $val )
public array Aerospike::predicateBetween ( string $bin, int $min, int $max )

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);
}

$total = 0;
$in_thirties = 0;
$where = Aerospike::predicateBetween("age", 30, 39);
$res = $db->query("test", "users", $where, function ($record) {
    echo "{$record['email']} age {$record['age']}\n";
    $total += (int) $record['age'];
    $in_thirties++;
    if ($in_thirties >= 10) return false; // stop the stream at the tenth record
}, array("email", "age"));
if ($res == Aerospike::ERR_QUERY) {
    echo "An error occured while querying[{$db->errorno()}] ".$db->error();
else if ($res == Aerospike::ERR_QUERY_ABORTED) {
    echo "Stopped the result stream after {$in_thirties} results\n";
} else {
    echo "The average age of employees in their thirties is ".round($total / $in_thirties)."\n";
}

?>