- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
Redis 最近发布了名为 HyperLogLog 的新数据结构。它允许我们保留唯一对象的数量,并且只占用 12k 字节的大小。我不明白的是Redis的PFCOUNT命令在技术上说是写命令。为什么会这样?
Note: as a side effect of calling this function, it is possible that the HyperLogLog is modified, since the last 8 bytes encode the latest computed cardinality for caching purposes. So PFCOUNT is technically a write command.
最佳答案
HyperLogLog对象的头部如下:
struct hllhdr {
char magic[4]; /* "HYLL" */
uint8_t encoding; /* HLL_DENSE or HLL_SPARSE. */
uint8_t notused[3]; /* Reserved for future use, must be zero. */
uint8_t card[8]; /* Cached cardinality, little endian. */
uint8_t registers[]; /* Data bytes. */
};
注意 card 字段:它包含算法评估的最后一个基数。计算基数的估计值是一项昂贵的操作,因此 Redis 会缓存该值并将其保存在该字段中。
当 PFADD 被调用时,HyperLogLog 对象可能会被更新,也可能不会被更新(很有可能不会)。如果未更新,调用 PFCOUNT 将重用缓存值(卡字段)。如果更新了,则card字段失效,所以下一个PFCOUNT会执行计数算法,将新值写入card字段。
这就是 PFCOUNT 可以改变 HyperLogLog 对象的原因。
关于data-structures - Redis Hyperloglog - PFCOUNT 副作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23164374/
我有以下错误,Redis 强制我对同一节点的键进行计数。是否有一种新的现代方法来处理 Redis 中的这种缺失功能? org.springframework.dao.InvalidDataAccess
Redis 最近发布了名为 HyperLogLog 的新数据结构。它允许我们保留唯一对象的数量,并且只占用 12k 字节的大小。我不明白的是Redis的PFCOUNT命令在技术上说是写命令。为什么会这
我是一名优秀的程序员,十分优秀!