{"id":201258,"date":"2025-05-10T11:00:33","date_gmt":"2025-05-10T03:00:33","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201258\/"},"modified":"2025-05-10T11:00:33","modified_gmt":"2025-05-10T03:00:33","slug":"%e5%9f%ba%e4%ba%8eredis%e4%bd%8d%e5%9b%be%e5%ae%9e%e7%8e%b0%e7%b3%bb%e7%bb%9f%e7%94%a8%e6%88%b7%e7%99%bb%e5%bd%95%e7%bb%9f%e8%ae%a1","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201258\/","title":{"rendered":"\u57fa\u4e8eRedis\u4f4d\u56fe\u5b9e\u73b0\u7cfb\u7edf\u7528\u6237\u767b\u5f55\u7edf\u8ba1"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u57fa\u4e8eRedis\u4f4d\u56fe\u5b9e\u73b0\u7cfb\u7edf\u7528\u6237\u767b\u5f55\u7edf\u8ba1<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>IT\u884c\u4e1a\u76f8\u5bf9\u4e8e\u4e00\u822c\u4f20\u7edf\u884c\u4e1a\uff0c\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u66f4\u5feb\uff0c\u4e00\u65e6\u505c\u6b62\u4e86\u5b66\u4e60\uff0c\u5f88\u5feb\u5c31\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8e0f\u8e0f\u5b9e\u5b9e\u7684\u4e0d\u65ad\u5b66\u4e60\uff0c\u7cbe\u8fdb\u81ea\u5df1\u7684\u6280\u672f\uff0c\u5c24\u5176\u662f\u521d\u5b66\u8005\u3002\u4eca\u5929golang\u5b66\u4e60\u7f51\u7ed9\u5927\u5bb6\u6574\u7406\u4e86\u300a\u57fa\u4e8eRedis\u4f4d\u56fe\u5b9e\u73b0\u7cfb\u7edf\u7528\u6237\u767b\u5f55\u7edf\u8ba1\u300b\uff0c\u804a\u804a\u7edf\u8ba1\u3001\u767b\u5f55\u3001\u7528\u6237\u3001Redis\u4f4d\u56fe\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p>\u9879\u76ee\u9700\u6c42\uff0c\u8bd5\u7740\u5199\u4e86\u4e00\u4e2a\u7b80\u5355\u767b\u5f55\u7edf\u8ba1\uff0c\u57fa\u672c\u529f\u80fd\u90fd\u5b9e\u73b0\u4e86\uff0c\u65e5\u5fd7\u6570\u636e\u91cf\u5c0f\u3002\u5177\u4f53\u6027\u80fd\u6ca1\u6709\u8fdb\u884c\u6d4b\u8bd5~ \u8bb0\u5f55\u4e0b\u5f00\u53d1\u8fc7\u7a0b\u4e0e\u4ee3\u7801\uff0c\u7559\u7740\u4ee5\u540e\u6539\u8fdb\uff01<\/p>\n<p>1. \u9700\u6c42\u3000<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5b9e\u73b0\u8bb0\u5f55\u7528\u6237\u54ea\u5929\u8fdb\u884c\u4e86\u767b\u5f55\uff0c\u6bcf\u5929\u53ea\u8bb0\u5f55\u662f\u5426\u767b\u5f55\u8fc7\uff0c\u91cd\u590d\u767b\u5f55\u72b6\u6001\u7b97\u5df2\u767b\u5f55\u3002\u4e0d\u9700\u8981\u8bb0\u5f55\u7528\u6237\u7684\u64cd\u4f5c\u884c\u4e3a\uff0c\u4e0d\u9700\u8981\u8bb0\u5f55\u7528\u6237\u4e0a\u6b21\u767b\u5f55\u65f6\u95f4\u548cIP\u5730\u5740\uff08\u8fd9\u90e8\u5206\u4ee5\u540e\u9700\u8981\u53ef\u4ee5\u5355\u72ec\u62ff\u51fa\u6765\u5b58\u50a8\uff09\u3000\u533a\u5206\u7528\u6237\u7c7b\u578b\u3000\u67e5\u8be2\u6570\u636e\u9700\u8981\u7cbe\u786e\u5230\u5929<\/p>\n<p>2. \u5206\u6790<\/p>\n<p>\u3000\u3000\u8003\u8651\u5230\u53ea\u662f\u7b80\u5355\u7684\u8bb0\u5f55\u7528\u6237\u662f\u5426\u767b\u5f55\uff0c\u8bb0\u5f55\u6570\u636e\u6bd4\u8f83\u5355\u4e00\uff0c\u67e5\u8be2\u9700\u8981\u7cbe\u786e\u5230\u5929\u3002\u4ee5\u767e\u4e07\u7528\u6237\u91cf\u4e3a\u524d\u63d0\uff0c\u524d\u671f\u8003\u8651\u4e86\u51e0\u4e2a\u65b9\u6848<\/p>\n<p>2.1 \u4f7f\u7528\u6587\u4ef6<\/p>\n<p>\u3000\u3000\u4f7f\u7528\u5355\u6587\u4ef6\u5b58\u50a8\uff1a\u6587\u4ef6\u5360\u7528\u7a7a\u95f4\u589e\u957f\u901f\u5ea6\u5feb\uff0c\u6d77\u91cf\u6570\u636e\u68c0\u7d22\u4e0d\u65b9\u4fbf\uff0cMap\/Reduce\u64cd\u4f5c\u4e5f\u9ebb\u70e6<\/p>\n<p>\u3000\u3000\u4f7f\u7528\u591a\u6587\u4ef6\u5b58\u50a8\uff1a\u6309\u65e5\u671f\u5bf9\u6587\u4ef6\u8fdb\u884c\u5206\u5272\u3002\u6bcf\u5929\u8bb0\u5f55\u5f53\u5929\u65e5\u5fd7\uff0c\u6587\u4ef6\u91cf\u8fc7\u5927<\/p>\n<p>2.2 \u4f7f\u7528\u6570\u636e\u5e93<\/p>\n<p>\u4e0d\u592a\u8ba4\u540c\u76f4\u63a5\u4f7f\u7528\u6570\u636e\u5e93\u5199\u5165\/\u8bfb\u53d6<\/p>\n<ul>\n<li>\u9891\u7e41\u8bf7\u6c42\u6570\u636e\u5e93\u505a\u4e00\u4e9b\u65e5\u5fd7\u8bb0\u5f55\u6d6a\u8d39\u670d\u52a1\u5668\u5f00\u9500\u3002\u3000<\/li>\n<li>\u968f\u7740\u65f6\u95f4\u63a8\u79fb\u6570\u636e\u6025\u5267\u589e\u5927\u3000<\/li>\n<li>\u6d77\u91cf\u6570\u636e\u68c0\u7d22\u6548\u7387\u4e5f\u4e0d\u9ad8\uff0c\u540c\u65f6\u4f7f\u7528\u7d22\u5f15\uff0c\u6613\u4ea7\u751f\u788e\u7247\uff0c\u6bcf\u6b21\u63d2\u5165\u6570\u636e\u8fd8\u8981\u7ef4\u62a4\u7d22\u5f15\uff0c\u5f71\u54cd\u6027\u80fd<\/li>\n<\/ul>\n<p>\u3000\u3000\u6240\u4ee5\u53ea\u8003\u8651\u4f7f\u7528\u6570\u636e\u5e93\u505a\u6570\u636e\u5907\u4efd\u3002<\/p>\n<p>2.3 \u4f7f\u7528Redis\u4f4d\u56fe\uff08BitMap\uff09<\/p>\n<p>\u3000\u3000\u8fd9\u4e5f\u662f\u5728\u7f51\u4e0a\u770b\u5230\u7684\u65b9\u6cd5\uff0c\u6bd4\u8f83\u5b9e\u7528\u3002\u4e5f\u662f\u6211\u6700\u7ec8\u8003\u8651\u4f7f\u7528\u7684\u65b9\u6cd5\uff0c<\/p>\n<p>\u3000\u3000\u9996\u5148\u4f18\u70b9\uff1a<\/p>\n<p>\u3000\u3000\u6570\u636e\u91cf\u5c0f\uff1a\u4e00\u4e2abit\u4f4d\u6765\u8868\u793a\u67d0\u4e2a\u5143\u7d20\u5bf9\u5e94\u7684\u503c\u6216\u8005\u72b6\u6001,\u5176\u4e2d\u7684key\u5c31\u662f\u5bf9\u5e94\u5143\u7d20\u672c\u8eab\u3002\u6211\u4eec\u77e5\u90538\u4e2abit\u53ef\u4ee5\u7ec4\u6210\u4e00\u4e2aByte\uff0c\u6240\u4ee5bitmap\u672c\u8eab\u4f1a\u6781\u5927\u7684\u8282\u7701\u50a8\u5b58\u7a7a\u95f4\u30021\u4ebf\u4eba\u6bcf\u5929\u7684\u767b\u9646\u60c5\u51b5,\u75281\u4ebfbit,\u7ea61200WByte,\u7ea610M \u7684\u5b57\u7b26\u5c31\u80fd\u8868\u793a\u3002<\/p>\n<p>\u3000\u3000\u8ba1\u7b97\u65b9\u4fbf\uff1a\u5b9e\u7528Redis bit \u76f8\u5173\u547d\u4ee4\u53ef\u4ee5\u6781\u5927\u7684\u7b80\u5316\u4e00\u4e9b\u7edf\u8ba1\u64cd\u4f5c\u3002\u5e38\u7528\u547d\u4ee4 \u3001\u3001\u3001<\/p>\n<p>\u3000\u3000\u518d\u8bf4\u5f0a\u7aef\uff1a<\/p>\n<p>\u3000\u3000\u5b58\u50a8\u5355\u4e00\uff1a\u8fd9\u4e5f\u7b97\u4e0d\u4e0a\u4ec0\u4e48\u7f3a\u70b9\uff0c\u4f4d\u56fe\u4e0a\u5b58\u50a8\u53ea\u662f0\/1\uff0c\u6240\u4ee5\u9700\u8981\u5b58\u50a8\u5176\u4ed6\u4fe1\u606f\u5c31\u8981\u522b\u7684\u5730\u65b9\u5355\u72ec\u8bb0\u5f55\uff0c\u5bf9\u4e8e\u9700\u8981\u5b58\u50a8\u4fe1\u606f\u591a\u7684\u8bb0\u5f55\u5c31\u9700\u8981\u4f7f\u7528\u522b\u7684\u65b9\u6cd5\u4e86<\/p>\n<p>3. \u8bbe\u8ba13.1 Redis BitMap<\/p>\n<p>\u3000\u3000Key\u7ed3\u6784\uff1a\u524d\u7f00_\u5e74Y-\u6708m_\u7528\u6237\u7c7b\u578b_\u7528\u6237ID<\/p>\n<blockquote>\n<p>\u6807\u51c6Key\uff1a KEYS loginLog_2017-10_client_1001<br \/> \u68c0\u7d22\u5168\u90e8\uff1a KEYS loginLog_*<br \/> \u68c0\u7d22\u67d0\u5e74\u67d0\u6708\u5168\u90e8\uff1a KEYS loginLog_2017-10_*<br \/> \u68c0\u7d22\u5355\u4e2a\u7528\u6237\u5168\u90e8\uff1a KEYS loginLog_*_client_1001<br \/> \u68c0\u7d22\u5355\u4e2a\u7c7b\u578b\u5168\u90e8\uff1a KEYS loginLog_*_office_*<br \/> &#8230;\u3000\u3000<\/p>\n<\/blockquote>\n<p>\u3000\u3000\u6bcf\u6761BitMap\u8bb0\u5f55\u5355\u4e2a\u7528\u6237\u4e00\u4e2a\u6708\u7684\u767b\u5f55\u60c5\u51b5\uff0c\u4e00\u4e2abit\u4f4d\u8868\u793a\u4e00\u5929\u767b\u5f55\u60c5\u51b5\u3002<\/p>\n<blockquote>\n<p>\u8bbe\u7f6e\u7528\u62371001\uff0c217-10-25\u767b\u5f55\uff1a SETBIT loginLog_2017-10_client_1001 25 1<br \/> \u83b7\u53d6\u7528\u62371001\uff0c217-10-25\u662f\u5426\u767b\u5f55\uff1aGETBIT loginLog_2017-10_client_1001 25<br \/> \u83b7\u53d6\u7528\u62371001\uff0c217-10\u6708\u662f\u5426\u767b\u5f55\uff1a GETCOUNT loginLog_2017-10_client_1001<br \/> \u83b7\u53d6\u7528\u62371001\uff0c217-10\/9\/7\u6708\u662f\u5426\u767b\u5f55\uff1aBITOP OR stat loginLog_2017-10_client_1001 loginLog_2017-09_client_1001 loginLog_2017-07_client_1001<br \/> &#8230;<\/p>\n<\/blockquote>\n<p>\u3000\u3000\u5173\u4e8e\u83b7\u53d6\u767b\u5f55\u4fe1\u606f\uff0c\u5c31\u5f97\u83b7\u53d6BitMap\u7136\u540e\u62c6\u5f00\uff0c\u5faa\u73af\u8fdb\u884c\u5224\u65ad\u3002\u7279\u522b\u6d89\u53ca\u65f6\u95f4\u8303\u56f4\uff0c\u9700\u8981\u6ce8\u610f\u65f6\u95f4\u8fb9\u754c\u7684\u95ee\u9898\uff0c\u4e0d\u8981\u67e5\u8be2\u51fa\u591a\u4f59\u7684\u6570\u636e<\/p>\n<p>\u3000\u3000\u83b7\u53d6\u6570\u636eRedis\u4f18\u5148\u7ea7\u9ad8\u4e8e\u6570\u636e\u5e93\uff0cRedis\u6709\u7684\u8bb0\u5f55\u4e0d\u8981\u53bb\u6570\u636e\u5e93\u83b7\u53d6<\/p>\n<p>\u3000\u3000Redis\u6570\u636e\u8fc7\u671f\uff1a\u5728\u6570\u636e\u540c\u6b65\u4e2d\u8fdb\u884c\u5224\u65ad\uff0c\u8fc7\u671f\u65f6\u95f4\u81ea\u5df1\u5b9a\u4e49\uff08\u6211\u5b9a\u4e49\u7684\u8fc7\u671f\u65f6\u95f4\u5355\u4f4d\u4e3a\u201c\u5929\u201d\uff0c\u5fc5\u987b\u5927\u4e8e31\uff09\u3002<\/p>\n<p>\u3000\u3000\u5728\u4e0d\u80fd\u4fdd\u8bc1\u540c\u6b65\u4e0e\u8fc7\u671f\u4e00\u81f4\u6027\u7684\u95ee\u9898\uff0c\u4e0d\u8981\u7ed9Key\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\uff0c\u4f1a\u9020\u6210\u6570\u636e\u4e22\u5931\u3002<\/p>\n<blockquote>\n<p>\u4e0a\u4e00\u6b21\u66f4\u65b0\u65f6\u95f4\uff1a 2107-10-02<br \/> \u4e0b\u4e00\u6b21\u66f4\u65b0\u65f6\u95f4\uff1a 2017-10-09<br \/> Redis BitMap \u8fc7\u671f\u65f6\u95f4\uff1a 2017-10-05<\/p>\n<\/blockquote>\n<p>\u8fd9\u6837\u4f1a\u9020\u6210\uff1a2017-10-09\u540c\u6b65\u7684\u65f6\u5019\uff0c3\/4\/5\/6\/7\/8\/9 \u6570\u636e\u4e22\u5931\u3000<\/p>\n<p>\u3000\u6240\u4ee5\u6211\u628aRedis\u8fc7\u671f\u6570\u636e\u653e\u5230\u540c\u6b65\u65f6\u8fdb\u884c\u5224\u65ad\u3000\u3000<\/p>\n<p>\u3000\u3000\u6211\u81ea\u5df1\u60f3\u7684\u540c\u6b65\u7b56\u7565\uff08\u5b9a\u65f6\u6bcf\u5468\u4e00\u51cc\u6668\u540c\u6b65\uff09\uff1a<\/p>\n<p>\u4e00\u3001\u9a8c\u8bc1\u662f\u5426\u9700\u8981\u8fdb\u884c\u540c\u6b65\uff1a<\/p>\n<p>1. \u5f53\u524d\u65e5\u671f &gt;= 8\u53f7\uff0c\u5bf9\u672c\u6708\u6240\u6709\u8bb0\u5f55\u8fdb\u884c\u540c\u6b65\uff0c\u4e0d\u5bf9\u672c\u6708\u4e4b\u524d\u7684\u8bb0\u5f55\u8fdb\u884c\u540c\u6b65<\/p>\n<p>2. \u5f53\u524d\u65e5\u671f <\/p>\n<p>\u4e8c\u3001\u9a8c\u8bc1\u8fc7\u671f\uff0c\u5982\u679c\u8fc7\u671f\uff0c\u8bb0\u5f55\u65e5\u5fd7\u540e\u5220\u9664[\/code]3.2 \u6570\u636e\u5e93\uff0c\u8868\u7ed3\u6784<\/p>\n<p>\u3000\u3000\u6bcf\u5468\u540c\u6b65\u4e00\u6b21\u6570\u636e\u5230\u6570\u636e\u5e93\uff0c\u8868\u4e2d\u4e00\u6761\u6570\u636e\u5bf9\u5e94\u4e00\u4e2aBitMap\uff0c\u8bb0\u5f55\u4e00\u4e2a\u6708\u6570\u636e\u3002\u6bcf\u6b21\u66f4\u65b0\u5df2\u5b58\u5728\u7684\u3001\u63d2\u5165\u6ca1\u6709\u7684<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230101\/167253753763b0e5c13f230.png\" class=\"aligncenter\"><\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230101\/167253753763b0e5c17f39c.png\" class=\"aligncenter\"><\/p>\n<p>3.3 \u6682\u5b9a\u63a5\u53e3\u3000<\/p>\n<ul>\n<li>\u3000\u8bbe\u7f6e\u7528\u6237\u767b\u5f55<\/li>\n<li>\u3000\u67e5\u8be2\u5355\u4e2a\u7528\u6237\u67d0\u5929\u662f\u5426\u767b\u5f55\u8fc7<\/li>\n<li>\u67e5\u8be2\u5355\u4e2a\u7528\u6237\u67d0\u6708\u662f\u5426\u767b\u5f55\u8fc7<\/li>\n<li>\u3000\u67e5\u8be2\u5355\u4e2a\u7528\u6237\u67d0\u4e2a\u65f6\u95f4\u6bb5\u662f\u5426\u767b\u5f55\u8fc7<\/li>\n<li>\u3000\u67e5\u8be2\u5355\u4e2a\u7528\u6237\u67d0\u4e2a\u65f6\u95f4\u6bb5\u767b\u5f55\u4fe1\u606f<\/li>\n<li>\u3000\u6307\u5b9a\u7528\u6237\u7c7b\u578b\uff1a\u83b7\u53d6\u67d0\u4e2a\u65f6\u95f4\u6bb5\u5185\u6709\u6548\u767b\u5f55\u7684\u7528\u6237<\/li>\n<li>\u3000\u5168\u90e8\u7528\u6237\uff1a\u83b7\u53d6\u67d0\u4e2a\u65f6\u95f4\u6bb5\u5185\u6709\u6548\u767b\u5f55\u7684\u7528\u6237<\/li>\n<\/ul>\n<p>4. Code<\/p>\n<p>\u3000\u3000TP3\u4e2d\u5b9e\u73b0\u7684\u4ee3\u7801\uff0c\u5728\u63a5\u53e3\u670d\u52a1\u5668\u5185\u90e8\u5e93\u4e2d\uff0cApplication\\Lib\\<\/p>\n<p>\u3000\u3000\u251c\u2500LoginLog<\/p>\n<p>\u3000\u3000\u2502\u251c\u2500Logs \u65e5\u5fd7\u76ee\u5f55\uff0cRedis\u4e2d\u8fc7\u671f\u7684\u8bb0\u5f55\u5220\u9664\u5199\u5165\u65e5\u5fd7\u8fdb\u884c\u5907\u4efd<\/p>\n<p>\u3000\u3000\u2502\u251c\u2500LoginLog.class.php \u5bf9\u5916\u63a5\u53e3<\/p>\n<p>\u3000\u3000\u2502\u251c\u2500LoginLogCommon.class.php \u516c\u5171\u5de5\u5177\u7c7b<\/p>\n<p>\u3000\u3000\u2502\u251c\u2500LoginLogDBHandle.class.php \u6570\u636e\u5e93\u64cd\u4f5c\u7c7b<\/p>\n<p>\u3000\u3000\u2502\u251c\u2500LoginLogRedisHandle.class.php Redis\u64cd\u4f5c\u7c7b<\/p>\n<p>4.1 LoginLog.class.php<\/p>\n<pre>\n_redisHandle = new LoginLogRedisHandle($this);\n$this-&gt;_dbHandle  = new LoginLogDBHandle($this);\n\n\/\/ \u521d\u59cb\u5316\u65e5\u5fd7\n$logHandler = new CLogFileHandler(__DIR__ . '\/Logs\/del.log');\nLog::Init($logHandler, 15);\n}\n\n\/**\n* \u8bb0\u5f55\u767b\u5f55\uff1a\u6bcf\u5929\u53ea\u8bb0\u5f55\u4e00\u6b21\u767b\u5f55\uff0c\u53ea\u5141\u8bb8\u8bbe\u7f6e\u5f53\u6708\u5185\u767b\u5f55\u8bb0\u5f55\n* @param string $type \u7528\u6237\u7c7b\u578b\n* @param int  $uid \u552f\u4e00\u6807\u8bc6\uff08\u7528\u6237ID\uff09\n* @param int  $time \u65f6\u95f4\u6233\n* @return boolean\n*\/\npublic function setLogging($type, $uid, $time)\n{\n$key = $this-&gt;_redisHandle-&gt;getLoginLogKey($type, $uid, $time);\nif ($this-&gt;_redisHandle-&gt;checkLoginLogKey($key)) {\nreturn $this-&gt;_redisHandle-&gt;setLogging($key, $time);\n}\nreturn false;\n}\n\n\/**\n* \u67e5\u8be2\u7528\u6237\u67d0\u4e00\u5929\u662f\u5426\u767b\u5f55\u8fc7\n* @param string $type \u7528\u6237\u7c7b\u578b\n* @param int  $uid \u552f\u4e00\u6807\u8bc6\uff08\u7528\u6237ID\uff09\n* @param int  $time \u65f6\u95f4\u6233\n* @return boolean \u53c2\u6570\u9519\u8bef\u6216\u672a\u767b\u5f55\u8fc7\u8fd4\u56defalse\uff0c\u767b\u5f55\u8fc7\u8fd4\u56detrue\n*\/\npublic function getDateWhetherLogin($type, $uid, $time)\n{\n$key = $this-&gt;_redisHandle-&gt;getLoginLogKey($type, $uid, $time);\nif ($this-&gt;_redisHandle-&gt;checkLoginLogKey($key)) {\n\n\/\/ \u5224\u65adRedis\u4e2d\u662f\u5426\u5b58\u5728\u8bb0\u5f55\n$isRedisExists = $this-&gt;_redisHandle-&gt;checkRedisLogExists($key);\nif ($isRedisExists) {\n\n\/\/ \u4eceRedis\u4e2d\u8fdb\u884c\u5224\u65ad\nreturn $this-&gt;_redisHandle-&gt;dateWhetherLogin($key, $time);\n} else {\n\n\/\/ \u4ece\u6570\u636e\u5e93\u4e2d\u8fdb\u884c\u5224\u65ad\nreturn $this-&gt;_dbHandle-&gt;dateWhetherLogin($type, $uid, $time);\n}\n}\nreturn false;\n}\n\n\/**\n* \u67e5\u8be2\u7528\u6237\u67d0\u6708\u662f\u5426\u767b\u5f55\u8fc7\n* @param string $type \u7528\u6237\u7c7b\u578b\n* @param int  $uid \u552f\u4e00\u6807\u8bc6\uff08\u7528\u6237ID\uff09\n* @param int  $time \u65f6\u95f4\u6233\n* @return boolean \u53c2\u6570\u9519\u8bef\u6216\u672a\u767b\u5f55\u8fc7\u8fd4\u56defalse\uff0c\u767b\u5f55\u8fc7\u8fd4\u56detrue\n*\/\npublic function getDateMonthWhetherLogin($type, $uid, $time)\n{\n$key = $this-&gt;_redisHandle-&gt;getLoginLogKey($type, $uid, $time);\nif ($this-&gt;_redisHandle-&gt;checkLoginLogKey($key)) {\n\n\/\/ \u5224\u65adRedis\u4e2d\u662f\u5426\u5b58\u5728\u8bb0\u5f55\n$isRedisExists = $this-&gt;_redisHandle-&gt;checkRedisLogExists($key);\nif ($isRedisExists) {\n\n\/\/ \u4eceRedis\u4e2d\u8fdb\u884c\u5224\u65ad\nreturn $this-&gt;_redisHandle-&gt;dateMonthWhetherLogin($key);\n} else {\n\n\/\/ \u4ece\u6570\u636e\u5e93\u4e2d\u8fdb\u884c\u5224\u65ad\nreturn $this-&gt;_dbHandle-&gt;dateMonthWhetherLogin($type, $uid, $time);\n}\n}\nreturn false;\n}\n\n\/**\n* \u67e5\u8be2\u7528\u6237\u5728\u67d0\u4e2a\u65f6\u95f4\u6bb5\u662f\u5426\u767b\u5f55\u8fc7\n* @param string $type \u7528\u6237\u7c7b\u578b\n* @param int  $uid \u552f\u4e00\u6807\u8bc6\uff08\u7528\u6237ID\uff09\n* @param int  $startTime \u5f00\u59cb\u65f6\u95f4\u6233\n* @param int  $endTime  \u7ed3\u675f\u65f6\u95f4\u6233\n* @return boolean \u53c2\u6570\u9519\u8bef\u6216\u672a\u767b\u5f55\u8fc7\u8fd4\u56defalse\uff0c\u767b\u5f55\u8fc7\u8fd4\u56detrue\n*\/\npublic function getTimeRangeWhetherLogin($type, $uid, $startTime, $endTime){\n$result = $this-&gt;getUserTimeRangeLogin($type, $uid, $startTime, $endTime);\nif ($result['hasLog']['count'] &gt; 0) {\nreturn true;\n}\nreturn false;\n}\n\n\/**\n* \u83b7\u53d6\u7528\u6237\u67d0\u65f6\u95f4\u6bb5\u5185\u767b\u5f55\u4fe1\u606f\n* @param string $type   \u7528\u6237\u7c7b\u578b\n* @param int  $uid    \u552f\u4e00\u6807\u8bc6\uff08\u7528\u6237ID\uff09\n* @param int  $startTime \u5f00\u59cb\u65f6\u95f4\u6233\n* @param int  $endTime  \u7ed3\u675f\u65f6\u95f4\u6233\n* @return array \u53c2\u6570\u9519\u8bef\u6216\u672a\u67e5\u8be2\u5230\u8fd4\u56dearray()\n* -------------------------------------------------\n* \u67e5\u8be2\u5230\u7ed3\u679c\uff1a\n* array(\n*   'hasLog' =&gt; array(\n*     'count' =&gt; n,                 \/\/ \u6709\u6548\u767b\u5f55\u6b21\u6570\uff0c\u6bcf\u5929\u91cd\u590d\u767b\u5f55\u7b97\u4e00\u6b21\n*     'list' =&gt; array('2017-10-1', '2017-10-15' ...) \/\/ \u6709\u6548\u767b\u5f55\u65e5\u671f\n*   ),\n*   'notLog' =&gt; array(\n*     'count' =&gt; n,                 \/\/ \u672a\u767b\u5f55\u6b21\u6570\n*     'list' =&gt; array('2017-10-1', '2017-10-15' ...) \/\/ \u672a\u767b\u5f55\u65e5\u671f\n*   )\n* )\n*\/\npublic function getUserTimeRangeLogin($type, $uid, $startTime, $endTime)\n{\n$hasCount  = 0;    \/\/ \u6709\u6548\u767b\u5f55\u6b21\u6570\n$notCount  = 0;    \/\/ \u672a\u767b\u5f55\u6b21\u6570\n$hasList  = array(); \/\/ \u6709\u6548\u767b\u5f55\u65e5\u671f\n$notList  = array(); \/\/ \u672a\u767b\u5f55\u65e5\u671f\n$successFlg = false;  \/\/ \u67e5\u8be2\u5230\u6570\u636e\u6807\u8bc6\n\nif ($this-&gt;checkTimeRange($startTime, $endTime)) {\n\n\/\/ \u83b7\u53d6\u9700\u8981\u67e5\u8be2\u7684Key\n$keyList = $this-&gt;_redisHandle-&gt;getTimeRangeRedisKey($type, $uid, $startTime, $endTime);\n\nif (!empty($keyList)) {\nforeach ($keyList as $key =&gt; $val) {\n\n\/\/ \u5224\u65adRedis\u4e2d\u662f\u5426\u5b58\u5728\u8bb0\u5f55\n$isRedisExists = $this-&gt;_redisHandle-&gt;checkRedisLogExists($val['key']);\nif ($isRedisExists) {\n\n\/\/ \u5b58\u5728\uff0c\u76f4\u63a5\u4eceRedis\u4e2d\u83b7\u53d6\n$logInfo = $this-&gt;_redisHandle-&gt;getUserTimeRangeLogin($val['key'], $startTime, $endTime);\n} else {\n\n\/\/ \u4e0d\u5b58\u5728\uff0c\u5c1d\u8bd5\u4ece\u6570\u636e\u5e93\u4e2d\u8bfb\u53d6\n$logInfo = $this-&gt;_dbHandle-&gt;getUserTimeRangeLogin($type, $uid, $val['time'], $startTime, $endTime);\n}\n\nif (is_array($logInfo)) {\n$hasCount += $logInfo['hasLog']['count'];\n$hasList = array_merge($hasList, $logInfo['hasLog']['list']);\n$notCount += $logInfo['notLog']['count'];\n$notList = array_merge($notList, $logInfo['notLog']['list']);\n$successFlg = true;\n}\n}\n}\n}\n\nif ($successFlg) {\nreturn array(\n'hasLog' =&gt; array(\n'count' =&gt; $hasCount,\n'list' =&gt; $hasList\n),\n'notLog' =&gt; array(\n'count' =&gt; $notCount,\n'list' =&gt; $notList\n)\n);\n}\n\nreturn array();\n}\n\n\/**\n* \u83b7\u53d6\u67d0\u6bb5\u65f6\u95f4\u5185\u6709\u6548\u767b\u5f55\u8fc7\u7684\u7528\u6237 \u7edf\u4e00\u63a5\u53e3\n* @param int  $startTime \u5f00\u59cb\u65f6\u95f4\u6233\n* @param int  $endTime  \u7ed3\u675f\u65f6\u95f4\u6233\n* @param array $typeArr  \u7528\u6237\u7c7b\u578b\uff0c\u4e3a\u7a7a\u65f6\u83b7\u53d6\u5168\u90e8\u7c7b\u578b\n* @return array \u53c2\u6570\u9519\u8bef\u6216\u672a\u67e5\u8be2\u5230\u8fd4\u56dearray()\n* -------------------------------------------------\n* \u67e5\u8be2\u5230\u7ed3\u679c\uff1a\u6307\u5b9a\u7528\u6237\u7c7b\u578b\n* array(\n*   'type1' =&gt; array(\n*     'count' =&gt; n,           \/\/ type1 \u6709\u6548\u767b\u5f55\u603b\u7528\u6237\u6570\n*     'list' =&gt; array('111', '222' ...) \/\/ type1 \u6709\u6548\u767b\u5f55\u7528\u6237\n*   ),\n*   'type2' =&gt; array(\n*     'count' =&gt; n,           \/\/ type2 \u6709\u6548\u767b\u5f55\u603b\u7528\u6237\u6570\n*     'list' =&gt; array('333', '444' ...) \/\/ type2 \u6709\u6548\u767b\u5f55\u7528\u6237\n*   )\n* )\n* -------------------------------------------------\n* \u67e5\u8be2\u5230\u7ed3\u679c\uff1a\u672a\u6307\u5b9a\u7528\u6237\u7c7b\u578b\uff0c\u5168\u90e8\u7528\u6237\uff0c\u56fa\u5b9a\u952e 'all'\n* array(\n*   'all' =&gt; array(\n*     'count' =&gt; n,           \/\/ \u6709\u6548\u767b\u5f55\u603b\u7528\u6237\u6570\n*     'list' =&gt; array('111', '222' ...) \/\/ \u6709\u6548\u767b\u5f55\u7528\u6237\n*   )\n* )\n*\/\npublic function getOrientedTimeRangeLogin($startTime, $endTime, $typeArr = array())\n{\nif ($this-&gt;checkTimeRange($startTime, $endTime)) {\n\n\/\/ \u5224\u65ad\u662f\u5426\u6307\u5b9a\u7c7b\u578b\nif (is_array($typeArr) &amp;&amp; !empty($typeArr)) {\n\n\/\/ \u6307\u5b9a\u7c7b\u578b\uff0c\u9a8c\u8bc1\u7c7b\u578b\u5408\u6cd5\u6027\nif ($this-&gt;checkTypeArr($typeArr)) {\n\n\/\/ \u4f9d\u636e\u7c7b\u578b\u83b7\u53d6\nreturn $this-&gt;getSpecifyTypeTimeRangeLogin($startTime, $endTime, $typeArr);\n}\n} else {\n\n\/\/ \u672a\u6307\u5b9a\u7c7b\u578b\uff0c\u7edf\u4e00\u83b7\u53d6\nreturn $this-&gt;getSpecifyAllTimeRangeLogin($startTime, $endTime);\n}\n}\nreturn array();\n}\n\n\/**\n* \u6307\u5b9a\u7c7b\u578b\uff1a\u83b7\u53d6\u67d0\u6bb5\u65f6\u95f4\u5185\u767b\u5f55\u8fc7\u7684\u7528\u6237\n* @param int  $startTime \u5f00\u59cb\u65f6\u95f4\u6233\n* @param int  $endTime  \u7ed3\u675f\u65f6\u95f4\u6233\n* @param array $typeArr  \u7528\u6237\u7c7b\u578b\n* @return array\n*\/\nprivate function getSpecifyTypeTimeRangeLogin($startTime, $endTime, $typeArr)\n{\n$data = array();\n$successFlg = false; \/\/ \u67e5\u8be2\u5230\u6570\u636e\u6807\u8bc6\n\n\/\/ \u6307\u5b9a\u7c7b\u578b\uff0c\u6839\u636e\u7c7b\u578b\u5355\u72ec\u83b7\u53d6\uff0c\u8fdb\u884c\u6574\u5408\nforeach ($typeArr as $typeArrVal) {\n\n\/\/ \u83b7\u53d6\u9700\u8981\u67e5\u8be2\u7684Key\n$keyList = $this-&gt;_redisHandle-&gt;getSpecifyTypeTimeRangeRedisKey($typeArrVal, $startTime, $endTime);\nif (!empty($keyList)) {\n\n$data[$typeArrVal]['count'] = 0;    \/\/ \u8be5\u7c7b\u578b\u4e0b\u6709\u6548\u767b\u5f55\u7528\u6237\u6570\n$data[$typeArrVal]['list'] = array(); \/\/ \u8be5\u7c7b\u578b\u4e0b\u6709\u6548\u767b\u5f55\u7528\u6237\n\nforeach ($keyList as $keyListVal) {\n\n\/\/ \u67e5\u8be2Kye\uff0c\u9a8c\u8bc1Redis\u4e2d\u662f\u5426\u5b58\u5728\uff1a\u6b64\u5904\u4e3a\u5355\u4e2a\u7c7b\u578b\uff0c\u6240\u4ee5\u76f4\u63a5\u770bRedis\u4e2d\u662f\u5426\u5b58\u5728\u8be5\u7c7b\u578bKey\u5373\u53ef\u5224\u65ad\u662f\u5426\u5b58\u5728\n\/\/ \u5b58\u5728\u7684\u6570\u636e\u4e0d\u9700\u8981\u53bb\u6570\u636e\u5e93\u4e2d\u53bb\u67e5\u770b\n$standardKeyList = $this-&gt;_redisHandle-&gt;getKeys($keyListVal['key']);\nif (is_array($standardKeyList) &amp;&amp; count($standardKeyList) &gt; 0) {\n\n\/\/ Redis\u5b58\u5728\nforeach ($standardKeyList as $standardKeyListVal) {\n\n\/\/ \u9a8c\u8bc1\u8be5\u7528\u6237\u5728\u6b64\u65f6\u95f4\u6bb5\u662f\u5426\u767b\u5f55\u8fc7\n$redisCheckLogin = $this-&gt;_redisHandle-&gt;getUserTimeRangeLogin($standardKeyListVal, $startTime, $endTime);\nif ($redisCheckLogin['hasLog']['count'] &gt; 0) {\n\n\/\/ \u540c\u4e00\u4e2a\u7528\u6237\u53ea\u9700\u8bb0\u5f55\u4e00\u6b21\n$uid = $this-&gt;_redisHandle-&gt;getLoginLogKeyInfo($standardKeyListVal, 'uid');\nif (!in_array($uid, $data[$typeArrVal]['list'])) {\n$data[$typeArrVal]['count']++;\n$data[$typeArrVal]['list'][] = $uid;\n}\n$successFlg = true;\n}\n}\n\n} else {\n\n\/\/ \u4e0d\u5b58\u5728\uff0c\u5c1d\u8bd5\u4ece\u6570\u636e\u5e93\u4e2d\u83b7\u53d6\n$dbResult = $this-&gt;_dbHandle-&gt;getTimeRangeLoginSuccessUser($keyListVal['time'], $startTime, $endTime, $typeArrVal);\nif (!empty($dbResult)) {\nforeach ($dbResult as $dbResultVal) {\nif (!in_array($dbResultVal, $data[$typeArrVal]['list'])) {\n$data[$typeArrVal]['count']++;\n$data[$typeArrVal]['list'][] = $dbResultVal;\n}\n}\n$successFlg = true;\n}\n}\n}\n}\n}\n\nif ($successFlg) { return $data; }\nreturn array();\n}\n\n\/**\n* \u5168\u90e8\u7c7b\u578b\uff1a\u83b7\u53d6\u67d0\u6bb5\u65f6\u95f4\u5185\u767b\u5f55\u8fc7\u7684\u7528\u6237\n* @param int  $startTime \u5f00\u59cb\u65f6\u95f4\u6233\n* @param int  $endTime  \u7ed3\u675f\u65f6\u95f4\u6233\n* @return array\n*\/\nprivate function getSpecifyAllTimeRangeLogin($startTime, $endTime)\n{\n$count   = 0;    \/\/ \u6709\u6548\u767b\u5f55\u7528\u6237\u6570\n$list    = array(); \/\/ \u6709\u6548\u767b\u5f55\u7528\u6237\n$successFlg = false;  \/\/ \u67e5\u8be2\u5230\u6570\u636e\u6807\u8bc6\n\n\/\/ \u672a\u6307\u5b9a\u7c7b\u578b\uff0c\u76f4\u63a5\u5bf9\u6240\u6709\u6570\u636e\u8fdb\u884c\u68c0\u7d22\n\/\/ \u83b7\u53d6\u9700\u8981\u67e5\u8be2\u7684Key\n$keyList = $this-&gt;_redisHandle-&gt;getSpecifyAllTimeRangeRedisKey($startTime, $endTime);\n\nif (!empty($keyList)) {\nforeach ($keyList as $keyListVal) {\n\n\/\/ \u67e5\u8be2Kye\n$standardKeyList = $this-&gt;_redisHandle-&gt;getKeys($keyListVal['key']);\n\nif (is_array($standardKeyList) &amp;&amp; count($standardKeyList) &gt; 0) {\n\n\/\/ \u67e5\u8be2\u5230Key\uff0c\u76f4\u63a5\u8bfb\u53d6\u6570\u636e\uff0c\u8bb0\u5f55\u7c7b\u578b\nforeach ($standardKeyList as $standardKeyListVal) {\n\n\/\/ \u9a8c\u8bc1\u8be5\u7528\u6237\u5728\u6b64\u65f6\u95f4\u6bb5\u662f\u5426\u767b\u5f55\u8fc7\n$redisCheckLogin = $this-&gt;_redisHandle-&gt;getUserTimeRangeLogin($standardKeyListVal, $startTime, $endTime);\nif ($redisCheckLogin['hasLog']['count'] &gt; 0) {\n\n\/\/ \u540c\u4e00\u4e2a\u7528\u6237\u53ea\u9700\u8bb0\u5f55\u4e00\u6b21\n$uid = $this-&gt;_redisHandle-&gt;getLoginLogKeyInfo($standardKeyListVal, 'uid');\nif (!in_array($uid, $list)) {\n$count++;\n$list[] = $uid;\n}\n$successFlg = true;\n}\n}\n}\n\n\/\/ \u65e0\u8bbaRedis\u4e2d\u5b58\u5728\u4e0d\u5b58\u5728\u90fd\u8981\u5c1d\u8bd5\u4ece\u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u4e00\u904d\u6570\u636e\uff0c\u6765\u8865\u5145Redis\u83b7\u53d6\u7684\u6570\u636e\uff0c\u4fdd\u8bc1\u68c0\u7d22\u6570\u636e\u5b8c\u6574\uff08Redis\u7c7b\u578b\u7f3a\u5931\u53ef\u80fd\u5bfc\u81f4\uff09\n$dbResult = $this-&gt;_dbHandle-&gt;getTimeRangeLoginSuccessUser($keyListVal['time'], $startTime, $endTime);\nif (!empty($dbResult)) {\nforeach ($dbResult as $dbResultVal) {\nif (!in_array($dbResultVal, $list)) {\n$count++;\n$list[] = $dbResultVal;\n}\n}\n$successFlg = true;\n}\n}\n}\n\nif ($successFlg) {\nreturn array(\n'all' =&gt; array(\n'count' =&gt; $count,\n'list' =&gt; $list\n)\n);\n}\nreturn array();\n}\n\n\/**\n* \u9a8c\u8bc1\u5f00\u59cb\u7ed3\u675f\u65f6\u95f4\n* @param string $startTime \u5f00\u59cb\u65f6\u95f4\n* @param string $endTime  \u7ed3\u675f\u65f6\u95f4\n* @return boolean\n*\/\nprivate function checkTimeRange($startTime, $endTime)\n{\nreturn $this-&gt;_redisHandle-&gt;checkTimeRange($startTime, $endTime);\n}\n\n\/**\n* \u6279\u91cf\u9a8c\u8bc1\u7528\u6237\u7c7b\u578b\n* @param array $typeArr \u7528\u6237\u7c7b\u578b\u6570\u7ec4\n* @return boolean\n*\/\nprivate function checkTypeArr($typeArr)\n{\n$flg = false;\nif (is_array($typeArr) &amp;&amp; !empty($typeArr)) {\nforeach ($typeArr as $val) {\nif ($this-&gt;_redisHandle-&gt;checkType($val)) {\n$flg = true;\n} else {\n$flg = false; break;\n}\n}\n}\nreturn $flg;\n}\n\n\/**\n* \u5b9a\u65f6\u4efb\u52a1\u6bcf\u5468\u8c03\u7528\u4e00\u6b21\uff1a\u4eceRedis\u540c\u6b65\u767b\u5f55\u65e5\u5fd7\u5230\u6570\u636e\u5e93\n* @param int  $existsDay \u4e00\u6761\u8bb0\u5f55\u5728Redis\u4e2d\u8fc7\u671f\u65f6\u95f4\uff0c\u5355\u4f4d\uff1a\u5929\uff0c\u5fc5\u987b\u5927\u4e8e31\n* @return string\n* 'null'\uff1a  Redis\u4e2d\u65e0\u6570\u636e\n* 'fail'\uff1a  \u540c\u6b65\u5931\u8d25\n* 'success'\uff1a\u540c\u6b65\u6210\u529f\n*\/\npublic function cronWeeklySync($existsDay)\n{\n\n\/\/ \u9a8c\u8bc1\u751f\u5b58\u65f6\u95f4\nif ($this-&gt;_redisHandle-&gt;checkExistsDay($existsDay)) {\n$likeKey = 'loginLog_*';\n$keyList = $this-&gt;_redisHandle-&gt;getKeys($likeKey);\n\nif (!empty($keyList)) {\nforeach ($keyList as $keyVal) {\n\nif ($this-&gt;_redisHandle-&gt;checkLoginLogKey($keyVal)) {\n$keyTime     = $this-&gt;_redisHandle-&gt;getLoginLogKeyInfo($keyVal, 'time');\n$thisMonth    = date('Y-m');\n$beforeMonth   = date('Y-m', strtotime('-1 month'));\n\n\/\/ \u9a8c\u8bc1\u662f\u5426\u9700\u8981\u8fdb\u884c\u540c\u6b65\uff1a\n\/\/ 1. \u5f53\u524d\u65e5\u671f &gt;= 8\u53f7\uff0c\u5bf9\u672c\u6708\u6240\u6709\u8bb0\u5f55\u8fdb\u884c\u540c\u6b65\uff0c\u4e0d\u5bf9\u672c\u6708\u4e4b\u524d\u7684\u8bb0\u5f55\u8fdb\u884c\u540c\u6b65\n\/\/ 2. \u5f53\u524d\u65e5\u671f = 8) {\n\n\/\/ \u53ea\u540c\u6b65\u672c\u6708\u6570\u636e\nif ($thisMonth == $keyTime) {\n$this-&gt;redis2db($keyVal);\n}\n} else {\n\n\/\/ \u540c\u6b65\u672c\u6708\u6216\u672c\u6708\u524d\u4e00\u4e2a\u6708\u6570\u636e\nif ($thisMonth == $keyTime || $beforeMonth == $keyTime) {\n$this-&gt;redis2db($keyVal);\n}\n}\n\n\/\/ \u9a8c\u8bc1\u662f\u5426\u8fc7\u671f\n$existsSecond = $existsDay * 24 * 60 * 60;\nif (strtotime($keyTime) + $existsSecond _redisHandle-&gt;getLoginLogBitMap($keyVal);\nLog::INFO('\u5220\u9664\u8fc7\u671f\u6570\u636e[' . $keyVal . ']\uff1a' . $bitMap);\n$this-&gt;_redisHandle-&gt;delLoginLog($keyVal);\n}\n}\n}\nreturn 'success';\n}\nreturn 'null';\n}\nreturn 'fail';\n}\n\n\/**\n* \u5c06\u8bb0\u5f55\u540c\u6b65\u5230\u6570\u636e\u5e93\n* @param string $key \u8bb0\u5f55Key\n* @return boolean\n*\/\nprivate function redis2db($key)\n{\nif ($this-&gt;_redisHandle-&gt;checkLoginLogKey($key) &amp;&amp; $this-&gt;_redisHandle-&gt;checkRedisLogExists($key)) {\n$time = $this-&gt;_redisHandle-&gt;getLoginLogKeyInfo($key, 'time');\n$data['id']   = Tools::generateId();\n$data['user_id'] = $this-&gt;_redisHandle-&gt;getLoginLogKeyInfo($key, 'uid');\n$data['type']  = $this-&gt;_redisHandle-&gt;getLoginLogKeyInfo($key, 'type');\n$data['year']  = date('Y', strtotime($time));\n$data['month']  = date('n', strtotime($time));\n$data['bit_log'] = $this-&gt;_redisHandle-&gt;getLoginLogBitMap($key);\nreturn $this-&gt;_dbHandle-&gt;redis2db($data);\n}\nreturn false;\n}\n}<\/pre>\n<p>4.2 LoginLogCommon.class.php<\/p>\n<pre>\n_loginLog = $loginLog;\n$this-&gt;_redis  = RedisData::getRedis();\n}\n\n\/**\n* \u9a8c\u8bc1\u7528\u6237\u7c7b\u578b\n* @param string $type \u7528\u6237\u7c7b\u578b\n* @return boolean\n*\/\nprotected function checkType($type)\n{\nif (in_array($type, array(\nStatus::LOGIN_LOG_TYPE_ADMIN,\nStatus::LOGIN_LOG_TYPE_CARRIER,\nStatus::LOGIN_LOG_TYPE_DRIVER,\nStatus::LOGIN_LOG_TYPE_OFFICE,\nStatus::LOGIN_LOG_TYPE_CLIENT,\n))) {\nreturn true;\n}\n$this-&gt;_loginLog-&gt;setError('\u672a\u5b9a\u4e49\u7684\u65e5\u5fd7\u7c7b\u578b\uff1a' . $type);\nreturn false;\n}\n\n\/**\n* \u9a8c\u8bc1\u552f\u4e00\u6807\u8bc6\n* @param string $uid\n* @return boolean\n*\/\nprotected function checkUid($uid)\n{\nif (is_numeric($uid) &amp;&amp; $uid &gt; 0) {\nreturn true;\n}\n$this-&gt;_loginLog-&gt;setError('\u552f\u4e00\u6807\u8bc6\u975e\u6cd5\uff1a' . $uid);\nreturn false;\n}\n\n\/**\n* \u9a8c\u8bc1\u65f6\u95f4\u6233\n* @param string $time\n* @return boolean\n*\/\nprotected function checkTime($time)\n{\nif (is_numeric($time) &amp;&amp; $time &gt; 0) {\nreturn true;\n}\n$this-&gt;_loginLog-&gt;setError('\u65f6\u95f4\u6233\u975e\u6cd5\uff1a' . $time);\nreturn false;\n}\n\n\/**\n* \u9a8c\u8bc1\u65f6\u95f4\u662f\u5426\u5728\u5f53\u6708\u4e2d\n* @param string $time\n* @return boolean\n*\/\nprotected function checkTimeWhetherThisMonth($time)\n{\nif ($this-&gt;checkTime($time) &amp;&amp; $time &gt; strtotime(date('Y-m')) &amp;&amp; $time _loginLog-&gt;setError('\u65f6\u95f4\u672a\u5728\u5f53\u524d\u6708\u4efd\u4e2d\uff1a' . $time);\nreturn false;\n}\n\n\/**\n* \u9a8c\u8bc1\u65f6\u95f4\u662f\u5426\u8d85\u8fc7\u5f53\u524d\u65f6\u95f4\n* @param string $time\n* @return boolean\n*\/\nprotected function checkTimeWhetherFutureTime($time)\n{\nif ($this-&gt;checkTime($time) &amp;&amp; $time checkTime($startTime) &amp;&amp;\n$this-&gt;checkTime($endTime) &amp;&amp;\n$startTime _loginLog-&gt;setError('\u65f6\u95f4\u8303\u56f4\u975e\u6cd5\uff1a' . $startTime . '-' . $endTime);\nreturn false;\n}\n\n\/**\n* \u9a8c\u8bc1\u65f6\u95f4\u662f\u5426\u5728\u6307\u5b9a\u8303\u56f4\u5185\n* @param string $time   \u9700\u8981\u68c0\u67e5\u7684\u65f6\u95f4\n* @param string $startTime \u5f00\u59cb\u65f6\u95f4\n* @param string $endTime  \u7ed3\u675f\u65f6\u95f4\n* @return boolean\n*\/\nprotected function checkTimeWithinTimeRange($time, $startTime, $endTime)\n{\nif ($this-&gt;checkTime($time) &amp;&amp;\n$this-&gt;checkTimeRange($startTime, $endTime) &amp;&amp;\n$startTime _loginLog-&gt;setError('\u8bf7\u6c42\u65f6\u95f4\u672a\u5728\u65f6\u95f4\u8303\u56f4\u5185\uff1a' . $time . '-' . $startTime . '-' . $endTime);\nreturn false;\n}\n\n\/**\n* \u9a8c\u8bc1Redis\u65e5\u5fd7\u8bb0\u5f55\u6807\u51c6Key\n* @param string $key\n* @return boolean\n*\/\nprotected function checkLoginLogKey($key)\n{\n$pattern = '\/^loginLog_\\d{4}-\\d{1,2}_\\S+_\\d+$\/';\n$result = preg_match($pattern, $key, $match);\nif ($result &gt; 0) {\nreturn true;\n}\n$this-&gt;_loginLog-&gt;setError('RedisKey\u975e\u6cd5\uff1a' . $key);\nreturn false;\n}\n\n\/**\n* \u83b7\u53d6\u6708\u4efd\u4e2d\u6709\u591a\u5c11\u5929\n* @param int $time \u65f6\u95f4\u6233\n* @return int\n*\/\nprotected function getDaysInMonth($time)\n{\nreturn date('t', $time);\n}\n\n\/**\n* \u5bf9\u6ca1\u6709\u524d\u5bfc\u96f6\u7684\u6708\u4efd\u6216\u65e5\u8bbe\u7f6e\u524d\u5bfc\u96f6\n* @param int $num \u6708\u4efd\u6216\u65e5\n* @return string\n*\/\nprotected function setDateLeadingZero($num)\n{\nif (is_numeric($num) &amp;&amp; strlen($num)  1 ? $num : '0' . $num);\n}\nreturn $num;\n}\n\n\/**\n* \u9a8c\u8bc1\u8fc7\u671f\u65f6\u95f4\n* @param int   $existsDay \u4e00\u6761\u8bb0\u5f55\u5728Redis\u4e2d\u8fc7\u671f\u65f6\u95f4\uff0c\u5355\u4f4d\uff1a\u5929\uff0c\u5fc5\u987b\u5927\u4e8e31\n* @return boolean\n*\/\nprotected function checkExistsDay($existsDay)\n{\nif (is_numeric($existsDay) &amp;&amp; ctype_digit(strval($existsDay)) &amp;&amp; $existsDay &gt; 31) {\nreturn true;\n}\n$this-&gt;_loginLog-&gt;setError('\u8fc7\u671f\u65f6\u95f4\u975e\u6cd5\uff1a' . $existsDay);\nreturn false;\n}\n\n\/**\n* \u83b7\u53d6\u5f00\u59cb\u65e5\u671f\u8fb9\u754c\n* @param int $time   \u9700\u8981\u5224\u65ad\u7684\u65f6\u95f4\u6233\n* @param int $startTime \u8d77\u59cb\u65f6\u95f4\n* @return int\n*\/\nprotected function getStartTimeBorder($time, $startTime)\n{\n$initDay = 1;\nif ($this-&gt;checkTime($time) &amp;&amp; $this-&gt;checkTime($startTime) &amp;&amp;\ndate('Y-m', $time) === date('Y-m', $startTime) &amp;&amp; false !== date('Y-m', $time)) {\n$initDay = date('j', $startTime);\n}\nreturn $initDay;\n}\n\n\/**\n* \u83b7\u53d6\u7ed3\u675f\u65e5\u671f\u8fb9\u754c\n* @param int $time   \u9700\u8981\u5224\u65ad\u7684\u65f6\u95f4\u6233\n* @param int $endTime  \u7ed3\u675f\u65f6\u95f4\n* @return int\n*\/\nprotected function getEndTimeBorder($time, $endTime)\n{\n$border = $this-&gt;getDaysInMonth($time);\nif ($this-&gt;checkTime($time) &amp;&amp; $this-&gt;checkTime($endTime) &amp;&amp;\ndate('Y-m', $time) === date('Y-m', $endTime) &amp;&amp; false !== date('Y-m', $time)) {\n$border = date('j', $endTime);\n}\nreturn $border;\n}\n}<\/pre>\n<p>4.3 LoginLogDBHandle.class.php<\/p>\n<pre>\n array(\n*     'count' =&gt; n,                 \/\/ \u6709\u6548\u767b\u5f55\u6b21\u6570\uff0c\u6bcf\u5929\u91cd\u590d\u767b\u5f55\u7b97\u4e00\u6b21\n*     'list' =&gt; array('2017-10-1', '2017-10-15' ...) \/\/ \u6709\u6548\u767b\u5f55\u65e5\u671f\n*   ),\n*   'notLog' =&gt; array(\n*     'count' =&gt; n,                 \/\/ \u672a\u767b\u5f55\u6b21\u6570\n*     'list' =&gt; array('2017-10-1', '2017-10-15' ...) \/\/ \u672a\u767b\u5f55\u65e5\u671f\n*   )\n* )\n*\/\npublic function getUserTimeRangeLogin($type, $uid, $time, $startTime, $endTime)\n{\n$hasCount = 0;    \/\/ \u6709\u6548\u767b\u5f55\u6b21\u6570\n$notCount = 0;    \/\/ \u672a\u767b\u5f55\u6b21\u6570\n$hasList = array(); \/\/ \u6709\u6548\u767b\u5f55\u65e5\u671f\n$notList = array(); \/\/ \u672a\u767b\u5f55\u65e5\u671f\n\nif ($this-&gt;checkType($type) &amp;&amp; $this-&gt;checkUid($uid) &amp;&amp; $this-&gt;checkTimeWithinTimeRange($time, $startTime, $endTime)) {\n\n$timeYM = date('Y-m', $time);\n\n\/\/ \u8bbe\u7f6e\u5f00\u59cb\u65f6\u95f4\n$initDay = $this-&gt;getStartTimeBorder($time, $startTime);\n\n\/\/ \u8bbe\u7f6e\u7ed3\u675f\u65f6\u95f4\n$border = $this-&gt;getEndTimeBorder($time, $endTime);\n\n$bitMap = $this-&gt;getBitMapFind($type, $uid, date('Y', $time), date('n', $time));\nfor ($i = $initDay; $i setDateLeadingZero($i);\n} else {\n$notCount++;\n$notList[] = $timeYM . '-' . $this-&gt;setDateLeadingZero($i);\n}\n} else {\n$notCount++;\n$notList[] = $timeYM . '-' . $this-&gt;setDateLeadingZero($i);\n}\n}\n}\n\nreturn array(\n'hasLog' =&gt; array(\n'count' =&gt; $hasCount,\n'list' =&gt; $hasList\n),\n'notLog' =&gt; array(\n'count' =&gt; $notCount,\n'list' =&gt; $notList\n)\n);\n}\n\n\/**\n* \u4ece\u6570\u636e\u5e93\u83b7\u53d6\u7528\u6237\u67d0\u6708\u65e5\u5fd7\u4f4d\u56fe\n* @param string $type \u7528\u6237\u7c7b\u578b\n* @param int   $uid  \u552f\u4e00\u6807\u8bc6\uff08\u7528\u6237ID\uff09\n* @param int   $year \u5e74Y\n* @param int   $month \u6708n\n* @return string\n*\/\nprivate function getBitMapFind($type, $uid, $year, $month)\n{\n$model = D('Home\/StatLoginLog');\n$map['type']  = array('EQ', $type);\n$map['user_id'] = array('EQ', $uid);\n$map['year']  = array('EQ', $year);\n$map['month']  = array('EQ', $month);\n\n$result = $model-&gt;field('bit_log')-&gt;where($map)-&gt;find();\nif (false !== $result &amp;&amp; isset($result['bit_log']) &amp;&amp; !empty($result['bit_log'])) {\nreturn $result['bit_log'];\n}\nreturn '';\n}\n\n\/**\n* \u4ece\u6570\u636e\u5e93\u4e2d\u5224\u65ad\u7528\u6237\u5728\u67d0\u4e00\u5929\u662f\u5426\u767b\u5f55\u8fc7\n* @param string $type \u7528\u6237\u7c7b\u578b\n* @param int   $uid  \u552f\u4e00\u6807\u8bc6\uff08\u7528\u6237ID\uff09\n* @param int   $time \u65f6\u95f4\u6233\n* @return boolean \u53c2\u6570\u9519\u8bef\u6216\u672a\u767b\u5f55\u8fc7\u8fd4\u56defalse\uff0c\u767b\u5f55\u8fc7\u8fd4\u56detrue\n*\/\npublic function dateWhetherLogin($type, $uid, $time)\n{\nif ($this-&gt;checkType($type) &amp;&amp; $this-&gt;checkUid($uid) &amp;&amp; $this-&gt;checkTime($time)) {\n\n$timeInfo = getdate($time);\n$bitMap = $this-&gt;getBitMapFind($type, $uid, $timeInfo['year'], $timeInfo['mon']);\nif (!empty($bitMap)) {\nif ($bitMap[$timeInfo['mday']-1] == '1') {\nreturn true;\n}\n}\n}\nreturn false;\n}\n\n\/**\n* \u4ece\u6570\u636e\u5e93\u4e2d\u5224\u65ad\u7528\u6237\u5728\u67d0\u6708\u662f\u5426\u767b\u5f55\u8fc7\n* @param string $type \u7528\u6237\u7c7b\u578b\n* @param int   $uid  \u552f\u4e00\u6807\u8bc6\uff08\u7528\u6237ID\uff09\n* @param int   $time \u65f6\u95f4\u6233\n* @return boolean \u53c2\u6570\u9519\u8bef\u6216\u672a\u767b\u5f55\u8fc7\u8fd4\u56defalse\uff0c\u767b\u5f55\u8fc7\u8fd4\u56detrue\n*\/\npublic function dateMonthWhetherLogin($type, $uid, $time)\n{\nif ($this-&gt;checkType($type) &amp;&amp; $this-&gt;checkUid($uid) &amp;&amp; $this-&gt;checkTime($time)) {\n\n$timeInfo = getdate($time);\n$userArr = $this-&gt;getMonthLoginSuccessUser($timeInfo['year'], $timeInfo['mon'], $type);\nif (!empty($userArr)) {\nif (in_array($uid, $userArr)) {\nreturn true;\n}\n}\n}\nreturn false;\n}\n\n\/**\n* \u83b7\u53d6\u67d0\u6708\u6240\u6709\u6709\u6548\u767b\u5f55\u8fc7\u7684\u7528\u6237ID\n* @param int   $year \u5e74Y\n* @param int   $month \u6708n\n* @param string $type \u7528\u6237\u7c7b\u578b\uff0c\u4e3a\u7a7a\u65f6\u83b7\u53d6\u5168\u90e8\u7c7b\u578b\n* @return array\n*\/\npublic function getMonthLoginSuccessUser($year, $month, $type = '')\n{\n$data = array();\nif (is_numeric($year) &amp;&amp; is_numeric($month)) {\n$model = D('Home\/StatLoginLog');\n$map['year']  = array('EQ', $year);\n$map['month']  = array('EQ', $month);\n$map['bit_log'] = array('LIKE', '%1%');\nif ($type != '' &amp;&amp; $this-&gt;checkType($type)) {\n$map['type']  = array('EQ', $type);\n}\n$result = $model-&gt;field('user_id')-&gt;where($map)-&gt;select();\nif (false !== $result &amp;&amp; count($result) &gt; 0) {\nforeach ($result as $val) {\nif (isset($val['user_id'])) {\n$data[] = $val['user_id'];\n}\n}\n}\n}\nreturn $data;\n}\n\n\/**\n* \u4ece\u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u67d0\u6708\u6240\u6709\u8bb0\u5f55\u5728\u6307\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u7684\u7528\u6237ID\n* @param int   $time   \u67e5\u8be2\u7684\u65f6\u95f4\u6233\n* @param int   $startTime \u5f00\u59cb\u65f6\u95f4\u6233\n* @param int   $endTime  \u7ed3\u675f\u65f6\u95f4\u6233\n* @param string $type \u7528\u6237\u7c7b\u578b\uff0c\u4e3a\u7a7a\u65f6\u83b7\u53d6\u5168\u90e8\u7c7b\u578b\n* @return array\n*\/\npublic function getTimeRangeLoginSuccessUser($time, $startTime, $endTime, $type = '')\n{\n$data = array();\nif ($this-&gt;checkTimeWithinTimeRange($time, $startTime, $endTime)) {\n\n$timeInfo = getdate($time);\n\n\/\/ \u83b7\u53d6\u6ee1\u8db3\u65f6\u95f4\u6761\u4ef6\u7684\u8bb0\u5f55\n$model = D('Home\/StatLoginLog');\n$map['year']  = array('EQ', $timeInfo['year']);\n$map['month']  = array('EQ', $timeInfo['mon']);\nif ($type != '' &amp;&amp; $this-&gt;checkType($type)) {\n$map['type']  = array('EQ', $type);\n}\n\n$result = $model-&gt;where($map)-&gt;select();\nif (false !== $result &amp;&amp; count($result) &gt; 0) {\n\n\/\/ \u8bbe\u7f6e\u5f00\u59cb\u65f6\u95f4\n$initDay = $this-&gt;getStartTimeBorder($time, $startTime);\n\n\/\/ \u8bbe\u7f6e\u7ed3\u675f\u65f6\u95f4\n$border = $this-&gt;getEndTimeBorder($time, $endTime);\n\nforeach ($result as $val) {\n\n$bitMap = $val['bit_log'];\nfor ($i = $initDay; $i where($map)-&gt;count();\nif (false !== $count &amp;&amp; $count &gt; 0) {\n\n\/\/ \u5b58\u5728\u8bb0\u5f55\u8fdb\u884c\u66f4\u65b0\n$saveData['bit_log'] = $data['bit_log'];\n\nif (!$model-&gt;create($saveData, Model::MODEL_UPDATE)) {\n\n$this-&gt;_loginLog-&gt;setError('\u540c\u6b65\u767b\u5f55\u65e5\u5fd7-\u66f4\u65b0\u8bb0\u5f55\uff0c\u521b\u5efa\u6570\u636e\u5bf9\u8c61\u5931\u8d25\uff1a' . $model-&gt;getError());\nlogger()-&gt;error('\u540c\u6b65\u767b\u5f55\u65e5\u5fd7-\u66f4\u65b0\u8bb0\u5f55\uff0c\u521b\u5efa\u6570\u636e\u5bf9\u8c61\u5931\u8d25\uff1a' . $model-&gt;getError());\nreturn false;\n} else {\n\n$result = $model-&gt;where($map)-&gt;save();\n\nif (false !== $result) {\nreturn true;\n} else {\n$this-&gt;_loginLog-&gt;setError('\u540c\u6b65\u767b\u5f55\u65e5\u5fd7-\u66f4\u65b0\u8bb0\u5f55\uff0c\u66f4\u65b0\u6570\u636e\u5931\u8d25\uff1a' . json_encode($data));\nlogger()-&gt;error('\u540c\u6b65\u767b\u5f55\u65e5\u5fd7-\u66f4\u65b0\u8bb0\u5f55\uff0c\u66f4\u65b0\u6570\u636e\u5931\u8d25\uff1a' . json_encode($data));\nreturn false;\n}\n}\n} else {\n\n\/\/ \u4e0d\u5b58\u5728\u8bb0\u5f55\u63d2\u5165\u4e00\u6761\u65b0\u7684\u8bb0\u5f55\nif (!$model-&gt;create($data, Model::MODEL_INSERT)) {\n\n$this-&gt;_loginLog-&gt;setError('\u540c\u6b65\u767b\u5f55\u65e5\u5fd7-\u63d2\u5165\u8bb0\u5f55\uff0c\u521b\u5efa\u6570\u636e\u5bf9\u8c61\u5931\u8d25\uff1a' . $model-&gt;getError());\nlogger()-&gt;error('\u540c\u6b65\u767b\u5f55\u65e5\u5fd7-\u63d2\u5165\u8bb0\u5f55\uff0c\u521b\u5efa\u6570\u636e\u5bf9\u8c61\u5931\u8d25\uff1a' . $model-&gt;getError());\nreturn false;\n} else {\n\n$result = $model-&gt;add();\n\nif (false !== $result) {\nreturn true;\n} else {\n$this-&gt;_loginLog-&gt;setError('\u540c\u6b65\u767b\u5f55\u65e5\u5fd7-\u63d2\u5165\u8bb0\u5f55\uff0c\u63d2\u5165\u6570\u636e\u5931\u8d25\uff1a' . json_encode($data));\nlogger()-&gt;error('\u540c\u6b65\u767b\u5f55\u65e5\u5fd7-\u63d2\u5165\u8bb0\u5f55\uff0c\u63d2\u5165\u6570\u636e\u5931\u8d25\uff1a' . json_encode($data));\nreturn false;\n}\n}\n}\n}\n}<\/pre>\n<p>4.4 LoginLogRedisHandle.class.php<\/p>\n<pre>\ncheckLoginLogKey($key) &amp;&amp; $this-&gt;checkTimeWhetherThisMonth($time)) {\n\n\/\/ \u5224\u65ad\u7528\u6237\u5f53\u5929\u662f\u5426\u5df2\u7ecf\u767b\u5f55\u8fc7\n$whetherLoginResult = $this-&gt;dateWhetherLogin($key, $time);\nif (!$whetherLoginResult) {\n\n\/\/ \u5f53\u5929\u672a\u767b\u5f55\uff0c\u8bb0\u5f55\u767b\u5f55\n$this-&gt;_redis-&gt;setBit($key, date('d', $time), 1);\n}\nreturn true;\n}\nreturn false;\n}\n\n\/**\n* \u4eceRedis\u4e2d\u5224\u65ad\u7528\u6237\u5728\u67d0\u4e00\u5929\u662f\u5426\u767b\u5f55\u8fc7\n* @param string $key \u65e5\u5fd7\u8bb0\u5f55Key\n* @param int  $time \u65f6\u95f4\u6233\n* @return boolean \u53c2\u6570\u9519\u8bef\u6216\u672a\u767b\u5f55\u8fc7\u8fd4\u56defalse\uff0c\u767b\u5f55\u8fc7\u8fd4\u56detrue\n*\/\npublic function dateWhetherLogin($key, $time)\n{\nif ($this-&gt;checkLoginLogKey($key) &amp;&amp; $this-&gt;checkTime($time)) {\n$result = $this-&gt;_redis-&gt;getBit($key, date('d', $time));\nif ($result === 1) {\nreturn true;\n}\n}\nreturn false;\n}\n\n\/**\n* \u4eceRedis\u4e2d\u5224\u65ad\u7528\u6237\u5728\u67d0\u6708\u662f\u5426\u767b\u5f55\u8fc7\n* @param string $key \u65e5\u5fd7\u8bb0\u5f55Key\n* @return boolean \u53c2\u6570\u9519\u8bef\u6216\u672a\u767b\u5f55\u8fc7\u8fd4\u56defalse\uff0c\u767b\u5f55\u8fc7\u8fd4\u56detrue\n*\/\npublic function dateMonthWhetherLogin($key)\n{\nif ($this-&gt;checkLoginLogKey($key)) {\n$result = $this-&gt;_redis-&gt;bitCount($key);\nif ($result &gt; 0) {\nreturn true;\n}\n}\nreturn false;\n}\n\n\/**\n* \u5224\u65ad\u67d0\u6708\u767b\u5f55\u8bb0\u5f55\u5728Redis\u4e2d\u662f\u5426\u5b58\u5728\n* @param string $key \u65e5\u5fd7\u8bb0\u5f55Key\n* @return boolean\n*\/\npublic function checkRedisLogExists($key)\n{\nif ($this-&gt;checkLoginLogKey($key)) {\nif ($this-&gt;_redis-&gt;exists($key)) {\nreturn true;\n}\n}\nreturn false;\n}\n\n\/**\n* \u4eceRedis\u4e2d\u83b7\u53d6\u7528\u6237\u67d0\u6708\u8bb0\u5f55\u5728\u6307\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u7684\u7528\u6237\u4fe1\u606f\n* @param string $key    \u65e5\u5fd7\u8bb0\u5f55Key\n* @param int   $startTime \u5f00\u59cb\u65f6\u95f4\u6233\n* @param int   $endTime  \u7ed3\u675f\u65f6\u95f4\u6233\n* @return array\n* array(\n*   'hasLog' =&gt; array(\n*     'count' =&gt; n,                 \/\/ \u6709\u6548\u767b\u5f55\u6b21\u6570\uff0c\u6bcf\u5929\u91cd\u590d\u767b\u5f55\u7b97\u4e00\u6b21\n*     'list' =&gt; array('2017-10-1', '2017-10-15' ...) \/\/ \u6709\u6548\u767b\u5f55\u65e5\u671f\n*   ),\n*   'notLog' =&gt; array(\n*     'count' =&gt; n,                 \/\/ \u672a\u767b\u5f55\u6b21\u6570\n*     'list' =&gt; array('2017-10-1', '2017-10-15' ...) \/\/ \u672a\u767b\u5f55\u65e5\u671f\n*   )\n* )\n*\/\npublic function getUserTimeRangeLogin($key, $startTime, $endTime)\n{\n$hasCount = 0;    \/\/ \u6709\u6548\u767b\u5f55\u6b21\u6570\n$notCount = 0;    \/\/ \u672a\u767b\u5f55\u6b21\u6570\n$hasList = array(); \/\/ \u6709\u6548\u767b\u5f55\u65e5\u671f\n$notList = array(); \/\/ \u672a\u767b\u5f55\u65e5\u671f\n\nif ($this-&gt;checkLoginLogKey($key) &amp;&amp; $this-&gt;checkTimeRange($startTime, $endTime) &amp;&amp; $this-&gt;checkRedisLogExists($key)) {\n\n$keyTime = $this-&gt;getLoginLogKeyInfo($key, 'time');\n$keyTime = strtotime($keyTime);\n$timeYM = date('Y-m', $keyTime);\n\n\/\/ \u8bbe\u7f6e\u5f00\u59cb\u65f6\u95f4\n$initDay = $this-&gt;getStartTimeBorder($keyTime, $startTime);\n\n\/\/ \u8bbe\u7f6e\u7ed3\u675f\u65f6\u95f4\n$border = $this-&gt;getEndTimeBorder($keyTime, $endTime);\n\nfor ($i = $initDay; $i _redis-&gt;getBit($key, $i);\nif ($result === 1) {\n$hasCount++;\n$hasList[] = $timeYM . '-' . $this-&gt;setDateLeadingZero($i);\n} else {\n$notCount++;\n$notList[] = $timeYM . '-' . $this-&gt;setDateLeadingZero($i);\n}\n}\n}\n\nreturn array(\n'hasLog' =&gt; array(\n'count' =&gt; $hasCount,\n'list' =&gt; $hasList\n),\n'notLog' =&gt; array(\n'count' =&gt; $notCount,\n'list' =&gt; $notList\n)\n);\n}\n\n\/**\n* \u9762\u5411\u7528\u6237\uff1a\u83b7\u53d6\u65f6\u95f4\u8303\u56f4\u5185\u53ef\u80fd\u9700\u8981\u7684Key\n* @param string $type   \u7528\u6237\u7c7b\u578b\n* @param int  $uid    \u552f\u4e00\u6807\u8bc6\uff08\u7528\u6237ID\uff09\n* @param string $startTime \u5f00\u59cb\u65f6\u95f4\n* @param string $endTime  \u7ed3\u675f\u65f6\u95f4\n* @return array\n*\/\npublic function getTimeRangeRedisKey($type, $uid, $startTime, $endTime)\n{\n$list = array();\n\nif ($this-&gt;checkType($type) &amp;&amp; $this-&gt;checkUid($uid) &amp;&amp; $this-&gt;checkTimeRange($startTime, $endTime)) {\n\n$data = $this-&gt;getSpecifyUserKeyHandle($type, $uid, $startTime);\nif (!empty($data)) { $list[] = $data; }\n\n$temYM = strtotime('+1 month', strtotime(date('Y-m', $startTime)));\n\nwhile ($temYM getSpecifyUserKeyHandle($type, $uid, $temYM);\nif (!empty($data)) { $list[] = $data; }\n\n$temYM = strtotime('+1 month', $temYM);\n}\n}\nreturn $list;\n}\nprivate function getSpecifyUserKeyHandle($type, $uid, $time)\n{\n$data = array();\n$key = $this-&gt;getLoginLogKey($type, $uid, $time);\nif ($this-&gt;checkLoginLogKey($key)) {\n$data = array(\n'key' =&gt; $key,\n'time' =&gt; $time\n);\n}\nreturn $data;\n}\n\n\/**\n* \u9762\u5411\u7c7b\u578b\uff1a\u83b7\u53d6\u65f6\u95f4\u8303\u56f4\u5185\u53ef\u80fd\u9700\u8981\u7684Key\n* @param string $type   \u7528\u6237\u7c7b\u578b\n* @param string $startTime \u5f00\u59cb\u65f6\u95f4\n* @param string $endTime  \u7ed3\u675f\u65f6\u95f4\n* @return array\n*\/\npublic function getSpecifyTypeTimeRangeRedisKey($type, $startTime, $endTime)\n{\n$list = array();\n\nif ($this-&gt;checkType($type) &amp;&amp; $this-&gt;checkTimeRange($startTime, $endTime)) {\n\n$data = $this-&gt;getSpecifyTypeKeyHandle($type, $startTime);\nif (!empty($data)) { $list[] = $data; }\n\n$temYM = strtotime('+1 month', strtotime(date('Y-m', $startTime)));\n\nwhile ($temYM getSpecifyTypeKeyHandle($type, $temYM);\nif (!empty($data)) { $list[] = $data; }\n\n$temYM = strtotime('+1 month', $temYM);\n}\n}\nreturn $list;\n}\nprivate function getSpecifyTypeKeyHandle($type, $time)\n{\n$data = array();\n$temUid = '11111111';\n\n$key = $this-&gt;getLoginLogKey($type, $temUid, $time);\nif ($this-&gt;checkLoginLogKey($key)) {\n$arr = explode('_', $key);\n$arr[count($arr)-1] = '*';\n$key = implode('_', $arr);\n$data = array(\n'key' =&gt; $key,\n'time' =&gt; $time\n);\n}\nreturn $data;\n}\n\n\/**\n* \u9762\u5411\u5168\u90e8\uff1a\u83b7\u53d6\u65f6\u95f4\u8303\u56f4\u5185\u53ef\u80fd\u9700\u8981\u7684Key\n* @param string $startTime \u5f00\u59cb\u65f6\u95f4\n* @param string $endTime  \u7ed3\u675f\u65f6\u95f4\n* @return array\n*\/\npublic function getSpecifyAllTimeRangeRedisKey($startTime, $endTime)\n{\n$list = array();\n\nif ($this-&gt;checkTimeRange($startTime, $endTime)) {\n\n$data = $this-&gt;getSpecifyAllKeyHandle($startTime);\nif (!empty($data)) { $list[] = $data; }\n\n$temYM = strtotime('+1 month', strtotime(date('Y-m', $startTime)));\n\nwhile ($temYM getSpecifyAllKeyHandle($temYM);\nif (!empty($data)) { $list[] = $data; }\n\n$temYM = strtotime('+1 month', $temYM);\n}\n}\nreturn $list;\n}\nprivate function getSpecifyAllKeyHandle($time)\n{\n$data = array();\n$temUid = '11111111';\n$temType = 'office';\n\n$key = $this-&gt;getLoginLogKey($temType, $temUid, $time);\nif ($this-&gt;checkLoginLogKey($key)) {\n$arr = explode('_', $key);\narray_pop($arr);\n$arr[count($arr)-1] = '*';\n$key = implode('_', $arr);\n$data = array(\n'key' =&gt; $key,\n'time' =&gt; $time\n);\n}\nreturn $data;\n}\n\n\/**\n* \u4eceRedis\u4e2d\u67e5\u8be2\u6ee1\u8db3\u6761\u4ef6\u7684Key\n* @param string $key \u67e5\u8be2\u7684Key\n* @return array\n*\/\npublic function getKeys($key)\n{\nreturn $this-&gt;_redis-&gt;keys($key);\n}\n\n\/**\n* \u4eceRedis\u4e2d\u5220\u9664\u8bb0\u5f55\n* @param string $key \u8bb0\u5f55\u7684Key\n* @return boolean\n*\/\npublic function delLoginLog($key)\n{\nreturn $this-&gt;_redis-&gt;del($key);\n}\n\n\/**\n* \u83b7\u53d6\u65e5\u5fd7\u6807\u51c6Key\uff1a\u524d\u7f00_\u5e74-\u6708_\u7528\u6237\u7c7b\u578b_\u552f\u4e00\u6807\u8bc6\n* @param string $type \u7528\u6237\u7c7b\u578b\n* @param int  $uid \u552f\u4e00\u6807\u8bc6\uff08\u7528\u6237ID\uff09\n* @param int  $time \u65f6\u95f4\u6233\n* @return string\n*\/\npublic function getLoginLogKey($type, $uid, $time)\n{\nif ($this-&gt;checkType($type) &amp;&amp; $this-&gt;checkUid($uid) &amp;&amp; $this-&gt;checkTime($time)) {\nreturn 'loginLog_' . date('Y-m', $time) . '_' . $type . '_' . $uid;\n}\nreturn '';\n}\n\n\/**\n* \u83b7\u53d6\u65e5\u5fd7\u6807\u51c6Key\u4e0a\u4fe1\u606f\n* @param string $key  key\n* @param string $field \u9700\u8981\u7684\u53c2\u6570 time,type,uid\n* @return mixed \u8fd4\u56de\u5bf9\u5e94\u7684\u503c\uff0c\u6ca1\u6709\u8fd4\u56denull\n*\/\npublic function getLoginLogKeyInfo($key, $field)\n{\n$param = array();\nif ($this-&gt;checkLoginLogKey($key)) {\n$arr = explode('_', $key);\n$param['time'] = $arr[1];\n$param['type'] = $arr[2];\n$param['uid'] = $arr[3];\n}\nreturn $param[$field];\n}\n\n\/**\n* \u83b7\u53d6Key\u8bb0\u5f55\u7684\u767b\u5f55\u4f4d\u56fe\n* @param string $key key\n* @return string\n*\/\npublic function getLoginLogBitMap($key)\n{\n$bitMap = '';\nif ($this-&gt;checkLoginLogKey($key)) {\n$time = $this-&gt;getLoginLogKeyInfo($key, 'time');\n$maxDay = $this-&gt;getDaysInMonth(strtotime($time));\nfor ($i = 1; $i _redis-&gt;getBit($key, $i);\n}\n}\nreturn $bitMap;\n}\n\n\/**\n* \u9a8c\u8bc1\u65e5\u5fd7\u6807\u51c6Key\n* @param string $key\n* @return boolean\n*\/\npublic function checkLoginLogKey($key)\n{\nreturn parent::checkLoginLogKey($key);\n}\n\n\/**\n* \u9a8c\u8bc1\u5f00\u59cb\/\u7ed3\u675f\u65f6\u95f4\n* @param string $startTime \u5f00\u59cb\u65f6\u95f4\n* @param string $endTime  \u7ed3\u675f\u65f6\u95f4\n* @return boolean\n*\/\npublic function checkTimeRange($startTime, $endTime)\n{\nreturn parent::checkTimeRange($startTime, $endTime);\n}\n\n\/**\n* \u9a8c\u8bc1\u7528\u6237\u7c7b\u578b\n* @param string $type\n* @return boolean\n*\/\npublic function checkType($type)\n{\nreturn parent::checkType($type);\n}\n\n\/**\n* \u9a8c\u8bc1\u8fc7\u671f\u65f6\u95f4\n* @param int $existsDay \u4e00\u6761\u8bb0\u5f55\u5728Redis\u4e2d\u8fc7\u671f\u65f6\u95f4\uff0c\u5355\u4f4d\uff1a\u5929\uff0c\u5fc5\u987b\u5927\u4e8e31\n* @return boolean\n*\/\npublic function checkExistsDay($existsDay)\n{\nreturn parent::checkExistsDay($existsDay);\n}\n}<\/pre>\n<p>5. \u53c2\u8003\u8d44\u6599<\/p>\n<p>\u3000\u3000<\/p>\n<p>\u3000\u3000<\/p>\n<p>\u3000\u3000<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u4e8eRedis\u4f4d\u56fe\u5b9e\u73b0\u7cfb\u7edf\u7528\u6237\u767b&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201258","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201258"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201258\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}