-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathhyper_log_log_commands.rs
69 lines (51 loc) · 1.77 KB
/
hyper_log_log_commands.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
use crate::{
commands::{FlushingMode, HyperLogLogCommands, ServerCommands},
tests::get_test_client,
Result,
};
use serial_test::serial;
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn pfadd() -> Result<()> {
let client = get_test_client().await?;
client.flushdb(FlushingMode::Sync).await?;
let result = client.pfadd("key", "a").await?;
assert!(result);
let result = client.pfadd("key", ["b", "c", "d", "e", "f", "g"]).await?;
assert!(result);
let result = client.pfadd("key", "a").await?;
assert!(!result);
let result = client.pfadd("key", ["c", "d", "e"]).await?;
assert!(!result);
Ok(())
}
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn pfcount() -> Result<()> {
let client = get_test_client().await?;
client.flushdb(FlushingMode::Sync).await?;
client
.pfadd("key1", ["a", "b", "c", "d", "e", "f", "g"])
.await?;
let count = client.pfcount("key1").await?;
assert_eq!(7, count);
client.pfadd("key2", ["f", "g", "h", "i"]).await?;
let count = client.pfcount(["key1", "key2"]).await?;
assert_eq!(9, count);
Ok(())
}
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn pfmerge() -> Result<()> {
let client = get_test_client().await?;
client.flushdb(FlushingMode::Sync).await?;
client.pfadd("key1", ["foo", "bar", "zap", "a"]).await?;
client.pfadd("key2", ["a", "b", "c", "foo"]).await?;
client.pfmerge("out", ["key1", "key2"]).await?;
let count = client.pfcount("out").await?;
assert_eq!(6, count);
Ok(())
}