{"id":202176,"date":"2025-05-10T08:36:12","date_gmt":"2025-05-10T00:36:12","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202176\/"},"modified":"2025-05-10T08:36:12","modified_gmt":"2025-05-10T00:36:12","slug":"redis%e4%b8%ad%e8%bf%87%e6%9c%9f%e6%93%8d%e4%bd%9c%e5%92%8c%e8%bf%87%e6%9c%9f%e7%ad%96%e7%95%a5%e7%9a%84%e7%a4%ba%e4%be%8b%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202176\/","title":{"rendered":"Redis\u4e2d\u8fc7\u671f\u64cd\u4f5c\u548c\u8fc7\u671f\u7b56\u7565\u7684\u793a\u4f8b\u5206\u6790"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Redis\u4e2d\u8fc7\u671f\u64cd\u4f5c\u548c\u8fc7\u671f\u7b56\u7565\u7684\u793a\u4f8b\u5206\u6790<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u6570\u636e\u5e93\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300aRedis\u4e2d\u8fc7\u671f\u64cd\u4f5c\u548c\u8fc7\u671f\u7b56\u7565\u7684\u793a\u4f8b\u5206\u6790\u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><\/p>\n<h3>\u8fc7\u671f\u64cd\u4f5c<\/h3>\n<p><strong>\u8fc7\u671f\u8bbe\u7f6e<\/strong><\/p>\n<p><code>Redis<\/code> \u4e2d\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\u4e3b\u8981\u901a\u8fc7\u4ee5\u4e0b\u56db\u79cd\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li>\n<p><code>expire key seconds<\/code>\uff1a\u8bbe\u7f6e <code>key<\/code> \u5728 n \u79d2\u540e\u8fc7\u671f\u3002<\/p>\n<\/li>\n<li>\n<p><code>pexpire key milliseconds<\/code>\uff1a\u8bbe\u7f6e <code>key<\/code> \u5728 n \u6beb\u79d2\u540e\u8fc7\u671f\u3002<\/p>\n<\/li>\n<li>\n<p><code>expireat key timestamp<\/code>\uff1a\u8bbe\u7f6e <code>key<\/code> \u5728\u67d0\u4e2a\u65f6\u95f4\u6233\uff08\u7cbe\u786e\u5230\u79d2\uff09\u4e4b\u540e\u8fc7\u671f\u3002<\/p>\n<\/li>\n<li>\n<p><code>pexpireat key millisecondsTimestamp<\/code>\uff1a\u8bbe\u7f6e <code>key<\/code> \u5728\u67d0\u4e2a\u65f6\u95f4\u6233\uff08\u7cbe\u786e\u5230\u6beb\u79d2\uff09\u4e4b\u540e\u8fc7\u671f\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u53ef\u7528\u547d\u4ee4 <code>ttl key<\/code> \uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u6216 <code>pttl key<\/code> \uff08\u4ee5\u6beb\u79d2\u4e3a\u5355\u4f4d\uff09\u6765\u67e5\u770b <code>key<\/code> \u8fd8\u6709\u591a\u4e45\u8fc7\u671f\u3002<\/p>\n<p><code>Redis<\/code> \u53ef\u4ee5\u4f7f\u7528 <code>time<\/code> \u547d\u4ee4\u67e5\u8be2\u5f53\u524d\u65f6\u95f4\u7684\u65f6\u95f4\u6233\uff08\u7cbe\u786e\u5230\u79d2\uff09\u3002<\/p>\n<p>\u5b57\u7b26\u4e32\u4e2d\u51e0\u4e2a\u76f4\u63a5\u64cd\u4f5c\u8fc7\u671f\u65f6\u95f4\u7684\u65b9\u6cd5\uff0c\u5982\u4e0b\u5217\u8868\uff1a<\/p>\n<ul>\n<li>\n<p><code>set key value ex seconds<\/code>\uff1a\u8bbe\u7f6e\u952e\u503c\u5bf9\u7684\u540c\u65f6\u6307\u5b9a\u8fc7\u671f\u65f6\u95f4\uff08\u7cbe\u786e\u5230\u79d2\uff09\u3002<\/p>\n<\/li>\n<li>\n<p><code>set key value px milliseconds<\/code>\uff1a\u8bbe\u7f6e\u952e\u503c\u5bf9\u7684\u540c\u65f6\u6307\u5b9a\u8fc7\u671f\u65f6\u95f4\uff08\u7cbe\u786e\u5230\u6beb\u79d2\uff09\u3002<\/p>\n<\/li>\n<li>\n<p><code>setex key seconds valule<\/code>\uff1a\u8bbe\u7f6e\u952e\u503c\u5bf9\u7684\u540c\u65f6\u6307\u5b9a\u8fc7\u671f\u65f6\u95f4\uff08\u7cbe\u786e\u5230\u79d2\uff09\u3002<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u79fb\u9664\u8fc7\u671f\u65f6\u95f4<\/strong><\/p>\n<p>\u4f7f\u7528\u547d\u4ee4\uff1a <code>persist key<\/code> \u53ef\u4ee5\u79fb\u9664\u952e\u503c\u7684\u8fc7\u671f\u65f6\u95f4\u3002-1 \u8868\u793a\u6c38\u4e0d\u8fc7\u671f\u3002<\/p>\n<p><strong>Java \u5b9e\u73b0\u8fc7\u671f\u64cd\u4f5c<\/strong><\/p>\n<p>\u4f7f\u7528 <code>Jedis<\/code> \u6765\u5b9e\u73b0\u5bf9 <code>Redis<\/code> \u7684\u64cd\u4f5c\uff0c\u4ee3\u7801\uff1a<\/p>\n<pre>public&nbsp;class&nbsp;TTLTest&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;throws&nbsp;InterruptedException&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u521b\u5efa&nbsp;Redis&nbsp;\u8fde\u63a5\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Jedis&nbsp;jedis&nbsp;=&nbsp;new&nbsp;Jedis(\"xxx.xxx.xxx.xxx\",&nbsp;6379);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u8bbe\u7f6e&nbsp;Redis&nbsp;\u5bc6\u7801(\u5982\u679c\u6ca1\u6709\u5bc6\u7801\uff0c\u6b64\u884c\u53ef\u7701\u7565)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.auth(\"xxx\");\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u5b58\u50a8\u952e\u503c\u5bf9\uff08\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u6c38\u4e0d\u8fc7\u671f\uff09\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.set(\"k\",&nbsp;\"v\");\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u67e5\u8be2&nbsp;TTL\uff08\u8fc7\u671f\u65f6\u95f4\uff09\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Long&nbsp;ttl&nbsp;=&nbsp;jedis.ttl(\"k\");\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u6253\u5370\u8fc7\u671f\u65e5\u5fd7\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u8fc7\u671f\u65f6\u95f4\uff1a-1\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(\"\u8fc7\u671f\u65f6\u95f4\uff1a\"&nbsp;+&nbsp;ttl);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u8bbe\u7f6e&nbsp;100s&nbsp;\u540e\u8fc7\u671f\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.expire(\"k\",&nbsp;100);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u7b49\u5f85&nbsp;1s&nbsp;\u540e\u6267\u884c\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(1000);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u6253\u5370\u8fc7\u671f\u65e5\u5fd7\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u6267\u884c&nbsp;expire&nbsp;\u540e\u7684&nbsp;TTL=99\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(\"\u6267\u884c&nbsp;expire&nbsp;\u540e\u7684&nbsp;TTL=\"&nbsp;+&nbsp;jedis.ttl(\"k\"));\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}<\/pre>\n<p><strong>\u66f4\u591a\u8fc7\u671f\u64cd\u4f5c\u65b9\u6cd5<\/strong>\uff0c\u5982\u4e0b\u5217\u8868\uff1a<\/p>\n<ul>\n<li>\n<p><code>pexpire(String key, long milliseconds)<\/code>\uff1a\u8bbe\u7f6e n \u6beb\u79d2\u540e\u8fc7\u671f\u3002<\/p>\n<\/li>\n<li>\n<p><code>expireAt(String key, long unixTime)<\/code>\uff1a\u8bbe\u7f6e\u67d0\u4e2a\u65f6\u95f4\u6233\u540e\u8fc7\u671f\uff08\u7cbe\u786e\u5230\u79d2\uff09\u3002<\/p>\n<\/li>\n<li>\n<p><code>pexpireAt(String key, long millisecondsTimestamp)<\/code>\uff1a\u8bbe\u7f6e\u67d0\u4e2a\u65f6\u95f4\u6233\u540e\u8fc7\u671f\uff08\u7cbe\u786e\u5230\u6beb\u79d2\uff09\u3002<\/p>\n<\/li>\n<li>\n<p><code>persist(String key)<\/code>\uff1a\u79fb\u9664\u8fc7\u671f\u65f6\u95f4\u3002<\/p>\n<\/li>\n<\/ul>\n<pre>public&nbsp;class&nbsp;TTLTest&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;throws&nbsp;InterruptedException&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u521b\u5efa&nbsp;Redis&nbsp;\u8fde\u63a5\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Jedis&nbsp;jedis&nbsp;=&nbsp;new&nbsp;Jedis(\"xxx.xxx.xxx.xxx\",&nbsp;6379);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u8bbe\u7f6e&nbsp;Redis&nbsp;\u5bc6\u7801(\u5982\u679c\u6ca1\u6709\u5bc6\u7801\uff0c\u6b64\u884c\u53ef\u7701\u7565)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.auth(\"xxx\");\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u5b58\u50a8\u952e\u503c\u5bf9\uff08\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u6c38\u4e0d\u8fc7\u671f\uff09\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.set(\"k\",&nbsp;\"v\");\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u67e5\u8be2&nbsp;TTL\uff08\u8fc7\u671f\u65f6\u95f4\uff09\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Long&nbsp;ttl&nbsp;=&nbsp;jedis.ttl(\"k\");\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u6253\u5370\u8fc7\u671f\u65e5\u5fd7\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(\"\u8fc7\u671f\u65f6\u95f4\uff1a\"&nbsp;+&nbsp;ttl);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u8bbe\u7f6e&nbsp;100s&nbsp;\u540e\u8fc7\u671f\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.expire(\"k\",&nbsp;100);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u7b49\u5f85&nbsp;1s&nbsp;\u540e\u6267\u884c\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(1000);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u6253\u5370\u8fc7\u671f\u65e5\u5fd7\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(\"\u6267\u884c&nbsp;expire&nbsp;\u540e\u7684&nbsp;TTL=\"&nbsp;+&nbsp;jedis.ttl(\"k\"));\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u8bbe\u7f6e&nbsp;n&nbsp;\u6beb\u79d2\u540e\u8fc7\u671f\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.pexpire(\"k\",&nbsp;100000);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u8bbe\u7f6e\u67d0\u4e2a\u65f6\u95f4\u6233\u540e\u8fc7\u671f\uff08\u7cbe\u786e\u5230\u79d2\uff09\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.expireAt(\"k\",&nbsp;1573468990);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u8bbe\u7f6e\u67d0\u4e2a\u65f6\u95f4\u6233\u540e\u8fc7\u671f\uff08\u7cbe\u786e\u5230\u6beb\u79d2\uff09\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.pexpireAt(\"k\",&nbsp;1573468990000L);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u79fb\u9664\u8fc7\u671f\u65f6\u95f4\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.persist(\"k\");\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}<\/pre>\n<p><strong>\u6301\u4e45\u5316\u4e2d\u7684\u8fc7\u671f\u952e<\/strong><\/p>\n<h5><strong>RDB \u4e2d\u7684\u8fc7\u671f\u952e<\/strong><\/h5>\n<p><code>RDB<\/code> \u6587\u4ef6\u5206\u4e3a\u4e24\u4e2a\u9636\u6bb5\uff0c<code>RDB<\/code> \u6587\u4ef6\u751f\u6210\u9636\u6bb5\u548c\u52a0\u8f7d\u9636\u6bb5\u3002<\/p>\n<p><strong>1. RDB \u6587\u4ef6\u751f\u6210<\/strong><\/p>\n<p><code>RDB<\/code> \u52a0\u8f7d\u5206\u4e3a\u4ee5\u4e0b\u4e24\u79cd\u60c5\u51b5\uff1a<\/p>\n<ul>\n<li>\n<p>\u5982\u679c <code>Redis<\/code> \u662f<strong>\u4e3b<\/strong>\u670d\u52a1\u5668\u8fd0\u884c\u6a21\u5f0f\u7684\u8bdd\uff0c\u5728\u8f7d\u5165 <code>RDB<\/code> \u6587\u4ef6\u65f6\uff0c\u7a0b\u5e8f\u4f1a\u5bf9\u6587\u4ef6\u4e2d\u4fdd\u5b58\u7684\u952e\u8fdb\u884c\u68c0\u67e5\uff0c\u8fc7\u671f\u952e\u4e0d\u4f1a\u88ab\u8f7d\u5165\u5230\u6570\u636e\u5e93\u4e2d\u3002\u6240\u4ee5\u8fc7\u671f\u952e\u4e0d\u4f1a\u5bf9\u8f7d\u5165 <code>RDB<\/code> \u6587\u4ef6\u7684\u4e3b\u670d\u52a1\u5668\u9020\u6210\u5f71\u54cd\uff1b<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c <code>Redis<\/code> \u662f<strong>\u4ece<\/strong>\u670d\u52a1\u5668\u8fd0\u884c\u6a21\u5f0f\u7684\u8bdd\uff0c\u5728\u8f7d\u5165 <code>RDB<\/code> \u6587\u4ef6\u65f6\uff0c\u4e0d\u8bba\u952e\u662f\u5426\u8fc7\u671f\u90fd\u4f1a\u88ab\u8f7d\u5165\u5230\u6570\u636e\u5e93\u4e2d\u3002\u4f46<strong>\u7531\u4e8e\u4e3b\u4ece\u670d\u52a1\u5668\u5728\u8fdb\u884c\u6570\u636e\u540c\u6b65\u65f6\uff0c\u4ece\u670d\u52a1\u5668\u7684\u6570\u636e\u4f1a\u88ab\u6e05\u7a7a<\/strong>\u3002\u6240\u4ee5\u4e00\u822c\u6765\u8bf4\uff0c\u8fc7\u671f\u952e\u5bf9\u8f7d\u5165 <code>RDB<\/code> \u6587\u4ef6\u7684\u4ece\u670d\u52a1\u5668\u4e5f\u4e0d\u4f1a\u9020\u6210\u5f71\u54cd\u3002<\/p>\n<\/li>\n<\/ul>\n<p><code>RDB<\/code> \u6587\u4ef6\u52a0\u8f7d\u7684\u6e90\u7801\u53ef\u4ee5\u5728 <code>rdb.c<\/code> \u6587\u4ef6\u7684 <code>rdbLoad()<\/code> \u51fd\u6570\u4e2d\u627e\u5230\uff0c\u6e90\u7801\u6240\u793a\uff1a<\/p>\n<pre>\/*&nbsp;Check&nbsp;if&nbsp;the&nbsp;key&nbsp;already&nbsp;expired.&nbsp;This&nbsp;function&nbsp;is&nbsp;used&nbsp;when&nbsp;loading\n*&nbsp;an&nbsp;RDB&nbsp;file&nbsp;from&nbsp;disk,&nbsp;either&nbsp;at&nbsp;startup,&nbsp;or&nbsp;when&nbsp;an&nbsp;RDB&nbsp;was\n*&nbsp;received&nbsp;from&nbsp;the&nbsp;master.&nbsp;In&nbsp;the&nbsp;latter&nbsp;case,&nbsp;the&nbsp;master&nbsp;is\n*&nbsp;responsible&nbsp;for&nbsp;key&nbsp;expiry.&nbsp;If&nbsp;we&nbsp;would&nbsp;expire&nbsp;keys&nbsp;here,&nbsp;the\n*&nbsp;snapshot&nbsp;taken&nbsp;by&nbsp;the&nbsp;master&nbsp;may&nbsp;not&nbsp;be&nbsp;reflected&nbsp;on&nbsp;the&nbsp;slave.&nbsp;\n*\n*&nbsp;\u5982\u679c\u670d\u52a1\u5668\u4e3a\u4e3b\u8282\u70b9\u7684\u8bdd\uff0c\n*&nbsp;\u90a3\u4e48\u5728\u952e\u5df2\u7ecf\u8fc7\u671f\u7684\u65f6\u5019\uff0c\u4e0d\u518d\u5c06\u5b83\u4eec\u5173\u8054\u5230\u6570\u636e\u5e93\u4e2d\u53bb\n*\/\nif&nbsp;(server.masterhost&nbsp;==&nbsp;NULL&nbsp;&amp;&amp;&nbsp;expiretime&nbsp;!=&nbsp;-1&nbsp;&amp;&amp;&nbsp;expiretime&nbsp;&lt;&nbsp;now)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;decrRefCount(key);\n&nbsp;&nbsp;&nbsp;&nbsp;decrRefCount(val);\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u8df3\u8fc7\n&nbsp;&nbsp;&nbsp;&nbsp;continue;\n}<\/pre>\n<h5><strong>AOF \u4e2d\u7684\u8fc7\u671f\u952e<\/strong><\/h5>\n<p><strong>1. AOF \u6587\u4ef6\u5199\u5165<\/strong><\/p>\n<p>\u5f53 <code>Redis<\/code> \u4ee5 <code>AOF<\/code> \u6a21\u5f0f\u6301\u4e45\u5316\u65f6\uff0c\u5982\u679c\u6570\u636e\u5e93\u67d0\u4e2a\u8fc7\u671f\u952e\u8fd8\u6ca1\u88ab\u5220\u9664\uff0c\u90a3\u4e48 <code>AOF<\/code> \u6587\u4ef6\u4f1a\u4fdd\u7559\u6b64\u8fc7\u671f\u952e\uff0c\u5f53\u6b64\u8fc7\u671f\u952e\u88ab\u5220\u9664\u540e\uff0c<code>Redis<\/code> \u4f1a\u5411 <code>AOF<\/code> \u6587\u4ef6\u8ffd\u52a0\u4e00\u6761 <code>DEL<\/code> \u547d\u4ee4\u6765\u663e\u5f0f\u5730\u5220\u9664\u8be5\u952e\u503c\u3002<\/p>\n<p><strong>2. AOF \u91cd\u5199<\/strong><\/p>\n<p>\u6267\u884c <code>AOF<\/code> \u91cd\u5199\u65f6\uff0c\u4f1a\u5bf9 <code>Redi<\/code>s \u4e2d\u7684\u952e\u503c\u5bf9\u8fdb\u884c\u68c0\u67e5\u5df2\u8fc7\u671f\u7684\u952e\u4e0d\u4f1a\u88ab\u4fdd\u5b58\u5230\u91cd\u5199\u540e\u7684 <code>AOF<\/code> \u6587\u4ef6\u4e2d\uff0c\u56e0\u6b64\u4e0d\u4f1a\u5bf9 <code>AOF<\/code> \u91cd\u5199\u9020\u6210\u4efb\u4f55\u5f71\u54cd\u3002<\/p>\n<p><strong>\u4e3b\u4ece\u5e93\u7684\u8fc7\u671f\u952e<\/strong><\/p>\n<p>\u5f53 <code>Redis<\/code> \u8fd0\u884c\u5728\u4e3b\u4ece\u6a21\u5f0f\u4e0b\u65f6\uff0c<strong>\u4ece\u5e93\u4e0d\u4f1a\u8fdb\u884c\u8fc7\u671f\u626b\u63cf\uff0c\u4ece\u5e93\u5bf9\u8fc7\u671f\u7684\u5904\u7406\u662f\u88ab\u52a8\u7684<\/strong>\u3002\u4e5f\u5c31\u662f\u5373\u4f7f\u4ece\u5e93\u4e2d\u7684 <code>key<\/code> \u8fc7\u671f\u4e86\uff0c\u5982\u679c\u6709\u5ba2\u6237\u7aef\u8bbf\u95ee\u4ece\u5e93\u65f6\uff0c\u4f9d\u7136\u53ef\u4ee5\u5f97\u5230 <code>key<\/code> \u5bf9\u5e94\u7684\u503c\uff0c\u50cf\u672a\u8fc7\u671f\u7684\u952e\u503c\u5bf9\u4e00\u6837\u8fd4\u56de\u3002<\/p>\n<p><strong>\u4ece\u5e93\u7684\u8fc7\u671f\u952e\u5904\u7406\u4f9d\u9760\u4e3b\u670d\u52a1\u5668\u63a7\u5236<\/strong>\uff0c\u4e3b\u5e93\u5728 <code>key<\/code> \u5230\u671f\u65f6\uff0c\u4f1a\u5728 <code>AOF<\/code> \u6587\u4ef6\u91cc\u589e\u52a0\u4e00\u6761 <code>del<\/code> \u6307\u4ee4\uff0c\u540c\u6b65\u5230\u6240\u6709\u7684\u4ece\u5e93\uff0c\u4ece\u5e93\u901a\u8fc7\u6267\u884c\u8fd9\u6761 <code>del<\/code> \u6307\u4ee4\u6765\u5220\u9664\u8fc7\u671f\u7684 <code>key<\/code>\u3002<\/p>\n<h3>\u8fc7\u671f\u7b56\u7565<\/h3>\n<blockquote>\n<p>\u5728 <code>Redis<\/code> \u4e2d\u6211\u4eec\u53ef\u4ee5\u7ed9\u4e00\u4e9b\u5143\u7d20\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\uff0c\u90a3\u5f53\u5b83\u8fc7\u671f\u4e4b\u540e <code>Redis<\/code> \u662f\u5982\u4f55\u5904\u7406\u8fd9\u4e9b\u8fc7\u671f\u952e\u5462\uff1f<\/p>\n<\/blockquote>\n<p><strong>\u8fc7\u671f\u952e\u6267\u884c\u6d41\u7a0b<\/strong><\/p>\n<p><code>Redis<\/code> \u4e4b\u6240\u4ee5\u80fd\u77e5\u9053\u90a3\u4e9b\u952e\u503c\u8fc7\u671f\uff0c\u662f\u56e0\u4e3a\u5728 <code>Redis<\/code> \u4e2d\u7ef4\u62a4\u4e86\u4e00\u4e2a\u5b57\u5178\uff0c\u5b58\u50a8\u4e86\u6240\u6709\u8bbe\u7f6e\u4e86\u8fc7\u671f\u65f6\u95f4\u7684\u952e\u503c\uff0c\u6211\u4eec\u79f0\u4e4b\u4e3a<strong>\u8fc7\u671f\u5b57\u5178<\/strong>\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230829\/169328843364ed87f18f2e5.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u8fc7\u671f\u952e\u6e90\u7801\u5206\u6790<\/strong><\/p>\n<p>\u8fc7\u671f\u952e\u5b58\u50a8\u5728 <code>redisDb<\/code> \u7ed3\u6784\u4e2d\uff0c\u6e90\u4ee3\u7801\u5728 <code>src\/server.h<\/code> \u6587\u4ef6\u4e2d\uff08\u57fa\u4e8e <code>Redis 5<\/code>\uff09\uff1a<\/p>\n<pre>\/*&nbsp;Redis&nbsp;database&nbsp;representation.&nbsp;There&nbsp;are&nbsp;multiple&nbsp;databases&nbsp;identified\n&nbsp;*&nbsp;by&nbsp;integers&nbsp;from&nbsp;0&nbsp;(the&nbsp;default&nbsp;database)&nbsp;up&nbsp;to&nbsp;the&nbsp;max&nbsp;configured\n&nbsp;*&nbsp;database.&nbsp;The&nbsp;database&nbsp;number&nbsp;is&nbsp;the&nbsp;'id'&nbsp;field&nbsp;in&nbsp;the&nbsp;structure.&nbsp;*\/\ntypedef&nbsp;struct&nbsp;redisDb&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;dict&nbsp;*dict;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/*&nbsp;\u6570\u636e\u5e93\u952e\u7a7a\u95f4\uff0c\u5b58\u653e\u7740\u6240\u6709\u7684\u952e\u503c\u5bf9&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;dict&nbsp;*expires;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/*&nbsp;\u952e\u7684\u8fc7\u671f\u65f6\u95f4&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;dict&nbsp;*blocking_keys;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/*&nbsp;Keys&nbsp;with&nbsp;clients&nbsp;waiting&nbsp;for&nbsp;data&nbsp;(BLPOP)*\/\n&nbsp;&nbsp;&nbsp;&nbsp;dict&nbsp;*ready_keys;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/*&nbsp;Blocked&nbsp;keys&nbsp;that&nbsp;received&nbsp;a&nbsp;PUSH&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;dict&nbsp;*watched_keys;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/*&nbsp;WATCHED&nbsp;keys&nbsp;for&nbsp;MULTI\/EXEC&nbsp;CAS&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;id;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/*&nbsp;Database&nbsp;ID&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;long&nbsp;avg_ttl;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/*&nbsp;Average&nbsp;TTL,&nbsp;just&nbsp;for&nbsp;stats&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;list&nbsp;*defrag_later;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/*&nbsp;List&nbsp;of&nbsp;key&nbsp;names&nbsp;to&nbsp;attempt&nbsp;to&nbsp;defrag&nbsp;one&nbsp;by&nbsp;one,&nbsp;gradually.&nbsp;*\/\n}&nbsp;redisDb;<\/pre>\n<p>\u8fc7\u671f\u952e\u6570\u636e\u7ed3\u6784\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230829\/169328843364ed87f192d59.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u8fc7\u671f\u7b56\u7565<\/strong><\/p>\n<p><code>Redis<\/code> \u4f1a\u5220\u9664\u5df2\u8fc7\u671f\u7684\u952e\u503c\uff0c\u4ee5\u6b64\u6765\u51cf\u5c11 <code>Redis<\/code> \u7684\u7a7a\u95f4\u5360\u7528\uff0c\u4f46\u56e0\u4e3a <code>Redis<\/code> \u672c\u8eab\u662f\u5355\u7ebf\u7684\uff0c\u5982\u679c\u56e0\u4e3a\u5220\u9664\u64cd\u4f5c\u800c\u5f71\u54cd\u4e3b\u4e1a\u52a1\u7684\u6267\u884c\u5c31\u5f97\u4e0d\u507f\u5931\u4e86\uff0c\u4e3a\u6b64 <code>Redis<\/code> \u9700\u8981\u5236\u5b9a\u591a\u4e2a\uff08\u8fc7\u671f\uff09\u5220\u9664\u7b56\u7565\u6765\u4fdd\u8bc1\u6b63\u5e38\u6267\u884c\u7684\u6027\u80fd\u3002<\/p>\n<h5><strong>\u5b9a\u65f6\u5220\u9664<\/strong><\/h5>\n<p><strong>\u5728\u8bbe\u7f6e\u952e\u503c\u8fc7\u671f\u65f6\u95f4\u65f6\uff0c\u521b\u5efa\u4e00\u4e2a\u5b9a\u65f6\u4e8b\u4ef6\uff0c\u5f53\u8fc7\u671f\u65f6\u95f4\u5230\u8fbe\u65f6\uff0c\u7531\u4e8b\u4ef6\u5904\u7406\u5668\u81ea\u52a8\u6267\u884c\u952e\u7684\u5220\u9664\u64cd\u4f5c<\/strong>\u3002<\/p>\n<ul>\n<li>\n<p><strong>\u4f18\u70b9<\/strong>\uff1a\u4fdd\u8bc1\u5185\u5b58\u53ef\u4ee5\u88ab\u5c3d\u5feb\u5730\u91ca\u653e\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u7f3a\u70b9<\/strong>\uff1a\u5728 <code>Redis<\/code> \u9ad8\u8d1f\u8f7d\u7684\u60c5\u51b5\u4e0b\u6216\u6709\u5927\u91cf\u8fc7\u671f\u952e\u9700\u8981\u540c\u65f6\u5904\u7406\u65f6\uff0c\u4f1a\u9020\u6210 <code>Redis<\/code> \u670d\u52a1\u5668\u5361\u987f\uff0c\u5f71\u54cd\u4e3b\u4e1a\u52a1\u6267\u884c\u3002<\/p>\n<\/li>\n<\/ul>\n<h5><strong>\u60f0\u6027\u5220\u9664<\/strong><\/h5>\n<p><strong>\u4e0d\u4e3b\u52a8\u5220\u9664\u8fc7\u671f\u952e\uff0c\u6bcf\u6b21\u4ece\u6570\u636e\u5e93\u83b7\u53d6\u952e\u503c\u65f6\u5224\u65ad\u662f\u5426\u8fc7\u671f\uff0c\u5982\u679c\u8fc7\u671f\u5219\u5220\u9664\u952e\u503c\uff0c\u5e76\u8fd4\u56de null<\/strong>\u3002<\/p>\n<ul>\n<li>\n<p><strong>\u4f18\u70b9<\/strong>\uff1a\u56e0\u4e3a\u6bcf\u6b21\u8bbf\u95ee\u65f6\uff0c\u624d\u4f1a\u5224\u65ad\u8fc7\u671f\u952e\uff0c\u6240\u4ee5\u6b64\u7b56\u7565\u53ea\u4f1a\u4f7f\u7528\u5f88\u5c11\u7684\u7cfb\u7edf\u8d44\u6e90\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u7f3a\u70b9<\/strong>\uff1a\u7cfb\u7edf\u5360\u7528\u7a7a\u95f4\u5220\u9664\u4e0d\u53ca\u65f6\uff0c\u5bfc\u81f4\u7a7a\u95f4\u5229\u7528\u7387\u964d\u4f4e\uff0c\u9020\u6210\u4e86\u4e00\u5b9a\u7684\u7a7a\u95f4\u6d6a\u8d39\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6e90\u7801\u89e3\u6790<\/p>\n<p>\u60f0\u6027\u5220\u9664\u7684\u6e90\u7801\u4f4d\u4e8e <code>src\/db.c<\/code> \u6587\u4ef6\u7684 <code>expireIfNeeded<\/code> \u65b9\u6cd5\u4e2d\uff0c\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>int&nbsp;expireIfNeeded(redisDb&nbsp;*db,&nbsp;robj&nbsp;*key)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u5224\u65ad\u952e\u662f\u5426\u8fc7\u671f\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!keyIsExpired(db,key))&nbsp;return&nbsp;0;\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(server.masterhost&nbsp;!=&nbsp;NULL)&nbsp;return&nbsp;1;\n&nbsp;&nbsp;&nbsp;&nbsp;\/*&nbsp;\u5220\u9664\u8fc7\u671f\u952e&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u589e\u52a0\u8fc7\u671f\u952e\u4e2a\u6570\n&nbsp;&nbsp;&nbsp;&nbsp;server.stat_expiredkeys++;\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u4f20\u64ad\u952e\u8fc7\u671f\u7684\u6d88\u606f\n&nbsp;&nbsp;&nbsp;&nbsp;propagateExpire(db,key,server.lazyfree_lazy_expire);\n&nbsp;&nbsp;&nbsp;&nbsp;notifyKeyspaceEvent(NOTIFY_EXPIRED,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"expired\",key,db-&gt;id);\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;server.lazyfree_lazy_expire&nbsp;\u4e3a&nbsp;1&nbsp;\u8868\u793a\u5f02\u6b65\u5220\u9664\uff08\u61d2\u7a7a\u95f4\u91ca\u653e\uff09\uff0c\u53cd\u4e4b\u540c\u6b65\u5220\u9664\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;server.lazyfree_lazy_expire&nbsp;?&nbsp;dbAsyncDelete(db,key)&nbsp;:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dbSyncDelete(db,key);\n}\n\/\/&nbsp;\u5224\u65ad\u952e\u662f\u5426\u8fc7\u671f\nint&nbsp;keyIsExpired(redisDb&nbsp;*db,&nbsp;robj&nbsp;*key)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;mstime_t&nbsp;when&nbsp;=&nbsp;getExpire(db,key);\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(when&nbsp;&lt;&nbsp;0)&nbsp;return&nbsp;0;&nbsp;\/*&nbsp;No&nbsp;expire&nbsp;for&nbsp;this&nbsp;key&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;\/*&nbsp;Don't&nbsp;expire&nbsp;anything&nbsp;while&nbsp;loading.&nbsp;It&nbsp;will&nbsp;be&nbsp;done&nbsp;later.&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(server.loading)&nbsp;return&nbsp;0;\n&nbsp;&nbsp;&nbsp;&nbsp;mstime_t&nbsp;now&nbsp;=&nbsp;server.lua_caller&nbsp;?&nbsp;server.lua_time_start&nbsp;:&nbsp;mstime();\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;now&nbsp;&gt;&nbsp;when;\n}\n\/\/&nbsp;\u83b7\u53d6\u952e\u7684\u8fc7\u671f\u65f6\u95f4\nlong&nbsp;long&nbsp;getExpire(redisDb&nbsp;*db,&nbsp;robj&nbsp;*key)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;dictEntry&nbsp;*de;\n&nbsp;&nbsp;&nbsp;&nbsp;\/*&nbsp;No&nbsp;expire?&nbsp;return&nbsp;ASAP&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(dictSize(db-&gt;expires)&nbsp;==&nbsp;0&nbsp;||\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(de&nbsp;=&nbsp;dictFind(db-&gt;expires,key-&gt;ptr))&nbsp;==&nbsp;NULL)&nbsp;return&nbsp;-1;\n&nbsp;&nbsp;&nbsp;&nbsp;\/*&nbsp;The&nbsp;entry&nbsp;was&nbsp;found&nbsp;in&nbsp;the&nbsp;expire&nbsp;dict,&nbsp;this&nbsp;means&nbsp;it&nbsp;should&nbsp;also\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;be&nbsp;present&nbsp;in&nbsp;the&nbsp;main&nbsp;dict&nbsp;(safety&nbsp;check).&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;serverAssertWithInfo(NULL,key,dictFind(db-&gt;dict,key-&gt;ptr)&nbsp;!=&nbsp;NULL);\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;dictGetSignedIntegerVal(de);\n}<\/pre>\n<p>\u6240\u6709\u5bf9\u6570\u636e\u5e93\u7684\u8bfb\u5199\u547d\u4ee4\u5728\u6267\u884c\u4e4b\u524d\uff0c\u90fd\u4f1a\u8c03\u7528 <code>expireIfNeeded<\/code> \u65b9\u6cd5\u5224\u65ad\u952e\u503c\u662f\u5426\u8fc7\u671f\uff0c\u8fc7\u671f\u5219\u4f1a\u4ece\u6570\u636e\u5e93\u4e2d\u5220\u9664\uff0c\u53cd\u4e4b\u5219\u4e0d\u505a\u4efb\u4f55\u5904\u7406\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230829\/169328843364ed87f1952d3.jpg\" class=\"aligncenter\"><\/p>\n<h5><strong>\u5b9a\u671f\u5220\u9664<\/strong><\/h5>\n<p><strong>\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u68c0\u67e5\u4e00\u6b21\u6570\u636e\u5e93\uff0c\u968f\u673a\u5220\u9664\u4e00\u4e9b\u8fc7\u671f\u952e<\/strong>\u3002<\/p>\n<p><code>Redis<\/code> \u9ed8\u8ba4\u6bcf\u79d2\u8fdb\u884c <code>10<\/code> \u6b21\u8fc7\u671f\u626b\u63cf\uff0c\u6b64\u914d\u7f6e\u53ef\u901a\u8fc7 <code>Redis<\/code> \u7684\u914d\u7f6e\u6587\u4ef6 redis.conf \u8fdb\u884c\u914d\u7f6e\uff0c\u914d\u7f6e\u952e\u4e3a <code>hz<\/code> \u5b83\u7684\u9ed8\u8ba4\u503c\u662f <code>hz 10<\/code>\u3002<\/p>\n<p>\u6ce8\u610f\uff1a<code>Redis<\/code> \u6bcf\u6b21\u626b\u63cf\u5e76\u4e0d\u662f\u904d\u5386\u8fc7\u671f\u5b57\u5178\u4e2d\u7684\u6240\u6709\u952e\uff0c\u800c\u662f\u91c7\u7528\u968f\u673a\u62bd\u53d6\u5224\u65ad\u5e76\u5220\u9664\u8fc7\u671f\u952e\u7684\u5f62\u5f0f\u6267\u884c\u7684\u3002<\/p>\n<p><strong>\u5b9a\u671f\u5220\u9664\u6d41\u7a0b<\/strong><\/p>\n<ul>\n<li>\n<p>\u4ece\u8fc7\u671f\u5b57\u5178\u4e2d\u968f\u673a\u53d6\u51fa 20 \u4e2a\u952e\u3002<\/p>\n<\/li>\n<li>\n<p>\u5220\u9664\u8fd9 20 \u4e2a\u952e\u4e2d\u8fc7\u671f\u7684\u952e\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u8fc7\u671f <code>key<\/code> \u7684\u6bd4\u4f8b\u8d85\u8fc7 25%\uff0c\u91cd\u590d\u6b65\u9aa4 1\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u540c\u65f6\u4e3a\u4e86\u4fdd\u8bc1\u8fc7\u671f\u626b\u63cf\u4e0d\u4f1a\u51fa\u73b0\u5faa\u73af\u8fc7\u5ea6\uff0c\u5bfc\u81f4\u7ebf\u7a0b\u5361\u6b7b\u73b0\u8c61\uff0c\u7b97\u6cd5\u8fd8\u589e\u52a0\u4e86\u626b\u63cf\u65f6\u95f4\u7684\u4e0a\u9650\uff0c\u9ed8\u8ba4\u4e0d\u4f1a\u8d85\u8fc7 25ms\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230829\/169328843364ed87f199dcb.jpg\" class=\"aligncenter\"><\/p>\n<ul>\n<li>\n<p><strong>\u4f18\u70b9<\/strong>\uff1a\u901a\u8fc7\u9650\u5236\u5220\u9664\u64cd\u4f5c\u7684\u65f6\u957f\u548c\u9891\u7387\uff0c\u6765\u51cf\u5c11\u5220\u9664\u64cd\u4f5c\u5bf9 <code>Redis<\/code> \u4e3b\u4e1a\u52a1\u7684\u5f71\u54cd\uff0c\u540c\u65f6\u4e5f\u80fd\u5220\u9664\u4e00\u90e8\u5206\u8fc7\u671f\u7684\u6570\u636e\u51cf\u5c11\u4e86\u8fc7\u671f\u952e\u5bf9\u7a7a\u95f4\u7684\u65e0\u6548\u5360\u7528\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u7f3a\u70b9<\/strong>\uff1a\u5185\u5b58\u6e05\u7406\u65b9\u9762\u6ca1\u6709\u5b9a\u65f6\u5220\u9664\u6548\u679c\u597d\uff0c\u540c\u65f6\u6ca1\u6709\u60f0\u6027\u5220\u9664\u4f7f\u7528\u7684\u7cfb\u7edf\u8d44\u6e90\u5c11\u3002<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u6e90\u7801\u89e3\u6790<\/strong><\/p>\n<p>\u5b9a\u671f\u5220\u9664\u7684\u6838\u5fc3\u6e90\u7801\u5728 <code>src\/expire.c<\/code> \u6587\u4ef6\u4e0b\u7684 <code>activeExpireCycle<\/code> \u65b9\u6cd5\u4e2d\uff0c\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>void&nbsp;activeExpireCycle(int&nbsp;type)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;unsigned&nbsp;int&nbsp;current_db&nbsp;=&nbsp;0;&nbsp;\/*&nbsp;\u4e0a\u6b21\u5b9a\u671f\u5220\u9664\u904d\u5386\u5230\u7684\u6570\u636e\u5e93ID&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;int&nbsp;timelimit_exit&nbsp;=&nbsp;0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/*&nbsp;Time&nbsp;limit&nbsp;hit&nbsp;in&nbsp;previous&nbsp;call?&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;long&nbsp;long&nbsp;last_fast_cycle&nbsp;=&nbsp;0;&nbsp;\/*&nbsp;\u4e0a\u4e00\u6b21\u6267\u884c\u5feb\u901f\u5b9a\u671f\u5220\u9664\u7684\u65f6\u95f4\u70b9&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;j,&nbsp;iteration&nbsp;=&nbsp;0;\n&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;dbs_per_call&nbsp;=&nbsp;CRON_DBS_PER_CALL;&nbsp;\/\/&nbsp;\u6bcf\u6b21\u5b9a\u671f\u5220\u9664\uff0c\u904d\u5386\u7684\u6570\u636e\u5e93\u7684\u6570\u91cf\n&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;long&nbsp;start&nbsp;=&nbsp;ustime(),&nbsp;timelimit,&nbsp;elapsed;\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(clientsArePaused())&nbsp;return;\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(type&nbsp;==&nbsp;ACTIVE_EXPIRE_CYCLE_FAST)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!timelimit_exit)&nbsp;return;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;ACTIVE_EXPIRE_CYCLE_FAST_DURATION&nbsp;\u662f\u5feb\u901f\u5b9a\u671f\u5220\u9664\u7684\u6267\u884c\u65f6\u957f\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(start&nbsp;&lt;&nbsp;last_fast_cycle&nbsp;+&nbsp;ACTIVE_EXPIRE_CYCLE_FAST_DURATION*2)&nbsp;return;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;last_fast_cycle&nbsp;=&nbsp;start;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(dbs_per_call&nbsp;&gt;&nbsp;server.dbnum&nbsp;||&nbsp;timelimit_exit)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dbs_per_call&nbsp;=&nbsp;server.dbnum;\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u6162\u901f\u5b9a\u671f\u5220\u9664\u7684\u6267\u884c\u65f6\u957f\n&nbsp;&nbsp;&nbsp;&nbsp;timelimit&nbsp;=&nbsp;1000000*ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC\/server.hz\/100;\n&nbsp;&nbsp;&nbsp;&nbsp;timelimit_exit&nbsp;=&nbsp;0;\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(timelimit&nbsp;&lt;=&nbsp;0)&nbsp;timelimit&nbsp;=&nbsp;1;\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(type&nbsp;==&nbsp;ACTIVE_EXPIRE_CYCLE_FAST)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timelimit&nbsp;=&nbsp;ACTIVE_EXPIRE_CYCLE_FAST_DURATION;&nbsp;\/*&nbsp;\u5220\u9664\u64cd\u4f5c\u7684\u6267\u884c\u65f6\u957f&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;total_sampled&nbsp;=&nbsp;0;\n&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;total_expired&nbsp;=&nbsp;0;\n&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(j&nbsp;=&nbsp;0;&nbsp;j&nbsp;&lt;&nbsp;dbs_per_call&nbsp;&amp;&amp;&nbsp;timelimit_exit&nbsp;==&nbsp;0;&nbsp;j++)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;expired;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redisDb&nbsp;*db&nbsp;=&nbsp;server.db+(current_db&nbsp;%&nbsp;server.dbnum);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;current_db++;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server.stat_expired_time_cap_reached_count++;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/*&nbsp;\u6bcf\u6b21\u68c0\u67e5\u53ea\u5220\u9664&nbsp;ACTIVE_EXPIRE_CYCLE_LOOKUPS_PER_LOOP\/4&nbsp;\u4e2a\u8fc7\u671f\u952e&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;while&nbsp;(expired&nbsp;&gt;&nbsp;ACTIVE_EXPIRE_CYCLE_LOOKUPS_PER_LOOP\/4);\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;.......\n}<\/pre>\n<p><code>activeExpireCycle<\/code> \u65b9\u6cd5\u5728\u89c4\u5b9a\u7684\u65f6\u95f4\uff0c\u5206\u591a\u6b21\u904d\u5386\u5404\u4e2a\u6570\u636e\u5e93\uff0c\u4ece\u8fc7\u671f\u5b57\u5178\u4e2d\u968f\u673a\u68c0\u67e5\u4e00\u90e8\u5206\u8fc7\u671f\u952e\u7684\u8fc7\u671f\u65f6\u95f4\uff0c\u5220\u9664\u5176\u4e2d\u7684\u8fc7\u671f\u952e\u3002<\/p>\n<p>\u8fd9\u4e2a\u51fd\u6570\u6709\u4e24\u79cd\u6267\u884c\u6a21\u5f0f\uff0c\u4e00\u4e2a\u662f\u5feb\u901f\u6a21\u5f0f\u4e00\u4e2a\u662f\u6162\u901f\u6a21\u5f0f\uff0c\u4f53\u73b0\u662f\u4ee3\u7801\u4e2d\u7684 <code>timelimit<\/code> \u53d8\u91cf\uff0c\u8fd9\u4e2a\u53d8\u91cf\u662f\u7528\u6765\u7ea6\u675f\u6b64\u51fd\u6570\u7684\u8fd0\u884c\u65f6\u95f4\u7684\u3002\u5feb\u901f\u6a21\u5f0f\u4e0b <code>timelimit<\/code> \u7684\u503c\u662f\u56fa\u5b9a\u7684\uff0c\u7b49\u4e8e\u9884\u5b9a\u4e49\u5e38\u91cf <code>ACTIVE_EXPIRE_CYCLE_FAST_DURATION<\/code>\uff0c\u6162\u901f\u6a21\u5f0f\u4e0b\uff0c\u8fd9\u4e2a\u53d8\u91cf\u7684\u503c\u662f\u901a\u8fc7 <code>1000000 * ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC\/server.hz\/100<\/code> \u8ba1\u7b97\u7684\u3002<\/p>\n<h5><strong>Redis \u4f7f\u7528\u7684\u8fc7\u671f\u7b56\u7565<\/strong><\/h5>\n<p><code>Redis<\/code> <strong>\u4f7f\u7528\u7684\u662f\u60f0\u6027\u5220\u9664\u52a0\u5b9a\u671f\u5220\u9664\u7684\u8fc7\u671f\u7b56\u7565<\/strong>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis\u4e2d\u8fc7\u671f\u64cd\u4f5c\u548c\u8fc7\u671f\u7b56\u7565\u7684&#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-202176","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202176","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=202176"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202176\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}