-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathnamespace.rs
39 lines (32 loc) · 1.1 KB
/
namespace.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Namespace example
use etcd_client::*;
#[tokio::main]
async fn main() -> Result<(), Error> {
let client = Client::connect(["localhost:2379"], None).await?;
let mut kv_client = client.kv_client();
let mut kv_client_prefix = KvClientPrefix::new(kv_client.clone(), "person/".into());
kv_client_prefix.put("Alice", "15", None).await?;
println!("put kv: {{Alice: 15}}");
// get prefixed kv
let resp = kv_client.get("person/Alice", None).await?;
if let Some(kv) = resp.kvs().first() {
println!(
"Get prefixed kv: {{{}: {}}}",
kv.key_str()?,
kv.value_str()?
);
}
// get kv
let resp = kv_client_prefix.get("Alice", None).await?;
if let Some(kv) = resp.kvs().first() {
println!("Get kv: {{{}: {}}}", kv.key_str()?, kv.value_str()?);
}
// delete kv
let resp = kv_client_prefix
.delete("Alice", Some(DeleteOptions::new().with_prev_key()))
.await?;
if let Some(kv) = resp.prev_kvs().first() {
println!("Delete kv: {{{}: {}}}", kv.key_str()?, kv.value_str()?);
}
Ok(())
}