Setup
For the complete documentation index see: llms.txt
All documentation pages available in markdown.
Verify database is running
This tutorial requires that Aerospike database is running. Before
starting the examples below, verify this from a terminal with
asinfo (part of the
Aerospike Tools package), for example
asinfo -v status.
Download and install additional components
Install the Aerospike client for your preferred language in a version with support for expressions.
Add the Aerospike Java client to your project’s Maven pom.xml:
<dependencies> <dependency> <groupId>com.aerospike</groupId> <artifactId>aerospike-client</artifactId> <version>10.4</version> </dependency></dependencies>Install the Aerospike Python client and its aerospike_helpers package,
which provides the expressions used throughout this tutorial.
pip install aerospikeInstall the Aerospike Go client, which provides the expression builder functions used throughout this tutorial.
go get github.com/aerospike/aerospike-client-go/v6Install the Aerospike C# client NuGet package, which provides the expression builder classes used throughout this tutorial.
dotnet add package Aerospike.ClientInstall the Aerospike Node.js client, which provides the exp module
used throughout this tutorial.
npm install aerospikeInstall the Aerospike Rust client, which provides the expression builder functions used throughout this tutorial. The client requires an async runtime; this tutorial uses Tokio.
cargo add tokio --features macros,rt-multi-threadcargo add aerospike --features rt-tokioInitialize client
Initialize the client. Also, define constants including the namespace
test and set expressions and a convenient function
truncateTestData.
import com.aerospike.client.AerospikeClient;
AerospikeClient client = new AerospikeClient("localhost", 3000);System.out.println("Initialized the client and connected to the cluster.");
final String NAMESPACE = "test";final String SET_NAME = "expressions";
// convenience functions to truncate test datavoid truncateTestData() { try { client.truncate(null, NAMESPACE, SET_NAME, null); } catch (AerospikeException e) { // ignore }}Output:
Initialized the client and connected to the cluster.
import aerospike
config = {'hosts': [('127.0.0.1', 3000)]}client = aerospike.client(config).connect()print("Initialized the client and connected to the cluster.")
NAMESPACE = "test"SET_NAME = "expressions"
# convenience function to truncate test datadef truncate_test_data(): try: client.truncate(NAMESPACE, SET_NAME, 0) except aerospike.exception.AerospikeError: pass # ignoreOutput:
Initialized the client and connected to the cluster.
The Go examples in this tutorial build on the following setup, assumed
to persist for the rest of this page’s client, NAMESPACE, SET_NAME, and
truncateTestData across later code blocks (each block also lists any
additional imports it needs).
import ( "fmt" "log"
as "github.com/aerospike/aerospike-client-go/v6")
client, err := as.NewClient("localhost", 3000)if err != nil { log.Fatal(err)}fmt.Println("Initialized the client and connected to the cluster.")
const NAMESPACE = "test"const SET_NAME = "expressions"
// convenience function to truncate test datafunc truncateTestData() { if err := client.Truncate(nil, NAMESPACE, SET_NAME, nil); err != nil { // ignore }}Output:
Initialized the client and connected to the cluster.
The C# examples in this tutorial build on the following setup, assumed
to persist for the rest of this page’s client, NAMESPACE, SET_NAME, and
TruncateTestData across later code blocks.
using Aerospike.Client;
Host host = new Host("localhost", 3000);AerospikeClient client = new AerospikeClient(null, host);Console.WriteLine("Initialized the client and connected to the cluster.");
const string NAMESPACE = "test";const string SET_NAME = "expressions";
// convenience function to truncate test datavoid TruncateTestData(){ client.Truncate(null, NAMESPACE, SET_NAME, null);}Output:
Initialized the client and connected to the cluster.
The Node.js examples in this tutorial build on the following setup,
assumed to persist for the rest of this page’s client, NAMESPACE,
SET_NAME, and truncateTestData across later code blocks.
const Aerospike = require('aerospike');const exp = Aerospike.exp;const op = Aerospike.operations;
const config = { hosts: '127.0.0.1:3000' };const client = await Aerospike.connect(config);console.log('Initialized the client and connected to the cluster.');
const NAMESPACE = 'test';const SET_NAME = 'expressions';
// convenience function to truncate test dataasync function truncateTestData() { await client.truncate(NAMESPACE, SET_NAME, 0);}Output:
Initialized the client and connected to the cluster.
The Rust examples in this tutorial build on the following setup, assumed
to persist for the rest of this page’s client, NAMESPACE, SET, and
truncate_test_data across later code blocks. Each block runs inside an
async function, for example #[tokio::main] async fn main() -> aerospike::Result<()> { ... }, so .await and ? are available.
use aerospike::{AdminPolicy, Client, ClientPolicy};
let client = Client::new(&ClientPolicy::default(), &"127.0.0.1:3000".to_string()).await?;println!("Initialized the client and connected to the cluster.");
const NAMESPACE: &str = "test";const SET: &str = "expressions";
// convenience function to truncate test dataasync fn truncate_test_data(client: &Client) { let _ = client.truncate(&AdminPolicy::default(), NAMESPACE, SET, 0).await;}Output:
Initialized the client and connected to the cluster.
Access shell commands
You may execute shell commands including Aerospike tools such as aql and asadm from a terminal throughout this tutorial.
Next
Continue to Understanding expressions.