rustis/commands/
hyper_log_log_commands.rs

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