{"id":2165,"date":"2023-04-02T13:40:39","date_gmt":"2023-04-02T05:40:39","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=2165"},"modified":"2023-04-02T13:40:39","modified_gmt":"2023-04-02T05:40:39","slug":"redis-hyperloglog","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/04\/02\/redis-hyperloglog\/","title":{"rendered":"Redis HyperLogLog"},"content":{"rendered":"<h2>Redis HyperLogLog<\/h2>\n<p>Redis \u5728 2.8.9 \u7248\u672c\u6dfb\u52a0\u4e86 HyperLogLog \u7ed3\u6784\u3002Redis HyperLogLog \u662f\u7528\u6765\u505a\u57fa\u6570\u7edf\u8ba1\u7684\u7b97\u6cd5\uff0cHyperLogLog \u7684\u4f18\u70b9\u662f\uff0c\u5728\u8f93\u5165\u5143\u7d20\u7684\u6570\u91cf\u6216\u8005\u4f53\u79ef\u975e\u5e38\u975e\u5e38\u5927\u65f6\uff0c\u8ba1\u7b97\u57fa\u6570\u6240\u9700\u7684\u7a7a\u95f4\u603b\u662f\u56fa\u5b9a\u7684\u3001\u5e76\u4e14\u662f\u5f88\u5c0f\u7684\u3002<\/p>\n<p>\u5728 Redis \u91cc\u9762\uff0c\u6bcf\u4e2a HyperLogLog \u952e\u53ea\u9700\u8981\u82b1\u8d39 12 KB \u5185\u5b58\uff0c\u5c31\u53ef\u4ee5\u8ba1\u7b97\u63a5\u8fd1 2^64 \u4e2a\u4e0d\u540c\u5143\u7d20\u7684\u57fa\u6570\u3002\u8fd9\u548c\u8ba1\u7b97\u57fa\u6570\u65f6\uff0c\u5143\u7d20\u8d8a\u591a\u8017\u8d39\u5185\u5b58\u5c31\u8d8a\u591a\u7684\u96c6\u5408\u5f62\u6210\u9c9c\u660e\u5bf9\u6bd4\u3002\u4f46\u662f\uff0c\u56e0\u4e3a HyperLogLog \u53ea\u4f1a\u6839\u636e\u8f93\u5165\u5143\u7d20\u6765\u8ba1\u7b97\u57fa\u6570\uff0c\u800c\u4e0d\u4f1a\u50a8\u5b58\u8f93\u5165\u5143\u7d20\u672c\u8eab\uff0c\u6240\u4ee5 HyperLogLog \u4e0d\u80fd\u50cf\u96c6\u5408\u90a3\u6837\uff0c\u8fd4\u56de\u8f93\u5165\u7684\u5404\u4e2a\u5143\u7d20\u3002<\/p>\n<p><!-- more --><\/p>\n<h3>\u4ec0\u4e48\u662f\u57fa\u6570?<\/h3>\n<p>\u6bd4\u5982\u6570\u636e\u96c6 {1, 3, 5, 7, 5, 7, 8}\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u636e\u96c6\u7684\u57fa\u6570\u96c6\u4e3a {1, 3, 5 ,7, 8}\uff0c\u57fa\u6570(\u4e0d\u91cd\u590d\u5143\u7d20)\u4e3a5\u3002\u57fa\u6570\u4f30\u8ba1\u5c31\u662f\u5728\u8bef\u5dee\u53ef\u63a5\u53d7\u7684\u8303\u56f4\u5185\uff0c\u5feb\u901f\u8ba1\u7b97\u57fa\u6570\u3002<\/p>\n<h3>HyperLogLog \u5b9e\u4f8b<\/h3>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u6f14\u793a\u4e86 HyperLogLog \u7684\u5de5\u4f5c\u8fc7\u7a0b\uff1a<\/p>\n<pre><code class=\"language-bash\">redis 127.0.0.1:6379&gt; PFADD appblog &quot;redis&quot;\n\n1) (integer) 1\n\nredis 127.0.0.1:6379&gt; PFADD appblog &quot;mongodb&quot;\n\n1) (integer) 1\n\nredis 127.0.0.1:6379&gt; PFADD appblog &quot;mysql&quot;\n\n1) (integer) 1\n\nredis 127.0.0.1:6379&gt; PFCOUNT appblog\n\n(integer) 3<\/code><\/pre>\n<h2>Redis HyperLogLog \u547d\u4ee4<\/h2>\n<h3>PFADD key element [element &#8230;]<\/h3>\n<p>\u6dfb\u52a0\u6307\u5b9a\u5143\u7d20\u5230 HyperLogLog \u4e2d<\/p>\n<pre><code class=\"language-bash\">redis 127.0.0.1:6379&gt; PFADD mykey a b c d e f g h i j\n(integer) 1\nredis 127.0.0.1:6379&gt; PFCOUNT mykey\n(integer) 10<\/code><\/pre>\n<h3>PFCOUNT key [key &#8230;]<\/h3>\n<p>\u8fd4\u56de\u7ed9\u5b9a HyperLogLog \u7684\u57fa\u6570\u4f30\u7b97\u503c\uff0c\u5982\u679c\u591a\u4e2a HyperLogLog \u5219\u8fd4\u56de\u57fa\u6570\u4f30\u503c\u4e4b\u548c<\/p>\n<pre><code class=\"language-bash\">redis 127.0.0.1:6379&gt; PFADD hll foo bar zap\n(integer) 1\nredis 127.0.0.1:6379&gt; PFADD hll zap zap zap\n(integer) 0\nredis 127.0.0.1:6379&gt; PFADD hll foo bar\n(integer) 0\nredis 127.0.0.1:6379&gt; PFCOUNT hll\n(integer) 3\nredis 127.0.0.1:6379&gt; PFADD some-other-hll 1 2 3\n(integer) 1\nredis 127.0.0.1:6379&gt; PFCOUNT hll some-other-hll\n(integer) 6\nredis&gt; <\/code><\/pre>\n<h3>PFMERGE destkey sourcekey [sourcekey &#8230;]<\/h3>\n<p>\u5c06\u591a\u4e2a HyperLogLog \u5408\u5e76\u4e3a\u4e00\u4e2a HyperLogLog\uff0c\u5408\u5e76\u540e\u7684 HyperLogLog \u7684\u57fa\u6570\u4f30\u7b97\u503c\u662f\u901a\u8fc7\u5bf9\u6240\u6709\u7ed9\u5b9a HyperLogLog \u8fdb\u884c\u5e76\u96c6\u8ba1\u7b97\u5f97\u51fa\u7684<\/p>\n<pre><code class=\"language-bash\">redis&gt; PFADD hll1 foo bar zap a\n(integer) 1\nredis&gt; PFADD hll2 a b c foo\n(integer) 1\nredis&gt; PFMERGE hll3 hll1 hll2\n&quot;OK&quot;\nredis&gt; PFCOUNT hll3\n(integer) 6\nredis&gt; <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Redis HyperLogLog Redis \u5728 2.8.9 \u7248\u672c\u6dfb\u52a0\u4e86 HyperLogLog \u7ed3\u6784\u3002Re [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[504],"class_list":["post-2165","post","type-post","status-publish","format-standard","hentry","category-redis","tag-hyperloglog"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2165"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2165\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}