Skip to content

Quickstart

For the complete documentation index see: llms.txt

All documentation pages available in markdown.

This Quickstart guide walks you through the essentials of deploying an Aerospike Database and building a simple application to interact with it. You’ll learn how to quickly spin up a local development environment using Docker, set up your project in your preferred programming language, connect to the database, and perform basic read and write operations.

Deploy Aerospike with Docker

The quickest and easiest way to get up and running quickly is with Docker.

The following command creates a single node Aerospike Enterprise database, using the latest version, equipped with a single node feature key and template configuration. No additional setup is needed.

Terminal window
docker run -d --name aerospike -p 3000-3002:3000-3002 aerospike/aerospike-server-enterprise:latest

If you’d like to customize your deployment, see configuring Aerospike for more information. Aerospike has a variety of options when it comes to deploying the database.

  • AeroLab is a community-supported tool for quickly spinning up development clusters.
  • You can deploy containers directly using Docker or Kubernetes Operator.
  • Aerospike supports the three major cloud providers, AWS, GCP, and Azure.
  • Bare metal deployments are available with a variety of Linux distributions as well.

Browse your cluster with Voyager

After deploying Aerospike Database, point Aerospike Voyager at the cluster you just started. Voyager is a free desktop app that gives you a visual workspace for adding sample data, browsing, and editing records.

Download Voyager and connect it to 127.0.0.1:3000. See Connecting to clusters for more information.

Voyager data browser showing the sidebar cluster tree expanded to sample sets, with sample_users records displayed as cards with type badges for boolean, map, integer, string, and geojson bins

Set up your development environment

Grab your favorite IDE and create a new project.

The Java SDK requires Java 21 or later. For this quickstart we’ll be using Maven for our build manager. After creating your project, add the following dependency to the pom.xml file.

<dependencies>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-client-sdk</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>

If you’re using a different build manager, or looking for more information on getting started with the Java SDK, check out the Developer SDK install docs.

Application basics

The following code block contains the necessary imports and basic application shell to get started.

package com.sample;
import java.time.Duration;
import com.aerospike.client.sdk.AerospikeException;
import com.aerospike.client.sdk.Cluster;
import com.aerospike.client.sdk.ClusterDefinition;
import com.aerospike.client.sdk.DataSet;
import com.aerospike.client.sdk.Key;
import com.aerospike.client.sdk.Record;
import com.aerospike.client.sdk.Session;
import com.aerospike.client.sdk.policy.Behavior;
import com.aerospike.client.sdk.policy.Behavior.Selectors;
public class App
{
public static void main( String[] args )
{
}
}

Client connection

The minimum information you need to connect to an Aerospike database is the server IP address and port number. If you’re using the basic Docker install from step one, the following information should work just fine.

If your database is deployed with a cloud provider or installed elsewhere, you’ll need information specific to your cluster setup.

Create variables to store the connection information, as well as the namespace and set name.

Using the address and port from above, instantiate the Aerospike client.

String address = "127.0.0.1"; // Aerospike address
int port = 3000; // Aerospike port
String namespace = "test"; // Cluster namespace
String set = "foo"; // Set name within namespace
// The session's Behavior sets the timeout: 5 seconds for every command
Behavior behavior = Behavior.DEFAULT.deriveWithChanges("quickstart", b -> b
.on(Selectors.all(), ops -> ops.abandonCallAfter(Duration.ofSeconds(5))));
Cluster cluster = new ClusterDefinition(address, port).connect();
Session session = cluster.createSession(behavior);

Write a record

  1. Create the record key from a DataSet, which names the namespace and set, and a user defined key. The session’s Behavior already sets the timeout, so there is no write policy to create.

    Key key = DataSet.of(namespace, set).id("bar");
  2. Write the record to Aerospike, with a bin to store data within the new record.

    try {
    session.upsert(key)
    .bin("myBin").setTo("Hello World!")
    .execute();
    System.out.println("Successfully wrote record");
    }
    catch (AerospikeException e) {
    e.printStackTrace();
    }

Read a record

  1. Using the same key from our write command, read the record back. The session’s Behavior sets the timeout for reads too.

    try {
    Record record = session.query(key).execute().getFirstRecord();
    System.out.println("Record: " + record.bins);
    }
    catch (AerospikeException e) {
    e.printStackTrace();
    }
    finally {
    cluster.close();
    }

Check out the Develop topic for more in-depth code samples and content to help you get started!

Put it all together

Check out the full code sample
package com.sample;
import java.time.Duration;
import com.aerospike.client.sdk.AerospikeException;
import com.aerospike.client.sdk.Cluster;
import com.aerospike.client.sdk.ClusterDefinition;
import com.aerospike.client.sdk.DataSet;
import com.aerospike.client.sdk.Key;
import com.aerospike.client.sdk.Record;
import com.aerospike.client.sdk.Session;
import com.aerospike.client.sdk.policy.Behavior;
import com.aerospike.client.sdk.policy.Behavior.Selectors;
public class App
{
public static void main( String[] args )
{
// ***
// Setup
// ***
String address = "127.0.0.1"; // Aerospike address
int port = 3000; // Aerospike port
String namespace = "test"; // Cluster namespace
String set = "foo"; // Set name within namespace
// The session's Behavior sets the timeout: 5 seconds for every command
Behavior behavior = Behavior.DEFAULT.deriveWithChanges("quickstart", b -> b
.on(Selectors.all(), ops -> ops.abandonCallAfter(Duration.ofSeconds(5))));
// Create the client and connect to the database
Cluster cluster = new ClusterDefinition(address, port).connect();
Session session = cluster.createSession(behavior);
// ***
// Write a record
// ***
// Create the record key
// A DataSet names the namespace and set; id() takes the user defined key
Key key = DataSet.of(namespace, set).id("bar");
// Write the record to your database, with a bin to store data within it
try {
session.upsert(key)
.bin("myBin").setTo("Hello World!")
.execute();
System.out.println("Successfully wrote record");
}
catch (AerospikeException e) {
e.printStackTrace();
}
// ***
// Read back the record we just wrote
// ***
// Read the record
try {
Record record = session.query(key).execute().getFirstRecord();
System.out.println("Record: " + record.bins);
}
catch (AerospikeException e) {
e.printStackTrace();
}
finally {
cluster.close();
}
}
}