{"id":1023,"date":"2020-06-05T18:02:04","date_gmt":"2020-06-05T10:02:04","guid":{"rendered":"http:\/\/diuut.com\/?p=1023"},"modified":"2020-06-10T09:44:22","modified_gmt":"2020-06-10T01:44:22","slug":"redis%e4%b9%8bbitmap%e9%80%82%e7%94%a8%e5%9c%ba%e6%99%af","status":"publish","type":"post","link":"https:\/\/diuut.com\/?p=1023","title":{"rendered":"Redis\u4e4bBitMap\u9002\u7528\u573a\u666f"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\"><p>\u53c2\u8003\u573a\u666f\uff1a<\/p><cite> \u9700\u8981\u5b58\u50a8\u91cf\u7279\u522b\u5927\u7684\u662f\u5426\u4fe1\u606f\uff0c\u4f8b\u5982\u7528\u6237\u70b9\u8d5e\uff0c\u7528\u6237\u7b7e\u5230\uff0c\u65e5\u6d3b\u7528\u6237\uff0c\u8bbf\u95ee\u8ba1\u6570\uff0c\u5728\u7ebf\u7528\u6237\u6570\u7b49\u7b49<\/cite><\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote\"><p> \u4f55\u4e3aBitMap\uff1a \u5f15\u7528\u81ea\u300a\u7f16\u7a0b\u73e0\u7391\u300b  <\/p><cite>  \u6240\u8c13\u7684Bit-map\u5c31\u662f\u7528\u4e00\u4e2abit\u4f4d\u6765\u6807\u8bb0\u67d0\u4e2a\u5143\u7d20\u5bf9\u5e94\u7684Value\uff0c \u800cKey\u5373\u662f\u8be5\u5143\u7d20\u3002\u7531\u4e8e\u91c7\u7528\u4e86Bit\u4e3a\u5355\u4f4d\u6765\u5b58\u50a8\u6570\u636e\uff0c\u56e0\u6b64\u5728\u5b58\u50a8\u7a7a\u95f4\u65b9\u9762\uff0c\u53ef\u4ee5\u5927\u5927\u8282\u7701\u3002<br> \u5982\u679c\u8bf4\u4e86\u8fd9\u4e48\u591a\u8fd8\u6ca1\u660e\u767d\u4ec0\u4e48\u662fBit-map\uff0c\u90a3\u4e48\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u5177\u4f53\u7684\u4f8b\u5b50\uff0c\u5047\u8bbe\u6211\u4eec\u8981\u5bf90-7\u5185\u76845\u4e2a\u5143\u7d20(4,7,2,5,3)\u6392\u5e8f\uff08\u8fd9\u91cc\u5047\u8bbe\u8fd9\u4e9b\u5143\u7d20\u6ca1\u6709\u91cd\u590d\uff09\u3002\u90a3\u4e48\u6211\u4eec\u5c31\u53ef\u4ee5\u91c7\u7528Bit-map\u7684\u65b9\u6cd5\u6765\u8fbe\u5230\u6392\u5e8f\u7684\u76ee\u7684\u3002\u8981\u8868\u793a8\u4e2a\u6570\uff0c\u6211\u4eec\u5c31\u53ea\u9700\u89818\u4e2aBit\uff081Bytes\uff09\uff0c\u9996\u5148\u6211\u4eec\u5f00\u8f9f1Byte\u7684\u7a7a\u95f4\uff0c\u5c06\u8fd9\u4e9b\u7a7a\u95f4\u7684\u6240\u6709Bit\u4f4d\u90fd\u7f6e\u4e3a0<br> \u7136\u540e\u904d\u5386\u8fd95\u4e2a\u5143\u7d20\uff0c\u9996\u5148\u7b2c\u4e00\u4e2a\u5143\u7d20\u662f4\uff0c\u90a3\u4e48\u5c31\u628a4\u5bf9\u5e94\u7684\u4f4d\u7f6e\u4e3a1\uff08\u53ef\u4ee5\u8fd9\u6837\u64cd\u4f5c p+(i\/8)|(0\u00d701&lt;&lt;(i%8)) \u5f53\u7136\u4e86\u8fd9\u91cc\u7684\u64cd\u4f5c\u6d89\u53ca\u5230Big-ending\u548cLittle-ending\u7684\u60c5\u51b5\uff0c\u8fd9\u91cc\u9ed8\u8ba4\u4e3aBig-ending\uff09,\u56e0\u4e3a\u662f\u4ece\u96f6\u5f00\u59cb\u7684\uff0c\u6240\u4ee5\u8981\u628a\u7b2c\u4e94\u4f4d\u7f6e\u4e3a1\u3002<br> \u7136\u540e\u518d\u5904\u7406\u7b2c\u4e8c\u4e2a\u5143\u7d207\uff0c\u5c06\u7b2c\u516b\u4f4d\u7f6e\u4e3a1,\uff0c\u63a5\u7740\u518d\u5904\u7406\u7b2c\u4e09\u4e2a\u5143\u7d20\uff0c\u4e00\u76f4\u5230\u6700\u540e\u5904\u7406\u5b8c\u6240\u6709\u7684\u5143\u7d20\uff0c\u5c06\u76f8\u5e94\u7684\u4f4d\u7f6e\u4e3a1\u3002<br> \u7136\u540e\u6211\u4eec\u73b0\u5728\u904d\u5386\u4e00\u904dBit\u533a\u57df\uff0c\u5c06\u8be5\u4f4d\u662f\u4e00\u7684\u4f4d\u7684\u7f16\u53f7\u8f93\u51fa\uff082\uff0c3\uff0c4\uff0c5\uff0c7\uff09\uff0c\u8fd9\u6837\u5c31\u8fbe\u5230\u4e86\u6392\u5e8f\u7684\u76ee\u7684\u3002<br> \u5176\u5b9e\u5c31\u662f\u628a\u8ba1\u6570\u6392\u5e8f\u7528\u7684\u7edf\u8ba1\u6570\u7ec4\u7684\u6bcf\u4e2a\u5355\u4f4d\u7f29\u5c0f\u6210bit\u7ea7\u522b\u7684\u5e03\u5c14\u6570\u7ec4  <\/cite><\/blockquote>\n\n\n\n<p>Redis\u4e2d\u63d0\u4f9b\u7684BitMap\u547d\u4ee4\uff1a setbit  ,  getbit  ,  bitcount<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n127.0.0.1:6379&gt; setbit key offset value\n\/\/\u8bbe\u7f6e\u6216\u8005\u6e05\u7a7akey\u7684value(\u5b57\u7b26\u4e32)\u5728offset\u5904\u7684bit\u503c(\u53ea\u80fd\u53ea0\u6216\u80051)\u3002 \n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n127.0.0.1:6379&gt; getbit key offset \n\/\/\u83b7\u53d6key\u7684BitMap\u6570\u503c\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n127.0.0.1:6379&gt; bitcount key &#91;start end]   \n\/\/\u7edf\u8ba1key\u4e2d\u7684BitMap\u4e2d\u503c\u4e3a1\u7684\u4e2a\u6570\uff0c&#91;\u53ef\u9009\u53c2\u6570\uff1a\u4ecestart\u5230end\u5f00\u59cb\u7edf\u8ba1]\n<\/pre><\/div>\n\n\n<p>\u4f8b\u5982\u4e00\u4e2a\u9700\u6c42\uff1a\u53d1\u5e03\u4e00\u4e2a\u9650\u5b9a\u4f18\u60e0\u5238\uff0c\u89c4\u5b9a\u6bcf\u4e2a\u7528\u6237\u53ea\u80fd\u9886\u53d6\u4e00\u6b21\uff0c\u7981\u6b62\u91cd\u590d\u9886\u53d6\uff0c\u5982\u679c\u7528\u6570\u636e\u5e93map\u65b9\u5f0f\u7684\u8bdd\uff0c\u9886\u8fc7\u7684\u7528\u6237\u628auid\u52a0\u5165\u5230\u8be5\u793c\u5305\u7684\u5df2\u9886\u53d6\u5217\u8868\u5b57\u6bb5\u4e2d\u4e2d\uff0c\u4e0b\u6b21\u5982\u679c\u518d\u6b21\u9886\u53d6\u7684\u65f6\u5019\u5c31\u53d6\u8be5\u5b57\u6bb5\u8fdb\u884c\u662f\u5426\u5df2\u5b58\u5728\u5224\u65ad\uff0c\u867d\u7136\u53ef\u4ee5\u8fbe\u5230\u6548\u679c\uff0c\u4f46\u662f\u8be5\u8fc7\u7a0b\u6548\u7387\u4f4e\u4e0b\u3002\u53ef\u4ee5\u901a\u8fc7BitMap\u7684\u6807\u8bc6\u65b9\u5f0f\u8fdb\u884c\u5224\u65ad\u8fdb\u884c\u4f18\u5316\uff0c\u5bf9\u4e8e\u6bcf\u4e00\u5f20\u53d1\u5e03\u7684\u4f18\u60e0\u5238\u65b0\u5efa\u4e00\u4e2akey\uff0c\u6e38\u620f\u7528\u6237uid\uff1a10001\u7684\u73a9\u5bb6\u5982\u679c\u9886\u53d6\u4e86\u7684\u8bdd\uff0c\u5c31\u6267\u884c:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nsetbit  discount-id:xxx  user-uid:10001 1\n<\/pre><\/div>\n\n\n<p>\u8fd9\u91cc\u5c31\u5bf9\u8be5\u4f18\u60e0\u5238\u7684bit\u5b57\u6bb5\u4e2duid\u7684\u4f4d\u7f6e\u8fdb\u884c\u4e86\u6807\u8bc6\uff0c\u8868\u793a\u8be5\u7528\u6237\u5df2\u7ecf\u9886\u53d6\u4e86\u8be5\u4f18\u60e0\u5238\uff0c\u5728\u4e1a\u52a1\u903b\u8f91\u4e2d\u5982\u9700\u5224\u65ad\u8be5\u7528\u6237\u662f\u5426\u5df2\u7ecf\u9886\u53d6\u8be5\u4f18\u60e0\u5238\uff0c\u5224\u65ad\u65b9\u6cd5\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\ngetbit  discount-id:xxx  user-uid:10001 \n\/\/\u8fd4\u56de\u503c 1  \u6216\u8005  0\n\/\/\u5982\u679c\u672a\u9886\u53d6\u7684\u8bdd\u5c31\u662f\u672a\u6807\u793a\u72b6\u6001\uff0c0\uff0c\u5982\u679c\u5df2\u9886\u53d6\u5c31\u662f1\n<\/pre><\/div>\n\n\n<p>\u5982\u679c\u8981\u7edf\u8ba1\u8be5\u4f18\u60e0\u5238\u6709\u591a\u5c11\u4e2a\u7528\u6237\u9886\u53d6\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nbitcount  discount-id:xxx\n\/\/ \u8fd4\u56de\u503c\u4e3a\u8be5key\u503c\u4e2d1\u7684\u4e2a\u6570\n<\/pre><\/div>\n\n\n<p>\u4f7f\u7528BitMap\u7684\u65b9\u5f0f\u7684\u8bdd\uff0c\u4f18\u70b9\uff1a\u67e5\u8be2\u7edf\u8ba1\u65f6\u95f4\u5feb\uff0c\u6548\u7387\u9ad8\uff0c\u8d44\u6e90\u5360\u7528\u4f4e\uff0c\u4e14\u8282\u7ea6\u7a7a\u95f4\u3002\u7f3a\u70b9\uff1a\u529f\u80fd\u6709\u9650\uff0c\u65e0\u6cd5\u5b58\u50a8\u590d\u6742\u7684\u5185\u5bb9\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u53ea\u4e3e\u4f8b\u4e86\u4e00\u79cd\u7b80\u5355\u7684\u4f7f\u7528\u573a\u666f\uff0c\u8fd8\u6709\u8bb8\u591a\u573a\u666f\u53ef\u4ee5\u5229\u7528BitMap\u8fdb\u884c\u4f18\u5316\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u8003\u573a\u666f\uff1a \u9700\u8981\u5b58\u50a8\u91cf\u7279\u522b\u5927\u7684\u662f\u5426\u4fe1\u606f\uff0c\u4f8b\u5982\u7528\u6237\u70b9\u8d5e\uff0c\u7528\u6237\u7b7e\u5230\uff0c\u65e5\u6d3b\u7528\u6237\uff0c\u8bbf\u95ee\u8ba1\u6570\uff0c\u5728\u7ebf\u7528\u6237\u6570\u7b49\u7b49 \u4f55\u4e3aBit<span class=\"more-button\"><a href=\"https:\/\/diuut.com\/?p=1023\" class=\"more-link\">view all . . .<span class=\"screen-reader-text\">Redis\u4e4bBitMap\u9002\u7528\u573a\u666f<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":688,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[21,10],"_links":{"self":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/1023"}],"collection":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1023"}],"version-history":[{"count":9,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/1023\/revisions"}],"predecessor-version":[{"id":1075,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/1023\/revisions\/1075"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/media\/688"}],"wp:attachment":[{"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}