Crate aerospike[][src]

Expand description

A pure-rust client for the Aerospike NoSQL database.

Aerospike is an enterprise-class, NoSQL database solution for real-time operational applications, delivering predictable performance at scale, superior uptime, and high availability at the lowest TCO compared to first-generation NoSQL and relational databases. For more information please refer to https://www.aerospike.com/.

Installation

Add this to your Cargo.toml:

[dependencies]
aerospike = "1.0.0"

Examples

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

#[macro_use]
extern crate aerospike;

use std::env;
use std::sync::Arc;
use std::time::Instant;
use std::thread;

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 client = Arc::new(client);

    let mut threads = vec![];
    let now = Instant::now();
    for i in 0..2 {
        let client = client.clone();
        let t = thread::spawn(move || {
            let rpolicy = ReadPolicy::default();
            let wpolicy = WritePolicy::default();
            let key = as_key!("test", "test", i);
            let bins = [
                as_bin!("int", 123),
                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", 999);
            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 (sould be true): {}", existed);

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

        threads.push(t);
    }

    for t in threads {
        t.join().unwrap();
    }

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

Re-exports

pub use errors::Error;
pub use errors::ErrorKind;
pub use errors::Result;
pub use expressions::regex_flag::RegexFlag;
pub use operations::MapPolicy;
pub use operations::MapReturnType;
pub use operations::MapWriteMode;
pub use policy::Policy;

Modules

Error and Result types for the Aerospike client.

Functions used for Filter Expressions. This module requires Aerospike Server version >= 5.2

Functions used to create database operations used in the client’s operate() method.

Policy types encapsulate optional parameters for various client operations.

Types and methods used for database queries and scans.

Types and methods used for long running status queries.

Macros

Construct a new bin from a name and an optional value (defaults to the empty value nil).

Constructs a new Blob Value from one of the supported native data types.

Create contains number filter for queries on a collection index.

Create contains range filter for queries on a collection index.

Create equality filter for queries; supports integer and string values.

Constructs a new GeoJSON Value from one of the supported native data types.

Construct a new key given a namespace, a set name and a user key.

Constructs a new List Value from a list of one or more native data types.

Constructs a Map Value from a list of key/value pairs.

Create range filter for queries; supports integer values.

Create geospatial “regions containing point” filter for queries. For queries on a collection index the collection index type must be specified.

Constructs a new Value from one of the supported native data types.

Constructs a vector of Values from a list of one or more native data types.

Create geospatial “points within radius” filter for queries. For queries on a collection index the collection index type must be specified.

Create geospatial “points within region” filter for queries. For queries on a collection index the collection index type must be specified.

Structs

BatchPolicy encapsulates parameters for all batch operations.

Key and bin names used in batch read commands where variable bins are needed for each key.

Container object for a record bin, comprising a name and a value.

Instantiate a Client instance to access an Aerospike database cluster and perform database operations.

ClientPolicy encapsulates parameters for client policy command.

Host name/port of database server.

Struct for querying index creation status

Unique record identifier. Records can be identified using a specified namespace, an optional set name and a user defined key which must be uique within a set. Records can also be identified by namespace/digest, which is the combination used on the server.

QueryPolicy encapsulates parameters for query operations.

Container object for a database record.

Virtual collection of records retrieved through queries and scans. During a query/scan, multiple threads will retrieve records from the server nodes and put these records on an internal queue managed by the recordset. The single user thread consumes these records from the queue.

Struct for querying udf register status

ScanPolicy encapsulates optional parameters used in scan operations.

Query statement parameters.

User and assigned roles.

WritePolicy encapsulates parameters for all write operations.

Enums

Specify which, if any, bins to return in read operations.

Secondary index collection type.

CommitLevel determines how to handle record writes based on record generation.

Specifies whether a command, that needs to be executed on multiple cluster nodes, should be executed sequentially, one node at a time, or in parallel on multiple nodes using the client’s thread pool.

ConsistencyLevel indicates how replicas should be consulted in a read operation to provide the desired consistency guarantee.

Record expiration, also known as time-to-live (TTL).

Container for floating point bin values stored in the Aerospike database.

GenerationPolicy determines how to handle record writes based on record generation.

Underlying data type of secondary index.

Priority of operations on database server.

RecordExistsAction determines how to handle record writes based on record generation.

Database operation error codes. The error codes are defined in the server-side file proto.h.

User-defined function (UDF) language

Container for bin values stored in the Aerospike database.

Traits

Base task interface

Type Definitions

ReadPolicy excapsulates parameters for transaction policy attributes used in all database operation calls.