{"id":43532,"date":"2024-12-01T16:44:41","date_gmt":"2024-12-01T08:44:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/43532\/"},"modified":"2024-12-01T16:44:41","modified_gmt":"2024-12-01T08:44:41","slug":"redis%e7%89%b9%e6%ae%8a%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8bbitmap%e4%bd%8d%e5%9b%be","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/43532\/","title":{"rendered":"Redis\u7279\u6b8a\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Redis\u7279\u6b8a\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe<\/h1>\n<p><span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300aRedis\u7279\u6b8a\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe\u300b\uff0c\u4e3b\u8981\u5305\u62ecBitMap\u3001Redis\u6570\u636e\u7c7b\u578b\u3001\u4f4d\u56fe\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002<\/p>\n<h2>Redis\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe<\/h2>\n<p>bitmap\u6570\u636e\u7ed3\u6784\uff0c\u662f\u57fa\u4e8e\u4e8c\u8fdb\u5236\u4f4d\u6765\u8fdb\u884c\u64cd\u4f5c\u8bb0\u5f55\u7684\uff0c\u53ea\u67090 \u548c 1\u4e24\u4e2a\u72b6\u6001\u3002<br \/>\u53ef\u4ee5\u60f3\u8c61\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u91cc\u9762\u53ea\u67090\u6216\u80051\u3002<\/p>\n<p>\u80fd\u5e72\u561b\u5462\uff1f<\/p>\n<p>\u73b0\u5b9e\u4e2d\u4f1a\u6709\u8fd9\u4e9b\u573a\u666f\uff0c\u6bd4\u5982\u7edf\u8ba1\u7528\u6237\u4fe1\u606f\uff0c\u6d3b\u8dc3\u7528\u6237\u548c\u975e\u6d3b\u8dc3\u7528\u6237\u3001\u767b\u5f55\u7684\u3001\u672a\u767b\u5f55\u7684\u7528\u6237\uff0c\u6253\u5361\u7684\u3001\u672a\u6253\u5361\u7684\uff0c\u50cf\u8fd9\u79cd\u53ea\u67092\u4e2a\u72b6\u6001\uff0c\u5e76\u4e14\u6570\u636e\u91cf\u975e\u5e38\u5927\u7684\uff0c\u5c31\u9002\u5408\u4f7f\u7528bitmap\u3002<\/p>\n<p>\u7f51\u4e0a\u627e\u4e86\u4e00\u4e2a\u5bf9\u6bd4\uff0c\u53ef\u4ee5\u5e2e\u52a9\u8bb0\u5fc6\u4e0bbitmap\u7684\u4f18\u70b9\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221230\/167238001263ae7e6c64c0b.png\" class=\"aligncenter\" title=\"Redis\u7279\u6b8a\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe\u63d2\u56fe\" alt=\"Redis\u7279\u6b8a\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe\u63d2\u56fe\" \/><\/p>\n<h3>\u4e00\u3001setbit<\/h3>\n<p>\u8bbe\u7f6e\u6216\u8005\u6e05\u7a7akey\u7684value(\u5b57\u7b26\u4e32)\u5728offset\u5904\u7684bit\u503c\u3002<\/p>\n<p>\u90a3\u4e2a\u4f4d\u7f6e\u7684bit\u8981\u4e48\u88ab\u8bbe\u7f6e\uff0c\u8981\u4e48\u88ab\u6e05\u7a7a\uff0c\u8fd9\u4e2a\u7531value(\u53ea\u80fd\u662f0\u6216\u80051)\u6765\u51b3\u5b9a\u3002\u5f53key\u4e0d\u5b58\u5728\u7684\u65f6\u5019\uff0c\u5c31\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32value\u3002<\/p>\n<p>\u6bd4\u5982\u73b0\u5728\u6211\u8bbe\u7f6e\u4e00\u4e2a\u7528\u6237\u76847\u5929\u7684\u6253\u5361\u4fe1\u606f\uff0c1\u662f\u6253\u5361\uff0c0\u662f\u672a\u6253\u5361\u3002<\/p>\n<pre>setbit sign 0 1\nsetbit sign 1 1\nsetbit sign 3 1\nsetbit sign 4 0\nsetbit sign 5 1\nsetbit sign 6 0\nsetbit sign 2 1<\/pre>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221230\/167238001263ae7e6cb0aba.png\" class=\"aligncenter\" title=\"Redis\u7279\u6b8a\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe\u63d2\u56fe1\" alt=\"Redis\u7279\u6b8a\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe\u63d2\u56fe1\" \/><\/p>\n<h3>\u4e8c\u3001getbit<\/h3>\n<p>\u5bf9 key \u6240\u50a8\u5b58\u7684\u5b57\u7b26\u4e32\u503c\uff0c\u83b7\u53d6\u6307\u5b9a\u504f\u79fb\u91cf\u4e0a\u7684\u4f4d(bit)\u3002<\/p>\n<pre>getbit sign 4<\/pre>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221230\/167238001363ae7e6d247f3.png\" class=\"aligncenter\" title=\"Redis\u7279\u6b8a\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe\u63d2\u56fe2\" alt=\"Redis\u7279\u6b8a\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe\u63d2\u56fe2\" \/><\/p>\n<h3>\u4e09\u3001bitcount<\/h3>\n<p>\u7edf\u8ba1\u5b57\u7b26\u4e32\u88ab\u8bbe\u7f6e\u4e3a1\u7684bit\u6570\u3002<\/p>\n<p>\u4e0d\u5b58\u5728\u7684 key \u88ab\u5f53\u6210\u662f\u7a7a\u5b57\u7b26\u4e32\u6765\u5904\u7406\uff0c\u56e0\u6b64\u5bf9\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684 key \u8fdb\u884c BITCOUNT \u64cd\u4f5c\uff0c\u7ed3\u679c\u4e3a 0 \u3002<\/p>\n<pre>bitcount sign<\/pre>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221230\/167238001363ae7e6d636f1.png\" class=\"aligncenter\" title=\"Redis\u7279\u6b8a\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe\u63d2\u56fe3\" alt=\"Redis\u7279\u6b8a\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe\u63d2\u56fe3\" \/><\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aRedis\u7279\u6b8a\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8eredis\u7684\u8d44\u6599\u8bf7\u5173\u6ce8golang\u5b66\u4e60\u7f51\u516c\u4f17\u53f7\uff01<\/p>\n<p>     \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1a\u811a\u672c\u4e4b\u5bb6 \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664  <\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   Redis\u7279\u6b8a\u6570\u636e\u7c7b\u578bHyperLogLog\u57fa\u6570\u7edf\u8ba1\u7b97\u6cd5\u8bb2\u89e3\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   Redisson\u5982\u4f55\u89e3\u51b3Redis\u5206\u5e03\u5f0f\u9501\u63d0\u524d\u91ca\u653e\u95ee\u9898\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Redis\u7279\u6b8a\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe 0\u6d4f\u89c8 \u6536\u85cf \u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300aRedis\u7279\u6b8a\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe\u300b\uff0c\u4e3b\u8981\u5305\u62ecBitMap\u3001Redis\u6570\u636e\u7c7b\u578b\u3001\u4f4d\u56fe\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002 Redis\u6570\u636e\u7c7b\u578bbitmap\u4f4d\u56fe bitmap\u6570\u636e\u7ed3\u6784\uff0c\u662f\u57fa\u4e8e\u4e8c\u8fdb\u5236\u4f4d\u6765\u8fdb\u884c\u64cd\u4f5c\u8bb0\u5f55\u7684\uff0c\u53ea\u67090 \u548c 1\u4e24\u4e2a\u72b6\u6001\u3002\u53ef\u4ee5\u60f3\u8c61\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u91cc\u9762\u53ea\u67090\u6216\u80051\u3002 \u80fd\u5e72\u561b\u5462\uff1f \u73b0\u5b9e\u4e2d\u4f1a\u6709\u8fd9\u4e9b\u573a\u666f\uff0c\u6bd4\u5982\u7edf\u8ba1\u7528\u6237\u4fe1\u606f\uff0c\u6d3b\u8dc3\u7528\u6237\u548c\u975e\u6d3b\u8dc3\u7528\u6237\u3001\u767b\u5f55\u7684\u3001\u672a\u767b\u5f55\u7684\u7528\u6237\uff0c\u6253\u5361\u7684\u3001\u672a\u6253\u5361\u7684\uff0c\u50cf\u8fd9\u79cd\u53ea\u67092\u4e2a\u72b6\u6001\uff0c\u5e76\u4e14\u6570\u636e\u91cf\u975e\u5e38\u5927\u7684\uff0c\u5c31\u9002\u5408\u4f7f\u7528bitmap\u3002 \u7f51\u4e0a\u627e\u4e86\u4e00\u4e2a\u5bf9\u6bd4\uff0c\u53ef\u4ee5\u5e2e\u52a9\u8bb0\u5fc6\u4e0bbitmap\u7684\u4f18\u70b9\u3002 \u4e00\u3001setbit \u8bbe\u7f6e\u6216\u8005\u6e05\u7a7akey\u7684value(\u5b57\u7b26\u4e32)\u5728offset\u5904\u7684bit\u503c\u3002 \u90a3\u4e2a\u4f4d\u7f6e\u7684bit\u8981\u4e48\u88ab\u8bbe\u7f6e\uff0c\u8981\u4e48\u88ab\u6e05\u7a7a\uff0c\u8fd9\u4e2a\u7531value(\u53ea\u80fd\u662f0\u6216\u80051)\u6765\u51b3\u5b9a\u3002\u5f53key\u4e0d\u5b58\u5728\u7684\u65f6\u5019\uff0c\u5c31\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32value\u3002 \u6bd4\u5982\u73b0\u5728\u6211\u8bbe\u7f6e\u4e00\u4e2a\u7528\u6237\u76847\u5929\u7684\u6253\u5361\u4fe1\u606f\uff0c1\u662f\u6253\u5361\uff0c0\u662f\u672a\u6253\u5361\u3002 setbit sign 0 1 setbit sign 1 1 setbit sign 3 1 setbit sign 4 0 setbit sign 5 1 setbit sign 6 0 setbit sign 2 1 \u4e8c\u3001getbit \u5bf9 key \u6240\u50a8\u5b58\u7684\u5b57\u7b26\u4e32\u503c\uff0c\u83b7\u53d6\u6307\u5b9a\u504f\u79fb\u91cf\u4e0a\u7684\u4f4d(bit)\u3002 getbit sign 4 \u4e09\u3001bitcount \u7edf\u8ba1\u5b57\u7b26\u4e32\u88ab\u8bbe\u7f6e\u4e3a1\u7684bit\u6570\u3002 \u4e0d\u5b58\u5728\u7684 key \u88ab\u5f53\u6210\u662f\u7a7a\u5b57\u7b26\u4e32\u6765\u5904\u7406\uff0c\u56e0\u6b64\u5bf9\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-43532","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/43532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=43532"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/43532\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=43532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=43532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=43532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}