关于redis:Redis的底层类型之haperloglog

4次阅读

共计 1509 个字符,预计需要花费 4 分钟才能阅读完成。

haperloglog

HyperLogLog is a probabilistic data structure that estimates the cardinality of a set.The Redis HyperLogLog implementation uses up to 12 KB and provides a standard error of 0.81%.
haperloglgo 是一个概率性的数据结构,用于预计汇合的基数,Redis HyperLogLog 实现最多应用 12 KB,并提供 0.81% 的规范谬误。

能够用作统计一些 PV,UV 等。

  • PFADD

Adds all the element arguments to the HyperLogLog data structure stored at the variable name specified as first argument.

PFADD key [element [element ...]]
  • PFADD
PFCOUNT key [key ...]


redis> PFADD hll foo bar zap
(integer) 1
redis> PFADD hll zap zap zap
(integer) 0
redis> PFADD hll foo bar
(integer) 0
redis> PFCOUNT hll
(integer) 3
redis> PFADD some-other-hll 1 2 3 bar
(integer) 1
redis> PFCOUNT hll some-other-hll
(integer) 6

When called with a single key, returns the approximated(近似的) cardinality computed by the HyperLogLog data structure stored at the specified variable, which is 0 if the variable does not exist.

When called with multiple keys, returns the approximated cardinality of the union of the HyperLogLogs passed, by internally merging the HyperLogLogs stored at the provided keys into a temporary HyperLogLog. 多个 key 返回合并的汇合

  • PFDEBUG
PFDEBUG ENC:显示 HLL 数据结构的编码方式(通常是 sparse)。PFDEBUG DUMP:以可读的形式显示 HLL 数据结构的外部数据。PFDEBUG DUMPEX:以可读的形式显示 HLL 数据结构的外部数据,包含估算的基数值。PFDEBUG INFO:显示 HLL 数据结构的信息,包含底层稠密数组的大小、估算的基数值 

PFDEBUG 命令用于在调试模式下查看 HyperLogLog 数据结构的外部状态,以帮忙开发人员诊断问题或优化性能。它能够用来查看 HLL 数据结构的各种信息,包含底层稠密数组的大小、估算的基数值等。

  • PFMERGE
PFMERGE destkey [sourcekey [sourcekey ...]]

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

  • PFSELFTEST

PFSELFTEST 命令用于执行 Redis 的 HyperLogLog 实现的自我测试。这个命令通常用于确保 Redis 的 HyperLogLog 实现在外部工作时没有产生谬误或损坏。

正文完
 0