NOTE: Branch master is currently under development. For v0.1.x based releases please check out the v0.1.x branch.
Add following dependencies in your project cargo.toml
:
toml
[dependencies]
etcd-rs = "0.2.0-alpha.1"
```rust let endpoints = vec!["http://127.0.0.1:2379".to_owned()];
let client = Client::new(ClientConfig { endpoints, auth: None, }); ```
rust
client.kv().put(PutRequest::new("foo", "bar")).await?;
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 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?;
```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?;
```
rust
client.lease().revoke(LeaseRevokeRequest::new(lease_id)).await?;
```rust use tokio::timer::Interval; let mut interval = Interval::newinterval(Duration::fromsecs(1));
loop { interval.next().await; client .lease() .keepalive(LeaseKeepAliveRequest::new(leaseid)) .await; } ```
This project is licensed under the MIT license.