Module: Protocol::Redis::Methods::Counting

Defined in:
lib/protocol/redis/methods/counting.rb

Overview

Methods for managing Redis HyperLogLogs.

Instance Method Summary collapse

Instance Method Details

#pfadd(key, element, *elements) ⇒ Object

Adds the specified elements to the specified HyperLogLog. O(1) to add every element. See <redis.io/commands/pfadd> for more details.



15
16
17
# File 'lib/protocol/redis/methods/counting.rb', line 15

def pfadd(key, element, *elements)
  call("PFADD", key, element, *elements)
end

#pfcount(key, *keys) ⇒ Object

Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s). O(1) with a very small average constant time when called with a single key. O(N) with N being the number of keys, and much bigger constant times, when called with multiple keys. See <redis.io/commands/pfcount> for more details.



22
23
24
# File 'lib/protocol/redis/methods/counting.rb', line 22

def pfcount(key, *keys)
  call("PFCOUNT", key, *keys)
end

#pfmerge(destkey, sourcekey, *sourcekeys) ⇒ Object

Merge N different HyperLogLogs into a single one. O(N) to merge N HyperLogLogs, but with high constant times. See <redis.io/commands/pfmerge> for more details.



30
31
32
# File 'lib/protocol/redis/methods/counting.rb', line 30

def pfmerge(destkey, sourcekey, *sourcekeys)
  call("PFMERGE", destkey, sourcekey, *sourcekeys)
end