Module aerospike::errors

source ·
Expand description

Error and Result types for the Aerospike client.

Examples

Handling an error returned by the client.

use aerospike::*;

let hosts = std::env::var("AEROSPIKE_HOSTS").unwrap_or("localhost".into());
let policy = ClientPolicy::default();
let client = Client::new(&policy, &hosts).expect("Failed to connect to cluster");
let key = as_key!("test", "test", "someKey");
match client.get(&ReadPolicy::default(), &key, Bins::None) {
    Ok(record) => {
        match record.time_to_live() {
            None => println!("record never expires"),
            Some(duration) => println!("ttl: {} secs", duration.as_secs()),
        }
    },
    Err(Error(ErrorKind::ServerError(ResultCode::KeyNotFoundError), _)) => {
        println!("No such record: {}", key);
    },
    Err(err) => {
        println!("Error fetching record: {}", err);
        for err in err.iter().skip(1) {
            println!("Caused by: {}", err);
        }
        // The backtrace is not always generated. Try to run this example
        // with `RUST_BACKTRACE=1`.
        if let Some(backtrace) = err.backtrace() {
            println!("Backtrace: {:?}", backtrace);
        }
    }
}

Structs

Enums

Traits

  • Additional methods for Result, for easy interaction with this crate.

Type Definitions

  • Convenient wrapper around std::Result.