-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcommand_args.rs
89 lines (71 loc) · 2.55 KB
/
command_args.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use crate::{
commands::{GenericCommands, HashCommands, SetCommands},
tests::get_test_client,
Result,
};
use serial_test::serial;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn key_value_collection() -> Result<()> {
let client = get_test_client().await?;
client.del("key").await?;
let items = ("field1", "value1");
let len = client.hset("key", items).await?;
assert_eq!(1, len);
client.del("key").await?;
let items = HashMap::from([("field1", "value1"), ("field2", "value2")]);
let len = client.hset("key", items).await?;
assert_eq!(2, len);
client.del("key").await?;
let items = BTreeMap::from([("field1", "value1"), ("field2", "value2")]);
let len = client.hset("key", items).await?;
assert_eq!(2, len);
client.del("key").await?;
let items = vec![("field1", "value1"), ("field2", "value2")];
let len = client.hset("key", items).await?;
assert_eq!(2, len);
client.del("key").await?;
let items = [("field1", "value1"), ("field2", "value2")];
let len = client.hset("key", items).await?;
assert_eq!(2, len);
client.del("key").await?;
let items = [("field1", "value1"), ("field2", "value2")];
let len = client.hset("key", items.as_slice()).await?;
assert_eq!(2, len);
client.close().await?;
Ok(())
}
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn set_collection() -> Result<()> {
let client = get_test_client().await?;
client.del("key").await?;
let items = "member1";
let len = client.sadd("key", items).await?;
assert_eq!(1, len);
client.del("key").await?;
let items = ["member1", "member2"];
let len = client.sadd("key", items).await?;
assert_eq!(2, len);
client.del("key").await?;
let items = ["member1", "member2"];
let len = client.sadd("key", items.as_slice()).await?;
assert_eq!(2, len);
client.del("key").await?;
let items = vec!["member1", "member2"];
let len = client.sadd("key", items).await?;
assert_eq!(2, len);
client.del("key").await?;
let items = HashSet::from(["member1", "member2"]);
let len = client.sadd("key", items).await?;
assert_eq!(2, len);
client.del("key").await?;
let items = BTreeSet::from(["member1", "member2"]);
let len = client.sadd("key", items).await?;
assert_eq!(2, len);
client.close().await?;
Ok(())
}