etcd for Rust

Crates.io Docs.rs MIT licensed Travis Build Status

NOTE: Branch master is currently under development. For v0.1.x based releases please check out the v0.1.x branch.

Features

Examples

./examples

Usage

Add following dependencies in your project cargo.toml:

toml [dependencies] etcd-rs = "0.2.0-alpha.1"

Setup Client

```rust let endpoints = vec!["http://127.0.0.1:2379".to_owned()];

let client = Client::new(ClientConfig { endpoints, auth: None, }); ```

Key Value

Put

rust client.kv().put(PutRequest::new("foo", "bar")).await?;

Get

Get a key-value pair

rust let resp = client.kv().get(KeyRange::key("foo")).await?;

List key-value paris by prefix

rust let resp = client.kv().get(KeyRange::prefix("foo")).await?;

List all key-value paris

rust let resp = client.kv().get(KeyRange::all()).await?;

Delete

Delete a key-value pair

rust client.kv().delete(KeyRange::key("foo")).await?;

Delete key-value paris by prefix

rust client.kv().delete(KeyRange::prefix("foo")).await?;

Delete all key-value paris

rust client.kv().delete(KeyRange::all()).await?;

Lease

Grant

```rust let lease = client .lease() .grant(LeaseGrantRequest::new(Duration::from_secs(3))) .await?;

println!("lease id: {}", lease.id());

// Put key-value with the above lease client .kv() .put({ let mut req = PutRequest::new(key, "bar"); req.set_lease(lease.id());

    req
})
.await?;

```

Revoke

rust client.lease().revoke(LeaseRevokeRequest::new(lease_id)).await?;

Keep Alive

```rust use tokio::timer::Interval; let mut interval = Interval::newinterval(Duration::fromsecs(1));

loop { interval.next().await; client .lease() .keepalive(LeaseKeepAliveRequest::new(leaseid)) .await; } ```

License

This project is licensed under the MIT license.