Skip to content
Visit booth 3171 at Google Cloud Next to see how to unlock real-time decisions at scaleMore info

Primary index queries

Use the Aerospike C client scan APIs to initialize and populate an as_scan object, and then use the following calls to execute a scan:

  • aerospike_scan_foreach() — Execute the scan and call a function for each record.
  • aerospike_scan_background() — Execute the scan without results, which provides the ability to check the scan status.

Processing Results with aerospike_scan_foreach()

The aerospike_scan_foreach() call executes a scan, and calls a callback function for each record:

typedef bool (*aerospike_scan_foreach_callback)(const as_val *value, void *udata);

(*aerospike_scan_foreach_callback)() is called with each record found during the scan, with value, and with the user-provided udata. Note that value is const as_val *, which means that the callback is not responsible for destroying value, and value is only available within the scope of the callback. The callback should not send value outside of the scope of the callback.

The callback is called with a NULL value when there are no more results.

This example is a normal scan operation, where value is expected to be a record, and so casts value into a record using as_record_fromval():

  • If value is a record, then the function returns as_record.
  • If value is not a record, then NULL returns.

You can also use as_val_type() to check the value data type.

bool callback(const as_val *value, void *udata) {
if (value == NULL) {
// scan is complete
return true;
}
as_record *rec = as_record_fromval(value);
if (rec != NULL) {
// process record
}
return true;
}
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?