-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbloom_commands.rs
173 lines (136 loc) · 4.82 KB
/
bloom_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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
use crate::{
commands::{
BfInfoParameter, BfInsertOptions, BfReserveOptions, BfScanDumpResult, BloomCommands,
FlushingMode, ServerCommands,
},
tests::get_redis_stack_test_client,
Result,
};
use serial_test::serial;
use std::collections::VecDeque;
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn bf_add() -> Result<()> {
let client = get_redis_stack_test_client().await?;
client.flushall(FlushingMode::Sync).await?;
let result = client.bf_add("key", "item").await?;
assert!(result);
let result = client.bf_add("key", "item").await?;
assert!(!result);
Ok(())
}
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn bf_exists() -> Result<()> {
let client = get_redis_stack_test_client().await?;
client.flushall(FlushingMode::Sync).await?;
let result = client.bf_exists("key", "item").await?;
assert!(!result);
let result = client.bf_add("key", "item").await?;
assert!(result);
let result = client.bf_exists("key", "item").await?;
assert!(result);
Ok(())
}
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn bf_info() -> Result<()> {
let client = get_redis_stack_test_client().await?;
client.flushall(FlushingMode::Sync).await?;
client.bf_add("key", "item1").await?;
client.bf_add("key", "item2").await?;
client.bf_add("key", "item3").await?;
let result = client
.bf_info("key", BfInfoParameter::NumItemsInserted)
.await?;
assert_eq!(3, result);
let result = client.bf_info_all("key").await?;
assert_eq!(3, result.num_items_inserted);
assert_eq!(1, result.num_filters);
Ok(())
}
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn bf_insert() -> Result<()> {
let client = get_redis_stack_test_client().await?;
client.flushall(FlushingMode::Sync).await?;
let results: Vec<bool> = client
.bf_insert("filter", ["boo", "bar", "barz"], BfInsertOptions::default())
.await?;
assert_eq!(vec![true, true, true], results);
let results: Vec<bool> = client
.bf_insert("filter", "hello", BfInsertOptions::default().capacity(1000))
.await?;
assert_eq!(vec![true], results);
let results: Vec<bool> = client
.bf_insert(
"filter",
["boo", "bar"],
BfInsertOptions::default().nocreate(),
)
.await?;
assert_eq!(vec![false, false], results);
Ok(())
}
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn bf_madd() -> Result<()> {
let client = get_redis_stack_test_client().await?;
client.flushall(FlushingMode::Sync).await?;
let results: Vec<bool> = client.bf_madd("filter", ["item1", "item2"]).await?;
assert_eq!(vec![true, true], results);
let results: Vec<bool> = client.bf_madd("filter", ["item2", "item3"]).await?;
assert_eq!(vec![false, true], results);
Ok(())
}
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn bf_mexists() -> Result<()> {
let client = get_redis_stack_test_client().await?;
client.flushall(FlushingMode::Sync).await?;
let results: [bool; 2] = client.bf_madd("filter", ["item1", "item2"]).await?;
assert_eq!([true, true], results);
let results: [bool; 3] = client
.bf_mexists("filter", ["item1", "item2", "item3"])
.await?;
assert_eq!([true, true, false], results);
Ok(())
}
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn bf_reserve_loadchunk_scandump() -> Result<()> {
let client = get_redis_stack_test_client().await?;
client.flushall(FlushingMode::Sync).await?;
client
.bf_reserve("bf", 0.1, 10, BfReserveOptions::default())
.await?;
let result = client.bf_add("bf", "item1").await?;
assert!(result);
let mut iterator: i64 = 0;
let mut chunks: VecDeque<BfScanDumpResult> = VecDeque::new();
loop {
let result = client.bf_scandump("bf", iterator).await?;
if result.iterator == 0 {
break;
} else {
iterator = result.iterator;
chunks.push_back(result);
}
}
client.flushall(FlushingMode::Sync).await?;
while let Some(dump_result) = chunks.pop_front() {
client
.bf_loadchunk("bf", dump_result.iterator, dump_result.data)
.await?;
}
let result = client.bf_exists("bf", "item1").await?;
assert!(result);
Ok(())
}