{"id":77799,"date":"2026-02-25T14:49:48","date_gmt":"2026-02-25T06:49:48","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/77799.html"},"modified":"2026-02-25T14:49:48","modified_gmt":"2026-02-25T06:49:48","slug":"redis%e8%bf%87%e6%9c%9f%e9%94%ae%e5%88%a0%e9%99%a4%e7%ad%96%e7%95%a5%e6%b7%b1%e5%ba%a6%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/77799.html","title":{"rendered":"Redis\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u6df1\u5ea6\u89e3\u6790"},"content":{"rendered":"<h2>Redis\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u6df1\u5ea6\u89e3\u6790<\/h2>\n<p>\u5728Redis\u7684\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;\u7f13\u5b58\u8fc7\u671f\u3001\u5185\u5b58\u5360\u7528\u8fc7\u9ad8\u662f\u5f00\u53d1\u548c\u8fd0\u7ef4\u8fc7\u7a0b\u4e2d\u9ad8\u9891\u9047\u5230\u7684\u95ee\u9898&#xff0c;\u800c\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u662fRedis\u89e3\u51b3\u8be5\u95ee\u9898\u7684\u6838\u5fc3\u673a\u5236\u3002\u5408\u7406\u7684\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u80fd\u5728CPU\u8d44\u6e90\u5360\u7528\u548c\u5185\u5b58\u5229\u7528\u7387\u4e4b\u95f4\u627e\u5230\u6700\u4f73\u5e73\u8861&#xff0c;\u4e5f\u662fRedis\u9ad8\u6027\u80fd\u7684\u91cd\u8981\u4fdd\u969c\u3002\u672c\u6587\u5c06\u4ece\u8fc7\u671f\u952e\u7684\u57fa\u7840\u64cd\u4f5c\u3001\u6838\u5fc3\u5220\u9664\u7b56\u7565\u3001Redis\u5b9e\u9645\u5b9e\u73b0\u3001\u7279\u6b8a\u573a\u666f\u5904\u7406\u7b49\u65b9\u9762\u5168\u9762\u89e3\u6790\u3002<\/p>\n<h3>\u4e00\u3001\u57fa\u7840\u94fa\u57ab&#xff1a;Redis\u8fc7\u671f\u952e\u7684\u8bbe\u7f6e\u4e0e\u7ba1\u7406<\/h3>\n<p>\u8981\u7406\u89e3\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565&#xff0c;\u9996\u5148\u9700\u8981\u638c\u63e1Redis\u4e2d\u8fc7\u671f\u952e\u7684\u57fa\u672c\u64cd\u4f5c&#xff0c;\u4ee5\u53caRedis\u5e95\u5c42\u5982\u4f55\u5b58\u50a8\u8fc7\u671f\u952e\u4fe1\u606f\u3002<\/p>\n<h4>1.1 \u8fc7\u671f\u65f6\u95f4\u7684\u8bbe\u7f6e\u4e0e\u67e5\u8be2<\/h4>\n<p>Redis\u63d0\u4f9b\u4e86\u591a\u79cd\u547d\u4ee4\u4e3akey\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4&#xff0c;\u540c\u65f6\u652f\u6301\u67e5\u8be2\u5269\u4f59\u5b58\u6d3b\u65f6\u95f4\u3001\u53d6\u6d88\u8fc7\u671f\u65f6\u95f4\u7b49\u64cd\u4f5c&#xff0c;\u8986\u76d6\u79d2\/\u6beb\u79d2\u3001\u65f6\u95f4\u6233\u7b49\u591a\u79cd\u7ef4\u5ea6\u3002<\/p>\n<table>\n<tr>\u64cd\u4f5c\u7c7b\u578b\u547d\u4ee4\u8bf4\u660e\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>\u8bbe\u7f6e\u8fc7\u671f&#xff08;\u79d2&#xff09;<\/td>\n<td>expire key n<\/td>\n<td>\u8bbekey\u5728n\u79d2\u540e\u8fc7\u671f<\/td>\n<td>expire user:1 60<\/td>\n<\/tr>\n<tr>\n<td>\u8bbe\u7f6e\u8fc7\u671f&#xff08;\u6beb\u79d2&#xff09;<\/td>\n<td>pexpire key n<\/td>\n<td>\u8bbekey\u5728n\u6beb\u79d2\u540e\u8fc7\u671f<\/td>\n<td>pexpire user:1 60000<\/td>\n<\/tr>\n<tr>\n<td>\u65f6\u95f4\u6233\u8fc7\u671f&#xff08;\u79d2&#xff09;<\/td>\n<td>expireat key n<\/td>\n<td>\u8bbekey\u5728\u79d2\u7ea7\u65f6\u95f4\u6233n\u540e\u8fc7\u671f<\/td>\n<td>expireat user:1 1736179200<\/td>\n<\/tr>\n<tr>\n<td>\u65f6\u95f4\u6233\u8fc7\u671f&#xff08;\u6beb\u79d2&#xff09;<\/td>\n<td>pexpireat key n<\/td>\n<td>\u8bbekey\u5728\u6beb\u79d2\u7ea7\u65f6\u95f4\u6233n\u540e\u8fc7\u671f<\/td>\n<td>pexpireat user:1 1736179200123<\/td>\n<\/tr>\n<tr>\n<td>\u8bbe\u503c\u540c\u65f6\u8fc7\u671f&#xff08;\u79d2&#xff09;<\/td>\n<td>set key value ex n<\/td>\n<td>\u539f\u5b50\u64cd\u4f5c&#xff0c;\u8bbe\u503c\u5e76\u6307\u5b9a\u79d2\u7ea7\u8fc7\u671f<\/td>\n<td>set session 123 ex 60<\/td>\n<\/tr>\n<tr>\n<td>\u8bbe\u503c\u540c\u65f6\u8fc7\u671f&#xff08;\u79d2&#xff09;<\/td>\n<td>setex key n value<\/td>\n<td>\u4e13\u7528\u547d\u4ee4&#xff0c;\u7b49\u4ef7\u4e8e\u4e0a\u8ff0ex\u64cd\u4f5c<\/td>\n<td>setex token 300 abc123<\/td>\n<\/tr>\n<tr>\n<td>\u67e5\u8be2\u5269\u4f59\u65f6\u95f4<\/td>\n<td>ttl key<\/td>\n<td>\u8fd4\u56de\u5269\u4f59\u79d2\u6570&#xff0c;-1\u6c38\u4e0d\u8fc7\u671f&#xff0c;-2\u5df2\u8fc7\u671f\/\u4e0d\u5b58\u5728<\/td>\n<td>ttl user:1 \u2192 (integer)56<\/td>\n<\/tr>\n<tr>\n<td>\u53d6\u6d88\u8fc7\u671f\u65f6\u95f4<\/td>\n<td>persist key<\/td>\n<td>\u79fb\u9664key\u7684\u8fc7\u671f\u65f6\u95f4&#xff0c;\u53d8\u4e3a\u6c38\u4e45\u6709\u6548<\/td>\n<td>persist user:1 \u2192 (integer)1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>1.2 \u8fc7\u671f\u5b57\u5178&#xff1a;Redis\u5e95\u5c42\u7684\u8fc7\u671f\u952e\u5b58\u50a8<\/h4>\n<p>\u5f53\u4e3akey\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\u540e&#xff0c;Redis\u4f1a\u5c06\u8be5key\u7684\u8fc7\u671f\u4fe1\u606f\u5b58\u50a8\u5728\u8fc7\u671f\u5b57\u5178&#xff08;expires dict&#xff09; \u4e2d&#xff0c;\u8be5\u5b57\u5178\u662fRedis\u6570\u636e\u5e93\u7ed3\u6784redisDb\u7684\u6838\u5fc3\u7ec4\u6210\u90e8\u5206\u3002<\/p>\n<p>\u5e95\u5c42\u7ed3\u6784\u5b9a\u4e49\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">redisDb<\/span><span class=\"token punctuation\">{<\/span><br \/>\n dict <span class=\"token operator\">*<\/span>dict<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5b58\u653e\u6570\u636e\u5e93\u6240\u6709\u952e\u503c\u5bf9<\/span><br \/>\n dict <span class=\"token operator\">*<\/span>expires<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u8fc7\u671f\u5b57\u5178&#xff0c;\u5b58\u653ekey\u7684\u8fc7\u671f\u65f6\u95f4<\/span><br \/>\n <span class=\"token comment\">\/\/ \u5176\u4ed6\u5c5e\u6027&#8230;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span>redisDb<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fc7\u671f\u5b57\u5178\u7684\u6838\u5fc3\u7279\u5f81&#xff1a;<\/p>\n<ul>\n<li>key&#xff1a;\u6307\u5411Redis\u4e2d\u952e\u5bf9\u8c61\u7684\u6307\u9488&#xff0c;\u4e0edict\u4e2d\u7684key\u4e00\u4e00\u5bf9\u5e94&#xff1b;<\/li>\n<li>value&#xff1a;long long\u578b\u6574\u6570&#xff0c;\u5b58\u50a8key\u7684\u6beb\u79d2\u7ea7Unix\u65f6\u95f4\u6233&#xff1b;<\/li>\n<li>\u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;\u57fa\u4e8e\u54c8\u5e0c\u8868\u5b9e\u73b0&#xff0c;\u67e5\u8be2\u3001\u65b0\u589e\u3001\u5220\u9664\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3aO(1)\u3002<\/li>\n<\/ul>\n<p>Redis\u5224\u65ad\u4e00\u4e2akey\u662f\u5426\u8fc7\u671f\u7684\u903b\u8f91\u975e\u5e38\u7b80\u5355&#xff1a;<\/p>\n<li>\u68c0\u67e5\u8be5key\u662f\u5426\u5b58\u5728\u4e8e\u8fc7\u671f\u5b57\u5178\u4e2d&#xff0c;\u4e0d\u5b58\u5728\u5219\u6c38\u4e0d\u8fc7\u671f&#xff1b;<\/li>\n<li>\u82e5\u5b58\u5728&#xff0c;\u5bf9\u6bd4\u5f53\u524d\u7cfb\u7edf\u6beb\u79d2\u65f6\u95f4\u6233\u4e0e\u8fc7\u671f\u5b57\u5178\u4e2d\u7684\u65f6\u95f4\u6233&#xff0c;\u5f53\u524d\u65f6\u95f4\u66f4\u5927\u5219\u5224\u5b9a\u4e3a\u8fc7\u671f\u3002<\/li>\n<h3>\u4e8c\u3001\u4e09\u5927\u6838\u5fc3\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565<\/h3>\n<p>\u4e1a\u754c\u4e3b\u6d41\u7684\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u5206\u4e3a\u5b9a\u65f6\u5220\u9664\u3001\u60f0\u6027\u5220\u9664\u3001\u5b9a\u671f\u5220\u9664\u4e09\u79cd&#xff0c;\u4e09\u8005\u7684\u6838\u5fc3\u5dee\u5f02\u5728\u4e8e\u5220\u9664\u65f6\u673a\u548c\u8d44\u6e90\u5360\u7528\u503e\u5411&#xff0c;\u5206\u522b\u5bf9\u5e94\u201c\u5185\u5b58\u4f18\u5148\u201d\u3001\u201cCPU\u4f18\u5148\u201d\u3001\u201c\u6298\u4e2d\u5e73\u8861\u201d\u4e09\u79cd\u8bbe\u8ba1\u601d\u8def\u3002<\/p>\n<h4>2.1 \u5b9a\u65f6\u5220\u9664&#xff1a;\u5185\u5b58\u53cb\u597d&#xff0c;CPU\u4e0d\u53cb\u597d<\/h4>\n<h5>\u6838\u5fc3\u539f\u7406<\/h5>\n<p>\u5728\u4e3akey\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\u7684\u540c\u65f6&#xff0c;\u521b\u5efa\u4e00\u4e2a\u5b9a\u65f6\u4e8b\u4ef6&#xff0c;\u5f53\u65f6\u95f4\u5230\u8fbe\u8fc7\u671f\u70b9\u65f6&#xff0c;\u7531Redis\u4e8b\u4ef6\u5904\u7406\u5668\u81ea\u52a8\u6267\u884c\u8be5key\u7684\u5220\u9664\u64cd\u4f5c\u3002<\/p>\n<h5>\u6267\u884c\u6d41\u7a0b\u56fe<\/h5>\n<p>\u8bbe\u7f6ekey\u8fc7\u671f\u65f6\u95f4 \u2192 \u521b\u5efa\u5b9a\u65f6\u4e8b\u4ef6&#xff08;\u7ed1\u5b9a\u8fc7\u671f\u65f6\u95f4\u548c\u5220\u9664\u64cd\u4f5c&#xff09;\u2192 \u65f6\u95f4\u5230\u8fbe \u2192 \u4e8b\u4ef6\u5904\u7406\u5668\u6267\u884c\u5220\u9664 \u2192 key\u88ab\u6e05\u7406<\/p>\n<h5>\u4f18\u7f3a\u70b9<\/h5>\n<ul>\n<li>\u2705 \u4f18\u70b9&#xff1a;\u8fc7\u671fkey\u88ab\u7acb\u5373\u5220\u9664&#xff0c;\u65e0\u5185\u5b58\u65e0\u6548\u5360\u7528&#xff0c;\u5bf9\u5185\u5b58\u5229\u7528\u7387\u6700\u53cb\u597d&#xff1b;<\/li>\n<li>\u274c \u7f3a\u70b9&#xff1a;\u82e5\u5b58\u5728\u5927\u91cf\u8fc7\u671fkey&#xff0c;\u4f1a\u521b\u5efa\u5927\u91cf\u5b9a\u65f6\u4e8b\u4ef6&#xff0c;\u9891\u7e41\u89e6\u53d1\u5220\u9664\u64cd\u4f5c&#xff0c;\u5360\u7528\u5927\u91cfCPU\u8d44\u6e90&#xff0c;\u4e25\u91cd\u5f71\u54cdRedis\u7684\u6838\u5fc3\u8bfb\u5199\u6027\u80fd\u3002<\/li>\n<\/ul>\n<h5>\u9002\u7528\u573a\u666f<\/h5>\n<p>\u51e0\u4e4e\u65e0\u5b9e\u9645\u9002\u7528\u573a\u666f&#xff0c;Redis\u672a\u91c7\u7528\u8be5\u7b56\u7565\u3002<\/p>\n<h4>2.2 \u60f0\u6027\u5220\u9664&#xff1a;CPU\u53cb\u597d&#xff0c;\u5185\u5b58\u53ef\u80fd\u6d6a\u8d39<\/h4>\n<h5>\u6838\u5fc3\u539f\u7406<\/h5>\n<p>Redis\u4e0d\u4e3b\u52a8\u68c0\u6d4b\u548c\u5220\u9664\u8fc7\u671fkey&#xff0c;\u53ea\u6709\u5f53\u5ba2\u6237\u7aef\u8bbf\u95ee\u8be5key\u65f6&#xff0c;\u624d\u4f1a\u68c0\u67e5\u5176\u662f\u5426\u8fc7\u671f&#xff1b;\u82e5\u8fc7\u671f\u5219\u7acb\u5373\u5220\u9664&#xff0c;\u672a\u8fc7\u671f\u5219\u6b63\u5e38\u8fd4\u56de\u952e\u503c\u5bf9\u3002<\/p>\n<h5>\u6267\u884c\u6d41\u7a0b\u56fe<\/h5>\n<p>\u5ba2\u6237\u7aef\u53d1\u8d77key\u8bbf\u95ee\u8bf7\u6c42 \u2192 Redis\u8c03\u7528expireIfNeeded\u51fd\u6570\u68c0\u67e5\u8fc7\u671f\u72b6\u6001 \u2192 \u672a\u8fc7\u671f\u2192\u8fd4\u56de\u952e\u503c\u5bf9<br \/>\n                                                          \u2193 \u8fc7\u671f<br \/>\n                                                     \u5220\u9664key&#xff08;\u540c\u6b65\/\u5f02\u6b65&#xff09;\u2192 \u8fd4\u56denull\u7ed9\u5ba2\u6237\u7aef<\/p>\n<h5>\u4f18\u7f3a\u70b9<\/h5>\n<ul>\n<li>\u2705 \u4f18\u70b9&#xff1a;\u4ec5\u5728\u8bbf\u95ee\u65f6\u6267\u884c\u68c0\u67e5&#xff0c;\u51e0\u4e4e\u4e0d\u5360\u7528\u989d\u5916CPU\u8d44\u6e90&#xff0c;\u5b9e\u73b0\u7b80\u5355&#xff0c;\u5bf9CPU\u6700\u53cb\u597d&#xff1b;<\/li>\n<li>\u274c \u7f3a\u70b9&#xff1a;\u82e5\u8fc7\u671fkey\u957f\u671f\u4e0d\u88ab\u8bbf\u95ee&#xff0c;\u4f1a\u4e00\u76f4\u5360\u7528\u5185\u5b58&#xff0c;\u9020\u6210\u5185\u5b58\u6cc4\u6f0f\u98ce\u9669&#xff0c;\u6781\u7aef\u60c5\u51b5\u4e0b\u4f1a\u5bfc\u81f4Redis\u5185\u5b58\u7206\u6ee1\u3002<\/li>\n<\/ul>\n<h5>\u5173\u952e\u5b9e\u73b0<\/h5>\n<p>Redis\u901a\u8fc7\u6838\u5fc3\u51fd\u6570expireIfNeeded\u5b9e\u73b0\u60f0\u6027\u5220\u9664&#xff0c;Redis4.0&#043;\u652f\u6301\u901a\u8fc7lazyfree_lazy_expire\u53c2\u6570\u914d\u7f6e\u540c\u6b65\u5220\u9664\u6216\u5f02\u6b65\u5220\u9664&#xff0c;\u907f\u514d\u5220\u9664\u5927key\u65f6\u963b\u585e\u4e3b\u7ebf\u7a0b\u3002<\/p>\n<p>\u6838\u5fc3\u4ee3\u7801\u7247\u6bb5&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">expireIfNeeded<\/span><span class=\"token punctuation\">(<\/span>redisDb <span class=\"token operator\">*<\/span>db<span class=\"token punctuation\">,<\/span> robj <span class=\"token operator\">*<\/span>key<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n <span class=\"token class-name\">mstime_t<\/span> when <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">getExpire<\/span><span class=\"token punctuation\">(<\/span>db<span class=\"token punctuation\">,<\/span> key<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n <span class=\"token class-name\">mstime_t<\/span> now <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">mstime<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>when <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u65e0\u8fc7\u671f\u65f6\u95f4&#xff0c;\u76f4\u63a5\u8fd4\u56de<\/span><br \/>\n <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>now <span class=\"token operator\">&lt;&#061;<\/span> when<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u672a\u8fc7\u671f&#xff0c;\u76f4\u63a5\u8fd4\u56de<\/span><br \/>\n <span class=\"token comment\">\/\/ \u4e3b\u4ece\u6a21\u5f0f\u4e0b&#xff0c;\u4ece\u5e93\u4e0d\u4e3b\u52a8\u5220\u9664&#xff0c;\u4ea4\u7ed9\u4e3b\u5e93\u5904\u7406<\/span><br \/>\n <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>server<span class=\"token punctuation\">.<\/span>masterhost <span class=\"token operator\">!&#061;<\/span> <span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n server<span class=\"token punctuation\">.<\/span>stat_expiredkeys<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u7edf\u8ba1\u8fc7\u671f\u5220\u9664\u7684key\u6570\u91cf<\/span><br \/>\n <span class=\"token comment\">\/\/ \u6839\u636e\u914d\u7f6e\u9009\u62e9\u540c\u6b65\/\u5f02\u6b65\u5220\u9664<\/span><br \/>\n <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>server<span class=\"token punctuation\">.<\/span>lazyfree_lazy_expire<span class=\"token punctuation\">)<\/span><br \/>\n <span class=\"token function\">dbAsyncDelete<\/span><span class=\"token punctuation\">(<\/span>db<span class=\"token punctuation\">,<\/span> key<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5f02\u6b65\u5220\u9664<\/span><br \/>\n <span class=\"token keyword\">else<\/span><br \/>\n <span class=\"token function\">dbSyncDelete<\/span><span class=\"token punctuation\">(<\/span>db<span class=\"token punctuation\">,<\/span> key<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u540c\u6b65\u5220\u9664<\/span><br \/>\n <span class=\"token function\">notifyKeyspaceEvent<\/span><span class=\"token punctuation\">(<\/span>NOTIFY_EXPIRED<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;expired&#034;<\/span><span class=\"token punctuation\">,<\/span> key<span class=\"token punctuation\">,<\/span> db<span class=\"token operator\">-&gt;<\/span>id<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n <span class=\"token keyword\">return<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>2.3 \u5b9a\u671f\u5220\u9664&#xff1a;\u6298\u4e2d\u65b9\u6848&#xff0c;\u5e73\u8861CPU\u4e0e\u5185\u5b58<\/h4>\n<h5>\u6838\u5fc3\u539f\u7406<\/h5>\n<p>Redis\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4&#xff0c;\u968f\u673a\u4ece\u8fc7\u671f\u5b57\u5178\u4e2d\u62bd\u53d6\u4e00\u5b9a\u6570\u91cf\u7684key\u8fdb\u884c\u8fc7\u671f\u68c0\u67e5&#xff0c;\u5220\u9664\u5176\u4e2d\u7684\u8fc7\u671fkey&#xff1b;\u540c\u65f6\u901a\u8fc7\u9650\u5236\u6267\u884c\u65f6\u957f\u548c\u9891\u7387&#xff0c;\u907f\u514d\u5bf9CPU\u9020\u6210\u8fc7\u5ea6\u5360\u7528\u3002<\/p>\n<h5>\u6267\u884c\u6d41\u7a0b\u56fe<\/h5>\n<p>Redis\u4e3b\u7ebf\u7a0b\u89e6\u53d1\u5b9a\u671f\u68c0\u67e5&#xff08;\u7531serverCron\u8c03\u5ea6&#xff09;\u2192 \u4ece\u8fc7\u671f\u5b57\u5178\u968f\u673a\u62bd\u53d620\u4e2akey \u2192 \u68c0\u67e5\u5e76\u5220\u9664\u8fc7\u671fkey<br \/>\n\u2192 \u7edf\u8ba1\u8fc7\u671fkey\u5360\u6bd4 \u2192 \u5360\u6bd4&gt;25%\u2192\u91cd\u590d\u62bd\u6837\u5220\u9664 \u2193 \u5360\u6bd4\u226425%\/\u6267\u884c\u65f6\u95f4\u226525ms<br \/>\n                                          \u7ed3\u675f\u672c\u8f6e\u5b9a\u671f\u5220\u9664<\/p>\n<h5>\u6838\u5fc3\u914d\u7f6e\u4e0e\u89c4\u5219<\/h5>\n<p>\u5b9a\u671f\u5220\u9664\u7684\u6267\u884c\u903b\u8f91\u7531Redis\u5e95\u5c42\u8c03\u5ea6\u5668serverCron\u63a7\u5236&#xff0c;\u6838\u5fc3\u89c4\u5219\u548c\u914d\u7f6e\u5982\u4e0b&#xff1a;<\/p>\n<li>\u6267\u884c\u9891\u7387&#xff1a;\u9ed8\u8ba4\u6bcf\u79d2\u6267\u884c10\u6b21&#xff0c;\u53ef\u901a\u8fc7redis.conf\u4e2d\u7684hz\u53c2\u6570\u4fee\u6539&#xff08;\u53d6\u503c1~500&#xff09;&#xff0c;hz\u8d8a\u9ad8&#xff0c;\u626b\u63cf\u8d8a\u9891\u7e41&#xff0c;\u8fc7\u671fkey\u6e05\u7406\u8d8a\u5feb&#xff0c;\u4f46CPU\u5360\u7528\u8d8a\u9ad8&#xff1b;<\/li>\n<li>\u62bd\u6837\u6570\u91cf&#xff1a;\u6e90\u7801\u5199\u6b7b\u4e3a20\u4e2akey&#xff0c;\u56fa\u5b9a\u4e0d\u53ef\u914d\u7f6e&#xff1b;<\/li>\n<li>\u5faa\u73af\u6761\u4ef6&#xff1a;\u82e5\u672c\u8f6e\u62bd\u6837\u7684\u8fc7\u671fkey\u5360\u6bd4\u8d85\u8fc725%&#xff0c;\u5219\u7ee7\u7eed\u62bd\u6837\u5220\u9664&#xff0c;\u786e\u4fdd\u8fc7\u671fkey\u88ab\u6709\u6548\u6e05\u7406&#xff1b;<\/li>\n<li>\u65f6\u95f4\u4e0a\u9650&#xff1a;\u5355\u6b21\u5b9a\u671f\u5220\u9664\u7684\u6267\u884c\u65f6\u95f4\u4e0d\u8d85\u8fc725ms&#xff0c;\u907f\u514d\u5faa\u73af\u8fc7\u5ea6\u5bfc\u81f4Redis\u4e3b\u7ebf\u7a0b\u5361\u6b7b\u3002<\/li>\n<h5>\u4f18\u7f3a\u70b9<\/h5>\n<ul>\n<li>\u2705 \u4f18\u70b9&#xff1a;\u901a\u8fc7\u9891\u7387\u3001\u6570\u91cf\u3001\u65f6\u95f4\u4e09\u91cd\u9650\u5236&#xff0c;\u5e73\u8861\u4e86CPU\u5360\u7528\u548c\u5185\u5b58\u6d6a\u8d39&#xff0c;\u662f\u5b9a\u65f6\u5220\u9664\u548c\u60f0\u6027\u5220\u9664\u7684\u6298\u4e2d\u65b9\u6848&#xff1b;<\/li>\n<li>\u274c \u7f3a\u70b9&#xff1a;\u968f\u673a\u62bd\u6837\u53ef\u80fd\u5bfc\u81f4\u90e8\u5206\u8fc7\u671fkey\u672a\u88ab\u68c0\u6d4b\u5230&#xff0c;\u4ecd\u4f1a\u5b58\u5728\u4e00\u5b9a\u7684\u5185\u5b58\u65e0\u6548\u5360\u7528&#xff1b;\u4e14hz\u53c2\u6570\u9700\u8981\u6839\u636e\u4e1a\u52a1\u573a\u666f\u7cbe\u7ec6\u914d\u7f6e&#xff0c;\u914d\u7f6e\u4e0d\u5f53\u4f1a\u5f71\u54cd\u6548\u679c\u3002<\/li>\n<\/ul>\n<h3>\u4e09\u3001Redis\u7684\u6700\u7ec8\u9009\u62e9&#xff1a;\u60f0\u6027\u5220\u9664&#043;\u5b9a\u671f\u5220\u9664\u7ec4\u5408\u7b56\u7565<\/h3>\n<p>Redis\u5e76\u672a\u9009\u62e9\u5355\u4e00\u7684\u5220\u9664\u7b56\u7565&#xff0c;\u800c\u662f\u91c7\u7528\u60f0\u6027\u5220\u9664&#043;\u5b9a\u671f\u5220\u9664\u7684\u7ec4\u5408\u7b56\u7565&#xff0c;\u5145\u5206\u53d1\u6325\u4e24\u8005\u7684\u4f18\u70b9&#xff0c;\u89c4\u907f\u5404\u81ea\u7684\u7f3a\u70b9&#xff0c;\u5728\u5408\u7406\u4f7f\u7528CPU\u65f6\u95f4\u548c\u5c3d\u91cf\u907f\u514d\u5185\u5b58\u6d6a\u8d39\u4e4b\u95f4\u53d6\u5f97\u6700\u4f73\u5e73\u8861\u3002<\/p>\n<h4>3.1 \u7ec4\u5408\u7b56\u7565\u6574\u4f53\u6267\u884c\u6d41\u7a0b\u56fe<\/h4>\n<p>Redis\u542f\u52a8 \u2192 \u521d\u59cb\u5316\u8fc7\u671f\u5b57\u5178&#xff0c;\u7ef4\u62a4key\u8fc7\u671f\u4fe1\u606f<br \/>\n\u251c\u2500 \u5ba2\u6237\u7aef\u8bbf\u95eekey \u2192 \u60f0\u6027\u5220\u9664&#xff1a;\u6267\u884cexpireIfNeeded\u68c0\u67e5&#xff0c;\u8fc7\u671f\u5219\u5220\u9664<br \/>\n\u2514\u2500 \u540e\u53f0\u5b9a\u671f\u8c03\u5ea6&#xff08;hz\u63a7\u5236\u9891\u7387&#xff09;\u2192 \u5b9a\u671f\u5220\u9664&#xff1a;\u968f\u673a\u62bd\u6837\u68c0\u67e5&#xff0c;\u5220\u9664\u8fc7\u671fkey<br \/>\n     \u2193 \u5185\u5b58\u5360\u7528\u6301\u7eed\u5347\u9ad8 \u2192 \u89e6\u53d1\u5185\u5b58\u6dd8\u6c70\u7b56\u7565&#xff08;maxmemory\u63a7\u5236&#xff09;<\/p>\n<h4>3.2 \u7ec4\u5408\u7b56\u7565\u7684\u6838\u5fc3\u4f18\u52bf<\/h4>\n<li>CPU\u5360\u7528\u53ef\u63a7&#xff1a;\u60f0\u6027\u5220\u9664\u4ec5\u5728\u8bbf\u95ee\u65f6\u6267\u884c\u68c0\u67e5&#xff0c;\u5b9a\u671f\u5220\u9664\u901a\u8fc7\u4e09\u91cd\u9650\u5236\u63a7\u5236CPU\u6d88\u8017&#xff0c;\u4e0d\u4f1a\u5f71\u54cdRedis\u6838\u5fc3\u4e1a\u52a1&#xff1b;<\/li>\n<li>\u5185\u5b58\u65e0\u6548\u5360\u7528\u53ef\u63a7&#xff1a;\u5b9a\u671f\u5220\u9664\u4e3b\u52a8\u6e05\u7406\u5927\u90e8\u5206\u8fc7\u671fkey&#xff0c;\u60f0\u6027\u5220\u9664\u515c\u5e95\u6e05\u7406\u201c\u6f0f\u7f51\u4e4b\u9c7c\u201d&#xff0c;\u907f\u514d\u8fc7\u671fkey\u957f\u671f\u5806\u79ef&#xff1b;<\/li>\n<li>\u5b9e\u73b0\u8f7b\u91cf\u9ad8\u6548&#xff1a;\u57fa\u4e8e\u8fc7\u671f\u5b57\u5178\u7684O(1)\u67e5\u8be2&#xff0c;\u642d\u914d\u7b80\u5355\u7684\u62bd\u6837\u548c\u68c0\u67e5\u903b\u8f91&#xff0c;\u5e95\u5c42\u5b9e\u73b0\u65e0\u590d\u6742\u5f00\u9500\u3002<\/li>\n<h3>\u56db\u3001\u7279\u6b8a\u573a\u666f&#xff1a;\u8fc7\u671f\u952e\u7684\u5904\u7406\u89c4\u5219<\/h3>\n<p>\u5728Redis\u7684\u4e3b\u4ece\u6a21\u5f0f\u548c\u6301\u4e45\u5316&#xff08;RDB\/AOF&#xff09; \u573a\u666f\u4e0b&#xff0c;\u8fc7\u671f\u952e\u7684\u5904\u7406\u6709\u7279\u6b8a\u89c4\u5219&#xff0c;\u8fd9\u662f\u5f00\u53d1\u548c\u8fd0\u7ef4\u4e2d\u5bb9\u6613\u8e29\u5751\u7684\u70b9&#xff0c;\u5fc5\u987b\u91cd\u70b9\u638c\u63e1\u3002<\/p>\n<h4>4.1 \u4e3b\u4ece\u6a21\u5f0f\u4e0b\u7684\u8fc7\u671f\u952e\u5904\u7406<\/h4>\n<p>\u4e3b\u4ece\u6a21\u5f0f\u4e2d&#xff0c;\u4ece\u5e93\u4e0d\u4e3b\u52a8\u6267\u884c\u8fc7\u671f\u952e\u5220\u9664\u64cd\u4f5c&#xff0c;\u6240\u6709\u8fc7\u671f\u952e\u7684\u5220\u9664\u7531\u4e3b\u5e93\u7edf\u4e00\u63a7\u5236&#xff0c;\u4fdd\u8bc1\u4e3b\u4ece\u6570\u636e\u4e00\u81f4\u6027&#xff1a;<\/p>\n<li>\u4e3b\u5e93\u68c0\u6d4b\u5230key\u8fc7\u671f\u540e&#xff0c;\u6267\u884c\u5220\u9664\u64cd\u4f5c&#xff0c;\u5e76\u5728AOF\u6587\u4ef6\u4e2d\u8ffd\u52a0\u4e00\u6761del\u6307\u4ee4&#xff1b;<\/li>\n<li>\u4e3b\u5e93\u901a\u8fc7\u4e3b\u4ece\u540c\u6b65&#xff0c;\u5c06del\u6307\u4ee4\u53d1\u9001\u7ed9\u6240\u6709\u4ece\u5e93&#xff1b;<\/li>\n<li>\u4ece\u5e93\u6267\u884cdel\u6307\u4ee4&#xff0c;\u5b8c\u6210\u8fc7\u671fkey\u7684\u5220\u9664&#xff1b;<\/li>\n<li>\u82e5\u5ba2\u6237\u7aef\u76f4\u63a5\u8bbf\u95ee\u4ece\u5e93\u7684\u8fc7\u671fkey&#xff0c;\u4ece\u5e93\u4f1a\u8fd4\u56de\u539f\u503c&#xff0c;\u76f4\u5230\u6536\u5230\u4e3b\u5e93\u7684del\u6307\u4ee4\u3002<\/li>\n<h4>4.2 \u6301\u4e45\u5316\u573a\u666f\u4e0b\u7684\u8fc7\u671f\u952e\u5904\u7406<\/h4>\n<p>\u8fc7\u671f\u952e\u5728RDB\u548cAOF\u4e24\u79cd\u6301\u4e45\u5316\u6587\u4ef6\u4e2d\u7684\u5904\u7406\u903b\u8f91\u4e0d\u540c&#xff0c;\u5206\u4e3a\u751f\u6210\/\u5199\u5165\u9636\u6bb5\u548c\u52a0\u8f7d\/\u91cd\u5199\u9636\u6bb5\u3002<\/p>\n<h5>RDB\u6587\u4ef6\u4e2d\u7684\u8fc7\u671f\u952e<\/h5>\n<ul>\n<li>\u751f\u6210\u9636\u6bb5&#xff1a;\u6301\u4e45\u5316\u751f\u6210\u65b0RDB\u6587\u4ef6\u65f6&#xff0c;Redis\u4f1a\u5bf9key\u8fdb\u884c\u8fc7\u671f\u68c0\u67e5&#xff0c;\u8fc7\u671fkey\u4e0d\u4f1a\u88ab\u5199\u5165RDB\u6587\u4ef6&#xff1b;<\/li>\n<li>\u52a0\u8f7d\u9636\u6bb5&#xff1a;\u4e3b\u5e93\u52a0\u8f7dRDB\u65f6&#xff0c;\u4f1a\u8fc7\u6ee4\u8fc7\u671fkey&#xff1b;\u4ece\u5e93\u52a0\u8f7dRDB\u65f6&#xff0c;\u4f1a\u8f7d\u5165\u6240\u6709key&#xff08;\u5305\u62ec\u8fc7\u671fkey&#xff09;&#xff0c;\u4f46\u4e3b\u4ece\u540c\u6b65\u540e\u4f1a\u88ab\u6e05\u7406\u3002<\/li>\n<\/ul>\n<h5>AOF\u6587\u4ef6\u4e2d\u7684\u8fc7\u671f\u952e<\/h5>\n<ul>\n<li>\u5199\u5165\u9636\u6bb5&#xff1a;\u8fc7\u671fkey\u672a\u88ab\u5220\u9664\u65f6&#xff0c;AOF\u6587\u4ef6\u4f1a\u4fdd\u7559\u5176\u76f8\u5173\u8bb0\u5f55&#xff1b;\u5f53\u8fc7\u671fkey\u88ab\u5220\u9664\u540e&#xff0c;Redis\u4f1a\u5411AOF\u6587\u4ef6\u8ffd\u52a0del\u6307\u4ee4&#xff0c;\u6807\u8bb0\u8be5key\u7684\u5220\u9664&#xff1b;<\/li>\n<li>\u91cd\u5199\u9636\u6bb5&#xff1a;\u6267\u884cAOF\u91cd\u5199\u65f6&#xff0c;Redis\u4f1a\u68c0\u67e5\u5185\u5b58\u4e2d\u7684\u952e\u503c\u5bf9&#xff0c;\u8fc7\u671fkey\u4e0d\u4f1a\u88ab\u5199\u5165\u91cd\u5199\u540e\u7684AOF\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<h3>\u4e94\u3001\u5ef6\u4f38&#xff1a;\u8fc7\u671f\u5220\u9664\u7b56\u7565\u4e0e\u5185\u5b58\u6dd8\u6c70\u7b56\u7565\u7684\u914d\u5408<\/h3>\n<p>\u5f53Redis\u7684\u8fd0\u884c\u5185\u5b58\u8fbe\u5230maxmemory\u8bbe\u7f6e\u7684\u4e0a\u9650\u65f6&#xff0c;\u4ec5\u9760\u8fc7\u671f\u5220\u9664\u7b56\u7565\u65e0\u6cd5\u89e3\u51b3\u5185\u5b58\u95ee\u9898&#xff0c;\u6b64\u65f6\u4f1a\u89e6\u53d1\u5185\u5b58\u6dd8\u6c70\u7b56\u7565&#xff0c;\u5220\u9664\u7b26\u5408\u6761\u4ef6\u7684key\u4ee5\u91ca\u653e\u5185\u5b58\u3002\u8fc7\u671f\u5220\u9664\u7b56\u7565\u5904\u7406\u5df2\u8fc7\u671f\u7684key&#xff0c;\u800c\u5185\u5b58\u6dd8\u6c70\u7b56\u7565\u5904\u7406\u5185\u5b58\u8d85\u9650\u540e\u7684key&#xff0c;\u4e24\u8005\u914d\u5408\u6784\u6210Redis\u7684\u5b8c\u6574\u5185\u5b58\u7ba1\u7406\u4f53\u7cfb\u3002<\/p>\n<h4>5.1 \u5185\u5b58\u6dd8\u6c70\u7b56\u7565\u7684\u5206\u7c7b&#xff08;Redis4.0&#043;\u51718\u79cd&#xff09;<\/h4>\n<p>Redis\u7684\u5185\u5b58\u6dd8\u6c70\u7b56\u7565\u5206\u4e3a\u4e09\u5927\u7c7b&#xff0c;\u53ef\u901a\u8fc7maxmemory-policy\u53c2\u6570\u914d\u7f6e&#xff1a;<\/p>\n<li>\u4e0d\u6dd8\u6c70&#xff1a;noeviction&#xff08;Redis3.0\u540e\u9ed8\u8ba4&#xff09;&#xff0c;\u5185\u5b58\u8d85\u9650\u65f6\u62d2\u7edd\u6240\u6709\u5199\u64cd\u4f5c&#xff0c;\u4ec5\u5141\u8bb8\u8bfb\/\u5220\u9664&#xff1b;<\/li>\n<li>\u4ec5\u6dd8\u6c70\u5e26\u8fc7\u671f\u65f6\u95f4\u7684key&#xff1a;volatile-lru\/volatile-lfu\/volatile-random\/volatile-ttl&#xff1b;<\/li>\n<li>\u6dd8\u6c70\u6240\u6709key&#xff1a;allkeys-lru&#xff08;\u63a8\u8350\u901a\u7528\u573a\u666f&#xff09;\/allkeys-lfu\/allkeys-random\u3002<\/li>\n<h4>5.2 \u6838\u5fc3\u63a8\u8350\u914d\u7f6e<\/h4>\n<ul>\n<li>\u901a\u7528\u4e1a\u52a1\u573a\u666f&#xff1a;allkeys-lru&#xff0c;\u6dd8\u6c70\u6240\u6709key\u4e2d\u6700\u8fd1\u6700\u5c11\u4f7f\u7528\u7684&#xff0c;\u9002\u914d\u7edd\u5927\u591a\u6570\u7f13\u5b58\u573a\u666f&#xff1b;<\/li>\n<li>\u70ed\u70b9\u6570\u636e\u660e\u663e\u573a\u666f&#xff1a;allkeys-lfu&#xff0c;\u6dd8\u6c70\u8bbf\u95ee\u9891\u7387\u6700\u4f4e\u7684key&#xff0c;\u66f4\u8d34\u5408\u70ed\u70b9\u6570\u636e\u5206\u5e03&#xff1b;<\/li>\n<li>\u6570\u636e\u4e0d\u53ef\u4e22\u5931\u573a\u666f&#xff1a;noeviction&#xff0c;\u62d2\u7edd\u5199\u64cd\u4f5c&#xff0c;\u907f\u514d\u6570\u636e\u4e22\u5931&#xff1b;<\/li>\n<li>\u90e8\u5206\u6570\u636e\u6301\u4e45\u5316\u573a\u666f&#xff1a;volatile-lru&#xff0c;\u4ec5\u6dd8\u6c70\u5e26\u8fc7\u671f\u65f6\u95f4\u7684\u7f13\u5b58key&#xff0c;\u4fdd\u62a4\u6301\u4e45\u5316\u6570\u636e\u3002<\/li>\n<\/ul>\n<h4>5.3 \u5b9e\u6218\u914d\u7f6e\u547d\u4ee4<\/h4>\n<p># \u4e34\u65f6\u8bbe\u7f6e\u6700\u5927\u5185\u5b58\u4e3a512MB<br \/>\nCONFIG SET maxmemory 536870912<br \/>\n# \u4e34\u65f6\u8bbe\u7f6e\u5185\u5b58\u6dd8\u6c70\u7b56\u7565\u4e3aallkeys-lru<br \/>\nCONFIG SET maxmemory-policy allkeys-lru<br \/>\n# \u6301\u4e45\u5316\u914d\u7f6e&#xff08;\u5199\u5165redis.conf&#xff09;<br \/>\nCONFIG REWRITE<\/p>\n<h3>\u516d\u3001\u5b9e\u6218\u914d\u7f6e\u4e0e\u6027\u80fd\u4f18\u5316\u5efa\u8bae<\/h3>\n<p>\u7ed3\u5408\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u7684\u539f\u7406&#xff0c;\u7ed9\u51fa\u4ee5\u4e0b\u5b9e\u6218\u914d\u7f6e\u548c\u6027\u80fd\u4f18\u5316\u5efa\u8bae&#xff0c;\u9002\u914d\u5927\u591a\u6570\u751f\u4ea7\u73af\u5883&#xff1a;<\/p>\n<li>\u5408\u7406\u8bbe\u7f6ehz\u53c2\u6570&#xff1a;\u9ed8\u8ba4hz&#061;10&#xff0c;\u82e5Redis\u5185\u5b58\u538b\u529b\u5927\u3001\u8fc7\u671fkey\u591a&#xff0c;\u53ef\u9002\u5f53\u63d0\u9ad8\u81f320~50&#xff0c;\u52a0\u5feb\u5b9a\u671f\u5220\u9664\u9891\u7387&#xff1b;\u82e5CPU\u8d44\u6e90\u7d27\u5f20&#xff0c;\u4fdd\u6301\u9ed8\u8ba4\u5373\u53ef&#xff1b;<\/li>\n<li>\u5f00\u542f\u5f02\u6b65\u5220\u9664&#xff1a;Redis4.0&#043;\u8bbe\u7f6elazyfree_lazy_expire yes&#xff0c;\u907f\u514d\u5220\u9664\u5927key\u65f6\u963b\u585e\u4e3b\u7ebf\u7a0b&#xff1b;<\/li>\n<li>\u7cbe\u51c6\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4&#xff1a;\u6839\u636e\u4e1a\u52a1\u573a\u666f\u4e3akey\u8bbe\u7f6e\u5408\u7406\u7684TTL&#xff0c;\u907f\u514d\u65e0\u610f\u4e49\u7684\u957f\u671f\u7f13\u5b58&#xff0c;\u51cf\u5c11\u8fc7\u671f\u5b57\u5178\u7684\u4f53\u79ef&#xff1b;<\/li>\n<li>\u914d\u7f6e\u5408\u7406\u7684maxmemory&#xff1a;\u6839\u636e\u670d\u52a1\u5668\u5185\u5b58\u5927\u5c0f&#xff0c;\u8bbe\u7f6eRedis\u6700\u5927\u8fd0\u884c\u5185\u5b58&#xff08;\u5efa\u8bae\u9884\u755930%\u4ee5\u4e0a\u5185\u5b58\u7ed9\u7cfb\u7edf&#xff09;&#xff0c;\u907f\u514d\u5185\u5b58\u7206\u6ee1&#xff1b;<\/li>\n<li>\u4e3b\u4ece\u5206\u79bb&#xff1a;\u5c06\u8bfb\u8bf7\u6c42\u5206\u6563\u5230\u4ece\u5e93&#xff0c;\u4e3b\u5e93\u4e13\u6ce8\u4e8e\u5199\u64cd\u4f5c\u548c\u8fc7\u671f\u952e\u7ba1\u7406&#xff0c;\u63d0\u5347\u6574\u4f53\u6027\u80fd&#xff1b;<\/li>\n<li>\u76d1\u63a7\u8fc7\u671fkey\u6307\u6807&#xff1a;\u901a\u8fc7info stats\u67e5\u770bexpired_keys\u6307\u6807&#xff0c;\u76d1\u63a7\u8fc7\u671fkey\u7684\u5220\u9664\u6570\u91cf&#xff0c;\u53ca\u65f6\u8c03\u6574\u7b56\u7565\u914d\u7f6e\u3002<\/li>\n<h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<p>Redis\u7684\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u662f\u5176\u5185\u5b58\u7ba1\u7406\u7684\u6838\u5fc3&#xff0c;\u6838\u5fc3\u8981\u70b9\u53ef\u603b\u7ed3\u4e3a\u4ee5\u4e0b3\u70b9&#xff1a;<\/p>\n<li>\u5e95\u5c42\u57fa\u7840&#xff1a;\u901a\u8fc7\u8fc7\u671f\u5b57\u5178\u5b9e\u73b0\u8fc7\u671fkey\u7684O(1)\u67e5\u8be2&#xff0c;\u662f\u6240\u6709\u5220\u9664\u7b56\u7565\u7684\u57fa\u7840&#xff1b;<\/li>\n<li>\u6838\u5fc3\u7b56\u7565&#xff1a;\u91c7\u7528\u60f0\u6027\u5220\u9664&#043;\u5b9a\u671f\u5220\u9664\u7ec4\u5408\u7b56\u7565&#xff0c;\u5e73\u8861CPU\u8d44\u6e90\u5360\u7528\u548c\u5185\u5b58\u5229\u7528\u7387&#xff0c;\u662fRedis\u9ad8\u6027\u80fd\u7684\u91cd\u8981\u4fdd\u969c&#xff1b;<\/li>\n<li>\u573a\u666f\u9002\u914d&#xff1a;\u4e3b\u4ece\u6a21\u5f0f\u548c\u6301\u4e45\u5316\u573a\u666f\u4e0b\u6709\u7279\u6b8a\u7684\u8fc7\u671f\u952e\u5904\u7406\u89c4\u5219&#xff0c;\u5185\u5b58\u6dd8\u6c70\u7b56\u7565\u4e0e\u8fc7\u671f\u5220\u9664\u7b56\u7565\u914d\u5408&#xff0c;\u6784\u6210\u5b8c\u6574\u7684\u5185\u5b58\u7ba1\u7406\u4f53\u7cfb\u3002<\/li>\n","protected":false},"excerpt":{"rendered":"<p>Redis\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u6df1\u5ea6\u89e3\u6790<br \/>\n\u5728Redis\u7684\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;\u7f13\u5b58\u8fc7\u671f\u3001\u5185\u5b58\u5360\u7528\u8fc7\u9ad8\u662f\u5f00\u53d1\u548c\u8fd0\u7ef4\u8fc7\u7a0b\u4e2d\u9ad8\u9891\u9047\u5230\u7684\u95ee\u9898&#xff0c;\u800c\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u662fRedis\u89e3\u51b3\u8be5\u95ee\u9898\u7684\u6838\u5fc3\u673a\u5236\u3002\u5408\u7406\u7684\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u80fd\u5728CPU\u8d44\u6e90\u5360\u7528\u548c\u5185\u5b58\u5229\u7528\u7387\u4e4b\u95f4\u627e\u5230\u6700\u4f73\u5e73\u8861&#xff0c;\u4e5f\u662fRedis\u9ad8\u6027\u80fd\u7684\u91cd\u8981\u4fdd\u969c\u3002\u672c\u6587\u5c06\u4ece\u8fc7\u671f\u952e\u7684\u57fa\u7840\u64cd\u4f5c\u3001\u6838\u5fc3\u5220\u9664\u7b56\u7565\u3001Redis\u5b9e\u9645\u5b9e\u73b0\u3001\u7279\u6b8a\u573a\u666f\u5904\u7406\u7b49\u65b9\u9762\u5168\u9762\u89e3\u6790\u3002<br \/>\n\u4e00\u3001\u57fa\u7840\u94fa\u57ab&#xff1a;Redis\u8fc7\u671f\u952e\u7684\u8bbe\u7f6e\u4e0e\u7ba1\u7406<br \/>\n\u8981\u7406\u89e3\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565&amp;#<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,105,100,398,176],"topic":[],"class_list":["post-77799","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-redis","tag-100","tag-398","tag-176"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Redis\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/77799.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Redis\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Redis\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u6df1\u5ea6\u89e3\u6790 \u5728Redis\u7684\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;\u7f13\u5b58\u8fc7\u671f\u3001\u5185\u5b58\u5360\u7528\u8fc7\u9ad8\u662f\u5f00\u53d1\u548c\u8fd0\u7ef4\u8fc7\u7a0b\u4e2d\u9ad8\u9891\u9047\u5230\u7684\u95ee\u9898&#xff0c;\u800c\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u662fRedis\u89e3\u51b3\u8be5\u95ee\u9898\u7684\u6838\u5fc3\u673a\u5236\u3002\u5408\u7406\u7684\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u80fd\u5728CPU\u8d44\u6e90\u5360\u7528\u548c\u5185\u5b58\u5229\u7528\u7387\u4e4b\u95f4\u627e\u5230\u6700\u4f73\u5e73\u8861&#xff0c;\u4e5f\u662fRedis\u9ad8\u6027\u80fd\u7684\u91cd\u8981\u4fdd\u969c\u3002\u672c\u6587\u5c06\u4ece\u8fc7\u671f\u952e\u7684\u57fa\u7840\u64cd\u4f5c\u3001\u6838\u5fc3\u5220\u9664\u7b56\u7565\u3001Redis\u5b9e\u9645\u5b9e\u73b0\u3001\u7279\u6b8a\u573a\u666f\u5904\u7406\u7b49\u65b9\u9762\u5168\u9762\u89e3\u6790\u3002 \u4e00\u3001\u57fa\u7840\u94fa\u57ab&#xff1a;Redis\u8fc7\u671f\u952e\u7684\u8bbe\u7f6e\u4e0e\u7ba1\u7406 \u8981\u7406\u89e3\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565&amp;#\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/77799.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-25T06:49:48+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/77799.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/77799.html\",\"name\":\"Redis\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-25T06:49:48+00:00\",\"dateModified\":\"2026-02-25T06:49:48+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/77799.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/77799.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/77799.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Redis\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u6df1\u5ea6\u89e3\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Redis\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/77799.html","og_locale":"zh_CN","og_type":"article","og_title":"Redis\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Redis\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u6df1\u5ea6\u89e3\u6790 \u5728Redis\u7684\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;\u7f13\u5b58\u8fc7\u671f\u3001\u5185\u5b58\u5360\u7528\u8fc7\u9ad8\u662f\u5f00\u53d1\u548c\u8fd0\u7ef4\u8fc7\u7a0b\u4e2d\u9ad8\u9891\u9047\u5230\u7684\u95ee\u9898&#xff0c;\u800c\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u662fRedis\u89e3\u51b3\u8be5\u95ee\u9898\u7684\u6838\u5fc3\u673a\u5236\u3002\u5408\u7406\u7684\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u80fd\u5728CPU\u8d44\u6e90\u5360\u7528\u548c\u5185\u5b58\u5229\u7528\u7387\u4e4b\u95f4\u627e\u5230\u6700\u4f73\u5e73\u8861&#xff0c;\u4e5f\u662fRedis\u9ad8\u6027\u80fd\u7684\u91cd\u8981\u4fdd\u969c\u3002\u672c\u6587\u5c06\u4ece\u8fc7\u671f\u952e\u7684\u57fa\u7840\u64cd\u4f5c\u3001\u6838\u5fc3\u5220\u9664\u7b56\u7565\u3001Redis\u5b9e\u9645\u5b9e\u73b0\u3001\u7279\u6b8a\u573a\u666f\u5904\u7406\u7b49\u65b9\u9762\u5168\u9762\u89e3\u6790\u3002 \u4e00\u3001\u57fa\u7840\u94fa\u57ab&#xff1a;Redis\u8fc7\u671f\u952e\u7684\u8bbe\u7f6e\u4e0e\u7ba1\u7406 \u8981\u7406\u89e3\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565&amp;#","og_url":"https:\/\/www.wsisp.com\/helps\/77799.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-25T06:49:48+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/77799.html","url":"https:\/\/www.wsisp.com\/helps\/77799.html","name":"Redis\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-25T06:49:48+00:00","dateModified":"2026-02-25T06:49:48+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/77799.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/77799.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/77799.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Redis\u8fc7\u671f\u952e\u5220\u9664\u7b56\u7565\u6df1\u5ea6\u89e3\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/77799","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=77799"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/77799\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=77799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=77799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=77799"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=77799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}