-
Notifications
You must be signed in to change notification settings - Fork 28
Query Records
Use the Aerospike PHP client to perform queries on a secondary index of a set. Similar to a scan, records matched to the query return to the client as a stream of records. Each record in the stream passes to a callback function for processing.
To halt record streams initiated by a scan or query, have the callback return false
.
The query()
method includes namespace and set parameters to identify the set to query, a predicate, a callback record handler, and (optionally) a subset of named bins to project.
The $where
predicate argument must follow a strict structure, so the Aerodpike PHP client provides these helper methods:
predicateEquals()
predicateBetween()
$where = Aerospike::predicateBetween("age", 30, 39);
$status = $db->query("infosphere", "characters", $where, function ($record) {
var_dump($record); });
This example only returns records that include the name bin:
$where = Aerospike::predicateBetween("age", 30, 39);
$status = $db->query("infosphere", "characters", $where, function ($record) {
var_dump($record);
}, ["name", "age"]);
This example buffers the records streaming back from the server into the $result
variable:
$result = array();
$where = Aerospike::predicateBetween("age", 30, 39);
$status = $db->query("test", "users", $where, function ($record) use (&$result) {
$result[] = $record['bins'];
});
if ($status !== Aerospike::OK) {
echo "An error occured while querying[{$db->errorno()}] {$db->error()}\n";
} else {
echo "The query returned ".count($result)." records\n";
}
PHP Client