-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathhyper_log_log_commands.rs
59 lines (56 loc) · 1.89 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
use crate::{
client::{prepare_command, PreparedCommand},
resp::{cmd, SingleArg, SingleArgCollection},
};
/// A group of Redis commands related to [`HyperLogLog`](https://redis.io/docs/data-types/hyperloglogs/)
///
/// # See Also
/// [Redis Hash Commands](https://redis.io/commands/?group=hyperloglog)
pub trait HyperLogLogCommands<'a> {
/// Adds the specified elements to the specified HyperLogLog.
///
/// # Return
/// * `true` if at least 1 HyperLogLog inFternal register was altered.
/// * `false` otherwise.
///
/// # See Also
/// [<https://redis.io/commands/pfadd/>](https://redis.io/commands/pfadd/)
fn pfadd<K, E, EE>(self, key: K, elements: EE) -> PreparedCommand<'a, Self, bool>
where
Self: Sized,
K: SingleArg,
E: SingleArg,
EE: SingleArgCollection<E>,
{
prepare_command(self, cmd("PFADD").arg(key).arg(elements))
}
/// Return the approximated cardinality of the set(s)
/// observed by the HyperLogLog at key(s).
///
/// # Return
/// The approximated number of unique elements observed via PFADD.
///
/// # See Also
/// [<https://redis.io/commands/pfcount/>](https://redis.io/commands/pfcount/)
fn pfcount<K, KK>(self, keys: KK) -> PreparedCommand<'a, Self, usize>
where
Self: Sized,
K: SingleArg,
KK: SingleArgCollection<K>,
{
prepare_command(self, cmd("PFCOUNT").arg(keys))
}
/// Merge N different HyperLogLogs into a single one.
///
/// # See Also
/// [<https://redis.io/commands/pfmerge/>](https://redis.io/commands/pfmerge/)
fn pfmerge<D, S, SS>(self, dest_key: D, source_keys: SS) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
D: SingleArg,
S: SingleArg,
SS: SingleArgCollection<S>,
{
prepare_command(self, cmd("PFMERGE").arg(dest_key).arg(source_keys))
}
}