简介

  • Redis HyperLogLog 即基数统计,有误差
  • 基数:不重复的元素
  • 使用场景:网页访问统计

    命令

    | 命令 | 解释 | | —- | —- | | PFADD key element [element …] | 将指定元素添加到HyperLogLog | | PFCOUNT key [key …] | 返回由HyperLogLog在键处观察到的集合的近似基数。 | | PFMERGE destkey sourcekey [sourcekey …] | 将N个不同的HyperLogLog合并到一个日志中。 |

例子

  1. hello-chen.cn:6379> PFADD letter1 a b c d e
  2. (integer) 1
  3. hello-chen.cn:6379> PFADD letter2 c d e f g
  4. (integer) 1
  5. hello-chen.cn:6379> PFCOUNT letter1
  6. (integer) 5
  7. hello-chen.cn:6379> PFMERGE letter3 letter1 letter2
  8. OK
  9. hello-chen.cn:6379> PFCOUNT letter3
  10. (integer) 7

其他

http://www.redis.cn/commands.html#hyperloglog

  1. PFADD key element [element ...]
  2. summary: Adds the specified elements to the specified HyperLogLog.
  3. since: 2.8.9
  4. PFCOUNT key [key ...]
  5. summary: Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s).
  6. since: 2.8.9
  7. PFMERGE destkey sourcekey [sourcekey ...]
  8. summary: Merge N different HyperLogLogs into a single one.
  9. since: 2.8.9