Skip to main content

Simple Put-Get Example

For an interactive Jupyter notebook experience: Launch in Binder#

A simple example of put and get calls in Aerospike.

This notebook requires Aerospike datbase running locally and that Java kernel has been installed. Visit Aerospike notebooks repo for additional details and the docker container.

Use magics to load aerospike client from pom#

%%loadFromPOM<dependencies>  <dependency>    <groupId>com.aerospike</groupId>    <artifactId>aerospike-client</artifactId>    <version>5.0.0</version>  </dependency></dependencies>

Use client to write a record to Aerospike DB and read it back#

import com.aerospike.client.AerospikeClient;import com.aerospike.client.policy.WritePolicy;import com.aerospike.client.Bin;import com.aerospike.client.Key;import com.aerospike.client.Record;import com.aerospike.client.Value;
public class Test{    public static void putRecordGetRecord () {        AerospikeClient client = new AerospikeClient("localhost", 3000);
        Key key = new Key("test", "demo", "putgetkey");        Bin bin1 = new Bin("bin1", "value1");        Bin bin2 = new Bin("bin2", "value2");
        // Write a record        client.put(null, key, bin1, bin2);
        // Read a record        Record record = client.get(null, key);        client.close();           System.out.println("Record values are:");        System.out.println(record);    }}
Test.putRecordGetRecord()

You can also skip the java boilerplate#

import com.aerospike.client.AerospikeClient;import com.aerospike.client.policy.WritePolicy;import com.aerospike.client.Bin;import com.aerospike.client.Key;import com.aerospike.client.Record;import com.aerospike.client.Value;
AerospikeClient client = new AerospikeClient("localhost", 3000);
Key key = new Key("test", "demo", "putgetkey");Bin bin1 = new Bin("bin1", "value1");Bin bin2 = new Bin("bin2", "value2");
// Write a recordclient.put(null, key, bin1, bin2);
// Read a recordRecord record = client.get(null, key);client.close();   System.out.println("Record values are:");System.out.println(record);