-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtop_k_commands.rs
125 lines (98 loc) · 3.61 KB
/
top_k_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
use crate::{
commands::{FlushingMode, ServerCommands, TopKCommands, TopKListWithCountResult},
tests::get_redis_stack_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 tdigest_add() -> Result<()> {
let client = get_redis_stack_test_client().await?;
client.flushall(FlushingMode::Sync).await?;
client.topk_reserve("key", 3, None).await?;
let item: Vec<Option<String>> = client.topk_add("key", "baz").await?;
assert_eq!(vec![None], item);
let items: Vec<Option<String>> = client.topk_add("key", ["foo", "bar", "42"]).await?;
assert_eq!(vec![None, None, Some("baz".to_owned())], items);
Ok(())
}
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn tdigest_incrby() -> Result<()> {
let client = get_redis_stack_test_client().await?;
client.flushall(FlushingMode::Sync).await?;
client.topk_reserve("key", 3, None).await?;
let items: Vec<Option<String>> = client
.topk_incrby("key", [("foo", 3), ("bar", 2), ("42", 30)])
.await?;
assert_eq!(vec![None, None, None], items);
Ok(())
}
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn tdigest_info() -> Result<()> {
let client = get_redis_stack_test_client().await?;
client.flushall(FlushingMode::Sync).await?;
client
.topk_reserve("topk", 50, Some((200, 7, 0.925)))
.await?;
let info = client.topk_info("topk").await?;
assert_eq!(50, info.k);
assert_eq!(200, info.width);
assert_eq!(7, info.depth);
assert_eq!(0.925, info.decay);
Ok(())
}
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn tdigest_list() -> Result<()> {
let client = get_redis_stack_test_client().await?;
client.flushall(FlushingMode::Sync).await?;
client.topk_reserve("key", 50, None).await?;
let _items: Vec<Option<String>> = client.topk_add("key", ["foo", "bar", "42"]).await?;
let _items: Vec<Option<String>> = client
.topk_incrby("key", [("foo", 3), ("bar", 2), ("42", 30)])
.await?;
let items: Vec<String> = client.topk_list("key").await?;
assert_eq!(
vec!["42".to_owned(), "foo".to_owned(), "bar".to_owned()],
items
);
let result: TopKListWithCountResult<String> = client.topk_list_with_count("key").await?;
assert_eq!(
vec![
("42".to_owned(), 31),
("foo".to_owned(), 4),
("bar".to_owned(), 3)
],
result.items
);
Ok(())
}
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn tdigest_query() -> Result<()> {
let client = get_redis_stack_test_client().await?;
client.flushall(FlushingMode::Sync).await?;
client.topk_reserve("key", 50, None).await?;
let _items: Vec<Option<String>> = client.topk_add("key", "42").await?;
let items: Vec<bool> = client.topk_query("key", ["42", "unknown"]).await?;
assert_eq!(vec![true, false], items);
Ok(())
}
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn tdigest_reserve() -> Result<()> {
let client = get_redis_stack_test_client().await?;
client.flushall(FlushingMode::Sync).await?;
client
.topk_reserve("topk", 50, Some((200, 7, 0.925)))
.await?;
Ok(())
}