12 releases (4 stable)

1.3.0 May 1, 2023
1.2.0 Oct 22, 2021
1.0.0 Oct 29, 2020
0.6.0 Sep 11, 2020
0.0.1 Feb 8, 2017

#729 in Database interfaces

Download history 150/week @ 2024-05-26 123/week @ 2024-06-02 193/week @ 2024-06-09 277/week @ 2024-06-16 322/week @ 2024-06-23 186/week @ 2024-06-30 243/week @ 2024-07-07 178/week @ 2024-07-14 184/week @ 2024-07-21 284/week @ 2024-07-28 539/week @ 2024-08-04 139/week @ 2024-08-11 227/week @ 2024-08-18 246/week @ 2024-08-25 135/week @ 2024-09-01 188/week @ 2024-09-08

806 downloads per month

Apache-2.0

640KB
13K SLoC

Aerospike Rust Client crates-io docs travis appveyor

An Aerospike client library for Rust.

This library is compatible with Rust 1.46+ and supports the following operating systems: Linux, Mac OS X, and Windows. The current release supports Aerospike version v5.6 and later. Take a look at the changelog for more details.

Usage:

The following is a very simple example of CRUD operations in an Aerospike database.

#[macro_use]
extern crate aerospike;

use std::env;
use std::time::Instant;

use aerospike::{Bins, Client, ClientPolicy, ReadPolicy, WritePolicy};
use aerospike::operations;

fn main() {
    let cpolicy = ClientPolicy::default();
    let hosts = env::var("AEROSPIKE_HOSTS")
        .unwrap_or(String::from("127.0.0.1:3000"));
    let client = Client::new(&cpolicy, &hosts)
        .expect("Failed to connect to cluster");

    let now = Instant::now();
    let rpolicy = ReadPolicy::default();
    let wpolicy = WritePolicy::default();
    let key = as_key!("test", "test", "test");

    let bins = [
        as_bin!("int", 999),
        as_bin!("str", "Hello, World!"),
    ];
    client.put(&wpolicy, &key, &bins).unwrap();
    let rec = client.get(&rpolicy, &key, Bins::All);
    println!("Record: {}", rec.unwrap());

    client.touch(&wpolicy, &key).unwrap();
    let rec = client.get(&rpolicy, &key, Bins::All);
    println!("Record: {}", rec.unwrap());

    let rec = client.get(&rpolicy, &key, Bins::None);
    println!("Record Header: {}", rec.unwrap());

    let exists = client.exists(&wpolicy, &key).unwrap();
    println!("exists: {}", exists);

    let bin = as_bin!("int", "123");
    let ops = &vec![operations::put(&bin), operations::get()];
    let op_rec = client.operate(&wpolicy, &key, ops);
    println!("operate: {}", op_rec.unwrap());

    let existed = client.delete(&wpolicy, &key).unwrap();
    println!("existed (should be true): {}", existed);

    let existed = client.delete(&wpolicy, &key).unwrap();
    println!("existed (should be false): {}", existed);

    println!("total time: {:?}", now.elapsed());
}

Known Limitations

The following features are not yet supported in the Aerospike Rust client:

  • Query Aggregation using Lua User-Defined Functions (UDF).
  • Secure connections using TLS.
  • IPv6 support.

Tests

This library is packaged with a number of tests. The tests assume that an Aerospike cluster is running at localhost:3000. To test using a cluster at a different address, set the AEROSPIKE_HOSTS environment variable to the list of cluster hosts.

To run all the test cases:

$ export AEROSPIKE_HOSTS=127.0.0.1:3000
$ cargo test

To enable debug logging for the aerospike crate:

$ RUST_LOG=aerospike=debug cargo test

To enable backtraces set the RUST_BACKTRACE environment variable:

$ RUST_BACKTRACE=1 cargo test

Benchmarks

The micro-benchmarks in the benches directory use the bencher crate and can be run on Rust stable releases:

$ export AEROSPIKE_HOSTS=127.0.0.1:3000
$ cargo bench

There is a separate benchmark tool under the tools/benchmark directory that is designed to insert data into an Aerospike server cluster and generate load.

Dependencies

~6–12MB
~144K SLoC