Module: Valkey::Commands::HyperLogLogCommands

Included in:
Valkey::Commands
Defined in:
lib/valkey/commands/hyper_log_log_commands.rb

Instance Method Summary collapse

Instance Method Details

#pfadd(key, member) ⇒ Boolean

Add one or more members to a HyperLogLog structure.

Parameters:

  • key (String)
  • member (String, Array<String>)

    one member, or array of members

Returns:

  • (Boolean)

    true if at least 1 HyperLogLog internal register was altered. false otherwise.

See Also:



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/valkey/commands/hyper_log_log_commands.rb', line 13

def pfadd(key, member)
  args = [key]

  if member.is_a?(Array)
    args += member
  else
    args << member
  end

  send_command(RequestType::PFADD, args, &Utils::Boolify)
end

#pfcount(*keys) ⇒ Integer

Get the approximate cardinality of members added to HyperLogLog structure.

If called with multiple keys, returns the approximate cardinality of the union of the HyperLogLogs contained in the keys.

Parameters:

  • keys (String, Array<String>)

Returns:

  • (Integer)

See Also:



34
35
36
# File 'lib/valkey/commands/hyper_log_log_commands.rb', line 34

def pfcount(*keys)
  send_command(RequestType::PFCOUNT, keys.flatten(1))
end

#pfmerge(dest_key, *source_key) ⇒ Boolean

Merge multiple HyperLogLog values into an unique value that will approximate the cardinality of the union of the observed Sets of the source HyperLogLog structures.

Parameters:

  • dest_key (String)

    destination key

  • source_key (String, Array<String>)

    source key, or array of keys

Returns:

  • (Boolean)

See Also:



46
47
48
# File 'lib/valkey/commands/hyper_log_log_commands.rb', line 46

def pfmerge(dest_key, *source_key)
  send_command(RequestType::PFMERGE, [dest_key, *source_key], &Utils::BoolifySet)
end