{"id":5824,"date":"2024-11-14T11:12:33","date_gmt":"2024-11-14T03:12:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5824\/"},"modified":"2024-11-14T11:12:33","modified_gmt":"2024-11-14T03:12:33","slug":"redis%e5%86%85%e5%ad%98%e6%bb%a1%e4%ba%86%e6%80%8e%e4%b9%88%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5824\/","title":{"rendered":"redis\u5185\u5b58\u6ee1\u4e86\u600e\u4e48\u5904\u7406"},"content":{"rendered":"<p><strong> \u5185\u5b58\u5df2\u6ee1\u7684\u5904\u7406\u65b9\u6cd5<\/strong><\/p>\n<p>\u5f53 Redis \u5185\u5b58\u5df2\u6ee1\u65f6\uff0c\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u89e3\u51b3\uff1a<\/p>\n<p><strong>1. \u9a71\u9010\u7b56\u7565<\/strong><\/p>\n<p>Redis \u63d0\u4f9b\u4e86\u591a\u79cd\u9a71\u9010\u7b56\u7565\uff0c\u5f53\u5185\u5b58\u5df2\u6ee1\u65f6\uff0c\u4f1a\u81ea\u52a8\u6dd8\u6c70\u6570\u636e\u3002\u5e38\u7528\u7684\u7b56\u7565\u5305\u62ec\uff1a<\/p>\n<ul>\n<li> <strong>volatile-lru\uff1a<\/strong> \u6700\u8fd1\u6700\u5c11\u4f7f\u7528\u7684 <\/li>\n<li> <strong>volatile-ttl\uff1a<\/strong> \u8fc7\u671f\u65f6\u95f4\u6700\u957f\u7684\u952e\u503c\u5bf9<\/li>\n<li> <strong>allkeys-lru\uff1a<\/strong> \u4efb\u610f\u952e\u503c\u5bf9\uff0c\u6839\u636e LRU \u89c4\u5219\u6dd8\u6c70<\/li>\n<li> <strong>allkeys-random\uff1a<\/strong> \u4efb\u610f\u952e\u503c\u5bf9\uff0c\u6839\u636e\u968f\u673a\u89c4\u5219\u6dd8\u6c70<\/li>\n<\/ul>\n<p><strong>2. \u8c03\u9ad8 maxmemory<\/strong><\/p>\n<p>maxmemory \u662f Redis \u914d\u7f6e\u4e2d\u8bbe\u7f6e\u7684\u6700\u5927\u5185\u5b58\u9650\u5236\u3002\u53ef\u4ee5\u8003\u8651\u5c06 maxmemory \u8c03\u9ad8\uff0c\u4e3a Redis \u63d0\u4f9b\u66f4\u591a\u53ef\u7528\u5185\u5b58\u3002\u7136\u800c\uff0c\u8fd9\u9700\u8981\u670d\u52a1\u5668\u62e5\u6709\u8db3\u591f\u7684\u7269\u7406\u5185\u5b58\u6765\u652f\u6301\u3002<\/p>\n<p><strong>3. \u542f\u7528\u5185\u5b58\u6dd8\u6c70<\/strong><\/p>\n<p>\u5f53\u542f\u7528\u5185\u5b58\u6dd8\u6c70\u65f6\uff0cRedis \u4f1a\u5728\u5185\u5b58\u4e0d\u8db3\u65f6\u81ea\u52a8\u9a71\u9010\u952e\u503c\u5bf9\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u542f\u7528\uff1a<\/p>\n<pre>config set maxmemory-policy noeviction<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u624b\u52a8\u5220\u9664\u6570\u636e<\/strong><\/p>\n<p>\u53ef\u4ee5\u624b\u52a8\u5220\u9664\u4e0d\u5fc5\u8981\u7684\u952e\u503c\u5bf9\uff0c\u91ca\u653e\u5185\u5b58\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664\u5355\u4e2a\u952e\uff1a<\/p>\n<pre>del key<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6216\u8005\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664\u6240\u6709\u952e\uff1a<\/p>\n<pre>flushall<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u4f7f\u7528\u6301\u4e45\u5316<\/strong><\/p>\n<p>Redis \u53ef\u4ee5\u5c06\u6570\u636e\u6301\u4e45\u5316\u5230\u786c\u76d8\u6216\u5176\u4ed6\u4ecb\u8d28\u3002\u8fd9\u53ef\u4ee5\u91ca\u653e\u5185\u5b58\uff0c\u540c\u65f6\u786e\u4fdd\u6570\u636e\u5b89\u5168\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u542f\u7528\u6301\u4e45\u5316\uff1a<\/p>\n<pre>save<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u5347\u7ea7 Redis \u7248\u672c<\/strong><\/p>\n<p>\u8f83\u65b0\u7684 Redis \u7248\u672c\u5177\u6709\u66f4\u6709\u6548\u7684\u5185\u5b58\u7ba1\u7406\u3002\u5347\u7ea7\u5230\u8fd9\u4e9b\u7248\u672c\u53ef\u4ee5\u63d0\u9ad8\u5185\u5b58\u5229\u7528\u7387\u3002<\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u6570\u636e\u9a71\u9010\u53ef\u80fd\u4f1a\u5bfc\u81f4\uff0c\u56e0\u6b64\u5728\u5b9e\u65bd\u4efb\u4f55\u9a71\u9010\u7b56\u7565\u4e4b\u524d\uff0c\u8bf7\u52a1\u5fc5\u6743\u8861\u5229\u5f0a\u3002<\/li>\n<li>\u5728\u8c03\u6574 maxmemory \u65f6\uff0c\u8bf7\u8003\u8651\u670d\u52a1\u5668\u7684\u7269\u7406\u5185\u5b58\u5bb9\u91cf\u3002<\/li>\n<li>\u5b9a\u671f\u76d1\u63a7 Redis \u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u4ee5\u786e\u4fdd\u53ca\u65f6\u91c7\u53d6\u9884\u9632\u63aa\u65bd\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5185\u5b58\u6ee1\u4e86\u600e\u4e48\u5904\u7406\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5185\u5b58\u5df2\u6ee1\u7684\u5904\u7406\u65b9\u6cd5 \u5f53 Redis \u5185\u5b58\u5df2\u6ee1\u65f6\uff0c\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u89e3\u51b3\uff1a 1. \u9a71\u9010\u7b56\u7565 Redis \u63d0\u4f9b\u4e86\u591a\u79cd\u9a71\u9010\u7b56\u7565\uff0c\u5f53\u5185\u5b58\u5df2\u6ee1\u65f6\uff0c\u4f1a\u81ea\u52a8\u6dd8\u6c70\u6570\u636e\u3002\u5e38\u7528\u7684\u7b56\u7565\u5305\u62ec\uff1a volatile-lru\uff1a \u6700\u8fd1\u6700\u5c11\u4f7f\u7528\u7684 volatile-ttl\uff1a \u8fc7\u671f\u65f6\u95f4\u6700\u957f\u7684\u952e\u503c\u5bf9 allkeys-lru\uff1a \u4efb\u610f\u952e\u503c\u5bf9\uff0c\u6839\u636e LRU \u89c4\u5219\u6dd8\u6c70 allkeys-random\uff1a \u4efb\u610f\u952e\u503c\u5bf9\uff0c\u6839\u636e\u968f\u673a\u89c4\u5219\u6dd8\u6c70 2. \u8c03\u9ad8 maxmemory maxmemory \u662f Redis \u914d\u7f6e\u4e2d\u8bbe\u7f6e\u7684\u6700\u5927\u5185\u5b58\u9650\u5236\u3002\u53ef\u4ee5\u8003\u8651\u5c06 maxmemory \u8c03\u9ad8\uff0c\u4e3a Redis \u63d0\u4f9b\u66f4\u591a\u53ef\u7528\u5185\u5b58\u3002\u7136\u800c\uff0c\u8fd9\u9700\u8981\u670d\u52a1\u5668\u62e5\u6709\u8db3\u591f\u7684\u7269\u7406\u5185\u5b58\u6765\u652f\u6301\u3002 3. \u542f\u7528\u5185\u5b58\u6dd8\u6c70 \u5f53\u542f\u7528\u5185\u5b58\u6dd8\u6c70\u65f6\uff0cRedis \u4f1a\u5728\u5185\u5b58\u4e0d\u8db3\u65f6\u81ea\u52a8\u9a71\u9010\u952e\u503c\u5bf9\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u542f\u7528\uff1a config set maxmemory-policy noeviction \u767b\u5f55\u540e\u590d\u5236 4. \u624b\u52a8\u5220\u9664\u6570\u636e \u53ef\u4ee5\u624b\u52a8\u5220\u9664\u4e0d\u5fc5\u8981\u7684\u952e\u503c\u5bf9\uff0c\u91ca\u653e\u5185\u5b58\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664\u5355\u4e2a\u952e\uff1a del key \u767b\u5f55\u540e\u590d\u5236 \u6216\u8005\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664\u6240\u6709\u952e\uff1a flushall \u767b\u5f55\u540e\u590d\u5236 5. \u4f7f\u7528\u6301\u4e45\u5316 Redis \u53ef\u4ee5\u5c06\u6570\u636e\u6301\u4e45\u5316\u5230\u786c\u76d8\u6216\u5176\u4ed6\u4ecb\u8d28\u3002\u8fd9\u53ef\u4ee5\u91ca\u653e\u5185\u5b58\uff0c\u540c\u65f6\u786e\u4fdd\u6570\u636e\u5b89\u5168\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u542f\u7528\u6301\u4e45\u5316\uff1a save \u767b\u5f55\u540e\u590d\u5236 6. \u5347\u7ea7 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5824","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5824"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5824\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}