redis - Redis中PFADD的返回值

标签 redis hyperloglog

根据 Redis documentation on PFADD command :

 Return value
 Integer reply, specifically:
 1 if at least 1 HyperLogLog internal register was altered. 0 otherwise.

谁能解释一下下面两点?

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

最佳答案

Does this mean PFADD will return "1" if the counter was really incremented by 1?

没有。

返回值是纯 bool 值,即它只表示是否 底层 HyperLogLog 被修改

Is it guaranteed that after running PFADD, the new PFCOUNT will be PFCOUNT(before) + output of PFADD?

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

话虽如此,您可能希望使用 PFADD 的输出作为调用的触发器 再次 PFCOUNT,如 antirez 所解释在original blog post :

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.

最后:

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

没有。如上所述,它仅表示一个新的基数可用

关于redis - Redis中PFADD的返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24391756/

相关文章:

redis - 使用 Redis 维护页面浏览量计数队列并使用集合值更新数据库,而不是在每次页面浏览时更新

go - 在go中实现redis

ruby-on-rails - Sidekiq 和 Puma 中的 Redis 变量,线程安全吗?

android - hyperlog-android 并不是所有的日志都发送到服务器。如何解决这个问题?

javascript - 用于计算大基数的 LogLog 和 HyperLogLog 算法

hadoop - MapReduce 上的 HyperLogLog 正确性

design-patterns - Redis中持久队列的 worker 管理

在 header 中找不到 Spring Boot 安全性 x-auth-token

hash - 在 Redis 中交叉巨大的 HyperLogLogs 的最佳方法

redis - 关于 HyperLogLog,前导零是什么?