-
Notifications
You must be signed in to change notification settings - Fork 64
/
hyperloglog.rs
42 lines (35 loc) · 1.23 KB
/
hyperloglog.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
use super::*;
use crate::{
protocol::{command::CommandKind, utils as protocol_utils},
types::*,
utils,
};
pub async fn pfadd<C: ClientLike>(client: &C, key: Key, elements: MultipleValues) -> Result<Value, Error> {
let frame = utils::request_response(client, move || {
let elements = elements.into_multiple_values();
let mut args = Vec::with_capacity(1 + elements.len());
args.push(key.into());
for element in elements.into_iter() {
args.push(element);
}
Ok((CommandKind::Pfadd, args))
})
.await?;
protocol_utils::frame_to_results(frame)
}
pub async fn pfcount<C: ClientLike>(client: &C, keys: MultipleKeys) -> Result<Value, Error> {
let args: Vec<Value> = keys.inner().into_iter().map(|k| k.into()).collect();
args_value_cmd(client, CommandKind::Pfcount, args).await
}
pub async fn pfmerge<C: ClientLike>(client: &C, dest: Key, sources: MultipleKeys) -> Result<Value, Error> {
let frame = utils::request_response(client, move || {
let mut args = Vec::with_capacity(1 + sources.len());
args.push(dest.into());
for source in sources.inner().into_iter() {
args.push(source.into());
}
Ok((CommandKind::Pfmerge, args))
})
.await?;
protocol_utils::frame_to_results(frame)
}