0

根据PFADD 命令的 Redis 文档

返回值
 整数回复,具体来说:
 如果至少 1 个 HyperLogLog 内部寄存器被更改,则为 1。否则为 0。

谁能解释以下两点?

  1. 这是否意味着如果计数器确实增加了 1,PFADD 将返回“1”?是否保证在运行 PFADD 后,新的 PFCOUNT 将为PFCOUNT(before) + output of PFADD?换句话说,单线程客户端能否仅使用 PFADD 的输出来跟踪计数?
  2. 当 PFADD 返回“0”或“1”时,它们是否分别转换为“缓存命中”和“缓存未命中”?
4

1 回答 1

3

这是否意味着如果计数器确实增加了 1,PFADD 将返回“1”?

不。

返回值是纯布尔值,即它仅指示底层 HyperLogLog 是否被修改

是否保证运行后PFADD,新的PFCOUNTPFCOUNT(before) + output of PFADD

不,因为 的输出PFADD不代表计数(见上文)。

话虽如此,您可能希望将 的输出用作再次PFADD调用的触发器 ,如antirez原始博客文章中所解释的:PFCOUNT

This is interesting for the user since as we add elements the probability of an element actually modifying some register decreases. The fact that the API is able to provide hints about the fact that a new cardinality is available allows for programs that continuously add elements and retrieve the approximated cardinality only when a new one is available.

At last:

When PFADD returns "0" or "1", do they translate to a "cache hit" and a "cache miss" respectively?

No. As detailed above it only indicates that a new cardinality is available.

于 2014-06-25T08:17:07.957 回答