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

Asynchronous read

The async get method takes extra event loop and write listener arguments. The listener is called when the get() completes.

Initiate the Read

import com.aerospike.client.async.EventLoop;
import com.aerospike.client.async.EventLoops;
// Find an event loop from eventLoops created in connect example.
EventLoop eventLoop = eventLoops.next();
// Read all the bins.
Policy policy = new Policy();
Key key = new Key("test", "myset", "mykey");
client.get(eventLoop, new ReadHandler(), policy, key);

Completion Handler

When the database returns from the read command, either onSuccess or onFailure is called.

private class ReadHandler implements RecordListener {
@Override
public void onSuccess(Key key, Record record) {
// Read completed.
Object received = (record == null)? null : record.getValue("mybin");
System.out.println(String.format("Received: " + received));
}
@Override
public void onFailure(AerospikeException e) {
e.printStackTrace();
}
}
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?