{"id":201575,"date":"2025-05-10T10:24:09","date_gmt":"2025-05-10T02:24:09","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201575\/"},"modified":"2025-05-10T10:24:09","modified_gmt":"2025-05-10T02:24:09","slug":"%e8%af%a6%e8%a7%a3redis%e6%85%a2%e6%9f%a5%e8%af%a2%e5%8a%9f%e8%83%bd%ef%bc%9a%e5%bf%ab%e9%80%9f%e5%ae%9a%e4%bd%8d%e6%80%a7%e8%83%bd%e7%93%b6%e9%a2%88","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201575\/","title":{"rendered":"\u8be6\u89e3Redis\u6162\u67e5\u8be2\u529f\u80fd\uff1a\u5feb\u901f\u5b9a\u4f4d\u6027\u80fd\u74f6\u9888"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u8be6\u89e3Redis\u6162\u67e5\u8be2\u529f\u80fd\uff1a\u5feb\u901f\u5b9a\u4f4d\u6027\u80fd\u74f6\u9888<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6570\u636e\u5e93\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0cgolang\u5b66\u4e60\u7f51\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300a\u8be6\u89e3Redis\u6162\u67e5\u8be2\u529f\u80fd\uff1a\u5feb\u901f\u5b9a\u4f4d\u6027\u80fd\u74f6\u9888\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\u547d\u4ee4\u3001Redis\u3001\u6570\u636e\u5e93\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<p>Redis\u6570\u636e\u5e93\u662f\u4e00\u4e2a\u57fa\u4e8e\u5185\u5b58\u7684 key-value\u5b58\u50a8\u7cfb\u7edf\uff0c\u73b0\u5728redis\u6700\u5e38\u7528\u7684\u4f7f\u7528\u573a\u666f\u5c31\u662f\u5b58\u50a8\u7f13\u5b58\u7528\u7684\u6570\u636e\uff0c\u5728\u9700\u8981\u9ad8\u901f\u8bfb\/\u5199\u7684\u573a\u5408\u4f7f\u7528\u5b83\u5feb\u901f\u8bfb\/\u5199\uff0c\u4ece\u800c\u7f13\u89e3\u5e94\u7528\u6570\u636e\u5e93\u7684\u538b\u529b\uff0c\u8fdb\u800c\u63d0\u5347\u5e94\u7528\u5904\u7406\u80fd\u529b\u3002<\/p>\n<p>\u8bb8\u591a\u6570\u636e\u5e93\u4f1a\u63d0\u4f9b\u6162\u67e5\u8be2\u65e5\u5fd7\u5e2e\u52a9\u5f00\u53d1\u548c\u8fd0\u7ef4\u4eba\u5458\u5b9a\u4f4d\u7cfb\u7edf\u5b58\u5728\u7684\u6162\u64cd\u4f5c\u3002\u6240\u8c13\u6162\u67e5\u8be2\u65e5\u5fd7\u5c31\u662f\u7cfb\u7edf\u5728\u547d\u4ee4\u6267\u884c\u524d\u540e\u8ba1\u7b97\u6bcf\u6761\u547d\u4ee4\u7684\u6267\u884c\u65f6\u95f4\uff0c\u5f53\u7136\u5728\u6570\u636e\u5e93\u4e2d\u6700\u5e38\u89c1\u7684\u5c31\u662fselect\u8fd9\u4e9bsql\u8bed\u53e5\u4e86\uff0c\u5f53\u8d85\u8fc7\u9884\u8bbe\u9600\u503c\uff0c\u5c31\u5c06\u8fd9\u6761\u547d\u4ee4\u7684\u76f8\u5173\u4fe1\u606f(\u4f8b\u5982\uff1a\u53d1\u751f\u65f6\u95f4\uff0c\u8017\u65f6\uff0c\u547d\u4ee4\u7684\u8be6\u7ec6\u4fe1\u606f)\u8bb0\u5f55\u4e0b\u6765\uff0c\u5176\u5b9eRedis\u4e5f\u63d0\u4f9b\u4e86\u7c7b\u4f3c\u7684\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728607463f95aba97954.jpg\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p><strong>\u4e00\u3001\u76f8\u5173\u53c2\u6570<\/strong><\/p>\n<p>Redis\u4e3b\u8981\u63d0\u4f9b\u4e86slowlog-log-slower-than\u548cslowlog-max-len\u4e24\u4e2a\u914d\u7f6e\u53c2\u6570\u6765\u63d0\u4f9b\u8fd9\u9879\u529f\u80fd\u3002\u4e24\u9879\u53c2\u6570\u5206\u522b\u7528\u6765\u8bbe\u7f6e\u6162\u67e5\u8be2\u7684\u9608\u503c\u4ee5\u53ca\u5b58\u653e\u6162\u67e5\u8be2\u7684\u8bb0\u5f55\u3002<\/p>\n<p>slowlog-log-slower-than\u53c2\u6570\u8bbe\u7f6e\u4ec0\u4e48\u60c5\u51b5\u4e0b\u662f\u6162\u8bed\u53e5\uff0c\u53ea\u6709redis\u547d\u4ee4\u6267\u884c\u65f6\u95f4\u5927\u4e8eslowlog-log-slower-than\u7684\u624d\u4f1a\u5b9a\u4e49\u6210\u6162\u67e5\u8be2\uff0c\u624d\u4f1a\u88abslowlog\u8fdb\u884c\u8bb0\u5f55\u3002\u5b83\u7684\u5355\u4f4d\u662f\u5fae\u79d2(1\u79d2=1000\u6beb\u79d2=1000000\u5fae\u79d2)\uff0c\u5728\u521d\u59cb\u60c5\u51b5\u4e0b\u9ed8\u8ba4\u503c\u662f10000\uff0c\u4e5f\u5c31\u662f10ms\uff0c\u5047\u5982\u6267\u884c\u4e86\u4e00\u6761\u6bd4\u8f83\u6162\u7684\u547d\u4ee4\uff0c\u5982\u679c\u5b83\u7684\u6267\u884c\u65f6\u95f4\u8d85\u8fc7\u4e86 10ms \uff0c\u90a3\u4e48\u5b83\u5c06\u88ab\u8bb0\u5f55\u5728\u6162\u67e5\u8be2\u65e5\u5fd7\u4e2d\u3002(\u5982\u679cslowlog-log-slower-than=0\u4f1a\u8bb0\u5f55\u6240\u6709\u7684\u547d\u4ee4\uff0cslowlog-log-slower than <\/p>\n<p>slowlog-max-len\u8bf4\u660e\u4e86\u6162\u67e5\u8be2\u65e5\u5fd7\u6700\u591a\u53ef\u4ee5\u5b58\u50a8\u591a\u5c11\u6761\u8bb0\u5f55\uff0c\u5b9e\u9645\u4e0aRedis\u4f7f\u7528\u4e86\u4e00\u4e2a\u5217\u8868\u6765\u5b58\u50a8\u6162\u67e5\u8be2\u65e5\u5fd7\uff0cslowlog-max-len\u5c31\u662f\u5217\u8868\u7684\u6700\u5927\u957f\u5ea6\uff0c\u5b83\u81ea\u8eab\u662f\u4e00\u4e2a\u5148\u8fdb\u5148\u51fa\u961f\u5217\uff0c\u5f53slowlog\u8d85\u8fc7\u8bbe\u5b9a\u7684\u6700\u5927\u503c\u540e\uff0c\u4f1a\u5c06\u6700\u65e9\u7684slowlog\u5220\u9664\u3002\u7b80\u800c\u8a00\u4e4b\u5f53\u4e00\u4e2a\u65b0\u7684\u547d\u4ee4\u6ee1\u8db3\u6162\u67e5\u8be2\u6761\u4ef6\u65f6\u4f1a\u88ab\u63d2\u5165\u5230\u8fd9\u4e2a\u5217\u8868\u4e2d\uff0c\u5f53\u6162\u67e5\u8be2\u65e5\u5fd7\u5217\u8868\u5df2\u5904\u4e8e\u5176\u6700\u5927\u957f\u5ea6\u65f6\uff0c\u6700\u65e9\u63d2\u5165\u7684\u4e00\u4e2a\u547d\u4ee4\u5c06\u4ece\u5217\u8868\u4e2d\u79fb\u51fa\uff0c\u4f8b\u5982slowlog-max-len\u8bbe\u7f6e\u4e3a 50 \uff0c\u5f53\u6709\u7b2c51\u6761\u6162\u67e5\u8be2\u63d2\u5165\u7684\u8bdd\uff0c\u90a3\u4e48\u961f\u5934\u7684\u7b2c\u4e00\u6761\u6570\u636e\u5c31\u51fa\u5217\uff0c\u7b2c51\u6761\u6162\u67e5\u8be2\u5c31\u4f1a\u5165\u5217\u3002<\/p>\n<p><strong>\u4e8c\u3001\u8bbe\u7f6eRedis\u6162\u67e5\u8be2<\/strong><\/p>\n<p><strong>1\u3001\u4e34\u65f6\u914d\u7f6e\uff1aCONFIG\u547d\u4ee4\u8fdb\u884c\u52a8\u6001\u914d\u7f6e<\/strong><\/p>\n<\/p>\n<ol>\n<li><span><span>#\u67e5\u770b&nbsp;<\/span><\/span><\/li>\n<li><span><span>&gt;<\/span><span>config&nbsp;get&nbsp;slowlog-log-slower-than&nbsp;<\/span><\/span><\/li>\n<li><span><span>&gt;<\/span><span>config&nbsp;get&nbsp;slowlog-max-len&nbsp;<\/span><\/span><\/li>\n<li><span>#\u914d\u7f6e\u67e5\u8be2\u65f6\u95f4\u8d85\u8fc71\u6beb\u7c73\u7684\u547d\u4ee4\u8fdb\u884c\u8bb0\u5f55\u5e76\u4fdd\u5b58500\u6761\u6162\u67e5\u8be2\u8bb0\u5f55&nbsp;<\/span><\/li>\n<li><span><span>&gt;<\/span><span>config&nbsp;set&nbsp;slowlog-log-slower-than&nbsp;1000&nbsp;<\/span><\/span><\/li>\n<li><span><span>&gt;<\/span><span>config&nbsp;set&nbsp;slowlog-max-len&nbsp;500&nbsp;<\/span><\/span><\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728607463f95abadfe29.jpg\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p>\u6ce8\u610f\u901a\u8fc7config\u547d\u4ee4\u914d\u7f6e\u7684\u4e3a\u52a8\u6001\u751f\u6548 \uff0c \u4e00\u65e6\u670d\u52a1\u91cd\u542f\u5219\u4f1a\u91cd\u65b0\u6062\u590d\u4e3a\u9ed8\u8ba4\u8bbe\u7f6e \uff0c \u6240\u4ee5\u5efa\u8bae\u5728\u6392\u67e5\u95ee\u9898\u65f6\u901a\u8fc7config\u8fd9\u79cd\u65b9\u5f0f\u8fdb\u884c\u914d\u7f6e \uff0c \u4f46\u662f\u670d\u52a1\u7a33\u5b9a\u540e\u901a\u8fc7\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u65b9\u5f0f\u8fdb\u884c\u6700\u7ec8\u786e\u8ba4 (\u53ef\u4ee5\u901a\u8fc7config rewrite\u547d\u4ee4\u6301\u4e45\u5316\u5230\u672c\u5730\u6587\u4ef6 \uff0c \u4f46\u8981\u4e3b\u8981\u542f\u52a8redis\u65f6\u8981\u6307\u5b9aredis.conf\u6587\u4ef6 \u8be5\u547d\u4ee4\u624d\u53ef\u4ee5\u751f\u6548)\u3002<\/p>\n<p><strong>2. \u6c38\u4e45\u914d\u7f6e\uff1a\u914d\u7f6eredis.conf\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<ol>\n<li><span><span>#&nbsp;vi&nbsp;redis.conf&nbsp;<\/span><\/span><\/li>\n<li><span>slowlog-log-slower-than&nbsp;1000&nbsp;<\/span><\/li>\n<li><span>slowlog-max-len&nbsp;500&nbsp;<\/span><\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728607563f95abb51f77.jpg\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p><strong>\u4e09\u3001\u67e5\u770bRedis\u6162\u67e5\u8be2\u8bb0\u5f55<\/strong><\/p>\n<p>\u8981\u60f3\u67e5\u770b\u6240\u8bb0\u5f55\u7684\u65e5\u5fd7 \uff0c\u4e3b\u8981\u4f7f\u7528 SLOWLOG GET \u6216\u8005 SLOWLOG GET number \u547d\u4ee4\uff0c\u524d\u8005\u5c06\u4f1a\u8f93\u51fa\u6240\u6709\u7684 slow log \uff0c\u6700\u5927\u957f\u5ea6\u53d6\u51b3\u4e8e slowlog-max-len \u9009\u9879\u7684\u503c\uff0c\u800c SLOWLOG GET number \u5219\u53ea\u6253\u5370\u6307\u5b9a\u6570\u91cf\u7684\u65e5\u5fd7\u3002<\/p>\n<p>\u67e5\u770b\u5f53\u524d\u65e5\u5fd7\u6570\u91cf: \u4f7f\u7528slowlog len\u547d\u4ee4\u67e5\u770b\u65e5\u5fd7\u6570\u91cf\u3002<\/p>\n<p>\u5982\u679c\u65e5\u5fd7\u6761\u6570\u8fc7\u591a\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528slowlog reset\u547d\u4ee4\u8fdb\u884c\u65e5\u5fd7\u6e05\u7a7a \u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728607563f95abbadbac.jpg\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p>\u90e8\u5206\u8bb0\u5f55\u8bf4\u660e\uff1a<\/p>\n<\/p>\n<ol>\n<li><span><span>3)&nbsp;1)&nbsp;(integer)&nbsp;25&nbsp;#&nbsp;\u552f\u4e00\u6027(unique)\u7684\u65e5\u5fd7\u6807\u8bc6\u7b26&nbsp;<\/span><\/span><\/li>\n<li><span>&nbsp;2)&nbsp;(integer)&nbsp;1565951323&nbsp;#&nbsp;\u88ab\u8bb0\u5f55\u547d\u4ee4\u7684\u6267\u884c\u65f6\u95f4\u70b9\uff0c\u4ee5&nbsp;UNIX&nbsp;\u65f6\u95f4\u6233\u683c\u5f0f\u8868\u793a&nbsp;<\/span><\/li>\n<li><span>&nbsp;3)&nbsp;(integer)&nbsp;22720&nbsp;#&nbsp;\u67e5\u8be2\u6267\u884c\u65f6\u95f4\uff0c\u4ee5\u5fae\u79d2\u4e3a\u5355\u4f4d&nbsp;<\/span><\/li>\n<li><span>&nbsp;4)&nbsp;1)&nbsp;&#8220;SMEMBERS&#8221;&nbsp;#&nbsp;\u6267\u884c\u7684\u547d\u4ee4\uff0c\u4ee5\u6570\u7ec4\u7684\u5f62\u5f0f\u6392\u5217&nbsp;<\/span><\/li>\n<li><span>&nbsp;2)&nbsp;&#8220;spring:session:expirations:1565950980000&#8221;&nbsp;#&nbsp;\u8fd9\u91cc\u5b8c\u6574\u7684\u547d\u4ee4\u662f&nbsp;SMEMBERS&nbsp;spring:session:expirations:1565950980000&nbsp;<\/span><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8be6\u89e3Redis\u6162\u67e5\u8be2\u529f\u80fd\uff1a\u5feb\u901f\u5b9a&#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-201575","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201575","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=201575"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201575\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}