Redis的底层类型之haperloglog

werbenhu / 145 /

ChatGPT 可用网址,仅供交流学习使用,如对您有所帮助,请收藏并推荐给需要的朋友。
https://ckai.xyz

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 实现在内部工作时没有发生错误或损坏。


Redis的底层类型之haperloglog
作者
werbenhu
许可协议
CC BY 4.0
发布于
2023-09-25
修改于
2024-07-25
Bonnie image
尚未登录