redis_driver/commands/
hyper_log_log_commands.rs

1use crate::{
2    prepare_command,
3    resp::{cmd, CommandArg, SingleArgOrCollection},
4    PreparedCommand,
5};
6
7/// A group of Redis commands related to [`HyperLogLog`](https://redis.io/docs/data-types/hyperloglogs/)
8///
9/// # See Also
10/// [Redis Hash Commands](https://redis.io/commands/?group=hyperloglog)
11pub trait HyperLogLogCommands {
12    /// Adds the specified elements to the specified HyperLogLog.
13    ///
14    /// # Return
15    /// * `true` if at least 1 HyperLogLog inFternal register was altered.
16    /// * `false` otherwise.
17    ///
18    /// # See Also
19    /// [<https://redis.io/commands/pfadd/>](https://redis.io/commands/pfadd/)
20    fn pfadd<K, E, EE>(&mut self, key: K, elements: EE) -> PreparedCommand<Self, bool>
21    where
22        Self: Sized,
23        K: Into<CommandArg>,
24        E: Into<CommandArg>,
25        EE: SingleArgOrCollection<E>,
26    {
27        prepare_command(self, cmd("PFADD").arg(key).arg(elements))
28    }
29
30    /// Return the approximated cardinality of the set(s)
31    /// observed by the HyperLogLog at key(s).
32    ///
33    /// # Return
34    /// The approximated number of unique elements observed via PFADD.
35    ///
36    /// # See Also
37    /// [<https://redis.io/commands/pfcount/>](https://redis.io/commands/pfcount/)
38    fn pfcount<K, KK>(&mut self, keys: KK) -> PreparedCommand<Self, usize>
39    where
40        Self: Sized,
41        K: Into<CommandArg>,
42        KK: SingleArgOrCollection<K>,
43    {
44        prepare_command(self, cmd("PFCOUNT").arg(keys))
45    }
46
47    /// Merge N different HyperLogLogs into a single one.
48    ///
49    /// # See Also
50    /// [<https://redis.io/commands/pfmerge/>](https://redis.io/commands/pfmerge/)
51    fn pfmerge<D, S, SS>(&mut self, dest_key: D, source_keys: SS) -> PreparedCommand<Self, ()>
52    where
53        Self: Sized,
54        D: Into<CommandArg>,
55        S: Into<CommandArg>,
56        SS: SingleArgOrCollection<S>,
57    {
58        prepare_command(self, cmd("PFMERGE").arg(dest_key).arg(source_keys))
59    }
60}