rsoffkv 0.1.4

A uniform interface for 3 different distributed key-value storages: Zookeeper, Consul, ETCD
docs.rs failed to build rsoffkv-0.1.4
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: rsoffkv-0.1.8

License Travis CI Travis CI codecov

rsoffkv

This library is designed to provide a uniform interface for 3 different distributed KV-storages: etcd, Zookeeper, Consul.

Rsoffkv is a wrapper around our C++ library liboffkv. Design details can be found in the liboffkv repository.

Build

  • install vcpkg and set VCPKG_ROOT
  • install dependencies (you can build build rsoffkv only for some of the supported KV-storages; in such a case feel free to change the value of ENABLE_ in the build script)
vcpkg install ppconsul offscale-libetcd-cpp zkpp
  • build with cargo
cargo build
  • (optional) run documentation tests
cargo test

Example

use rsoffkv::client::Client;
use rsoffkv::result::OffkvError;

use rsoffkv::txn::{Transaction, TxnCheck, TxnOp, TxnOpResult};

use std::{thread,time};

fn main() {
    // firstly specify service {zk | consul | etcd} and its address
    // you can also specify a prefix all keys will start with
    let client = Client::new("consul://localhost:8500", "/prefix").unwrap();
    
    // Each method returns std::Result
    match client.create("/key", "value", false) {
        Ok(initial_version) => 
            println!("Key \"/prefix/key\" successfully created. Initial version: {}",
                     initial_version),
        Err(OffkvError::EntryExists) =>
            println!("Error: key \"/prefix/key\" already exists!"),
    };
    
    // WATCH EXAMPLE
    let (result, watch_handle) = client.exists("/key", true).unwrap();
    
    thread::spawn(|| {
        let another_client = Client::new("consul://localhost:8500", "/prefix", false).unwrap();
        thread::sleep(time::Duration::from_secs(5));
        another_client.erase("/key", 0).unwrap();
    });
    
    // now the key exists
    assert!(result);
    
    // wait for changes
    watch_handle.wait();
    
    // if the waiting was completed, the existence state must be different
    let (result, _) = client.exists("/key", false).unwrap();
    assert!(!result);
    
    // TRANSACTION EXAMPLE
    match client.commit(
        // firstly list your checks
        checks: vec![
            TxnCheck{key: "/key", version: initial_version},
        ],
        // then operations
        ops: vec![
            TxnOp::Create{key: "/key/child", value: "value", leased: false},
            TxnOp::Set{key: "/key", value: "new value"},
        ],
    ) {
        // on success a vector with changed version is returned
        Ok(_) => println!("Success!"),
        // on failure an index of the first failed operation is returned
        Err(OffkvError::TxnFailed(failed_op)) => println!("Failed at {}", failed_op),
    };
}