{"id":2606,"date":"2026-10-22T13:49:03","date_gmt":"2026-10-22T05:49:03","guid":{"rendered":"http:\/\/www.spiceandwolf.com.cn\/?p=2606"},"modified":"2026-10-23T11:46:53","modified_gmt":"2026-10-23T03:46:53","slug":"redis-hm-memory-recycle","status":"publish","type":"post","link":"http:\/\/www.spiceandwolf.com.cn\/index.php\/redis-hm-memory-recycle\/","title":{"rendered":"Redis\u5185\u5b58\u56de\u6536"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Redis\u662f\u57fa\u4e8e\u5185\u5b58\u7684\u6570\u636e\u5e93\uff0c\u968f\u7740\u952e\u503c\u6570\u636e\u8d8a\u6765\u8d8a\u591a\uff0c\u8fbe\u5230\u5b58\u50a8\u4e0a\u9650\u7684\u6570\u636e\u4f1a\u5f71\u54cd\u6301\u4e45\u5316\u548c\u4e3b\u4ece\u540c\u6b65\u6027\u80fd\uff0c\u4e3a\u4e86\u4f18\u5316\u7a7a\u95f4\u5185\u5b58\uff0credis\u6709\u4e24\u79cd\u5185\u5b58\u56de\u6536\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8fc7\u671fkey\u5904\u7406<\/li>\n\n\n\n<li>\u5185\u5b58\u6dd8\u6c70<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u8fc7\u671fkey\u5904\u7406<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u601d\u8003\u4e24\u4e2a\u95ee\u9898\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Redis\u662f\u5982\u4f55\u77e5\u9053\u4e00\u4e2akey\u662f\u5426\u8fc7\u671f<\/li>\n\n\n\n<li>ttl\u5230\u671f\u662f\u5426\u7acb\u5373\u5220\u9664<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">redis\u89e3\u51b3\u7b2c\u4e00\u4e2a\u95ee\u9898\u7684\u65b9\u5f0f\uff0credisDb\u7ed3\u6784\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"381\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-47-1024x381.png\" alt=\"\" class=\"wp-image-2608\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-47-1024x381.png 1024w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-47-300x112.png 300w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-47-768x286.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-47.png 1424w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u4e2ddict\u7528\u6765\u4fdd\u5b58\u6240\u6709key\u548cvalue\u7684\u6307\u9488\uff0cexpire\u7528\u6765\u4fdd\u5b58\u6240\u6709key\u7684\u8fc7\u671f\u65f6\u95f4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">redis\u89e3\u51b3\u7b2c\u4e8c\u4e2a\u95ee\u9898\u7684\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u60f0\u6027\u5220\u9664\u3002\u8bbf\u95ee\u5bf9\u5e94key\u65f6\uff0c\u5982\u679c\u5224\u65ad\u5f53\u524dkey\u8fc7\u671f\u4e86\uff0c\u624d\u4f1a\u5220\u9664<\/li>\n\n\n\n<li>\u5b9a\u671f\u5220\u9664\u3002\u5982\u679c\u67d0\u4e9bkey\u8fc7\u671f\u4e86\u4e4b\u540e\u4e00\u76f4\u6ca1\u6709\u8bbf\u95ee\uff0c\u4f1a\u5927\u91cf\u5360\u7528\u5185\u5b58\u7a7a\u95f4\uff0c\u6240\u4ee5redis\u8bbe\u8ba1\u4e86\u5b9a\u671f\u5220\u9664\uff0c\u5b9a\u671f\u5220\u9664\u7684\u5468\u671f\u6709\u4e24\u79cd\uff1a\n<ul class=\"wp-block-list\">\n<li>SLOW\u3002Redis\u4f1a\u8bbe\u7f6e\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1serverCron()\uff0c\u6309\u7167server.hz\u7684\u9891\u7387\u6765\u6267\u884c\u8fc7\u671fkey\u6e05\u7406\uff0c\u5355\u6b21\u7684\u6e05\u7406\u65f6\u95f4\u5f80\u5f80\u8f83\u957f\u3002<\/li>\n\n\n\n<li>FAST\u3002Redis\u7684\u6bcf\u4e2a\u4e8b\u4ef6\u5faa\u73af\u524d\u4f1a\u8c03\u7528beforeSleep()\u51fd\u6570\uff0c\u6267\u884c\u8fc7\u671fkey\u6e05\u7406\uff0c\u5355\u6b21\u7684\u6e05\u7406\u65f6\u95f4\u5f80\u5f80\u8f83\u77ed\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\">SLOW\u6a21\u5f0f\u5904\u7406\u6d41\u7a0b<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6267\u884c\u9891\u7387\u53d7server.hz\u5f71\u54cd\uff0c\u9ed8\u8ba4\u4e3a10\uff0c\u5373\u6bcf\u79d2\u6267\u884c10\u6b21\uff0c\u6bcf\u4e2a\u6267\u884c\u5468\u671f100ms\u3002<\/li>\n\n\n\n<li>\u6267\u884c\u6e05\u7406\u8017\u65f6\u4e0d\u8d85\u8fc7\u4e00\u6b21\u6267\u884c\u5468\u671f\u768425%<\/li>\n\n\n\n<li>\u9010\u4e2a\u904d\u5386db\uff0c\u9010\u4e2a\u904d\u5386db\u4e2d\u7684bucket\uff0c\u62bd\u53d620\u4e2akey\u5224\u65ad\u662f\u5426\u8fc7\u671f<\/li>\n\n\n\n<li>\u5982\u679c\u6ca1\u8fbe\u5230\u65f6\u95f4\u4e0a\u9650\uff0825ms\uff09\u5e76\u4e14\u8fc7\u671fkey\u6bd4\u4f8b\u5927\u4e8e10%\uff0c\u518d\u8fdb\u884c\u4e00\u6b21\u62bd\u6837\uff0c\u5426\u5219\u7ed3\u675f<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\">FAST\u6a21\u5f0f\u5904\u7406\u6d41\u7a0b<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6267\u884c\u9891\u7387\u53d7beforeSleep()\u8c03\u7528\u9891\u7387\u5f71\u54cd\uff0c\u4f46\u4e24\u6b21FAST\u6a21\u5f0f\u95f4\u9694\u4e0d\u4f4e\u4e8e2ms\u3002<\/li>\n\n\n\n<li>\u6267\u884c\u6e05\u7406\u8017\u65f6\u4e0d\u8d85\u8fc71ms<\/li>\n\n\n\n<li>\u9010\u4e2a\u904d\u5386db\uff0c\u9010\u4e2a\u904d\u5386db\u4e2d\u7684bucket\uff0c\u62bd\u53d620\u4e2akey\u5224\u65ad\u662f\u5426\u8fc7\u671f<\/li>\n\n\n\n<li>\u5982\u679c\u6ca1\u8fbe\u5230\u65f6\u95f4\u4e0a\u9650\uff081ms\uff09\u5e76\u4e14\u8fc7\u671fkey\u6bd4\u4f8b\u5927\u4e8e10%\uff0c\u518d\u8fdb\u884c\u4e00\u6b21\u62bd\u6837\uff0c\u5426\u5219\u7ed3\u675f<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u5185\u5b58\u6dd8\u6c70\u7b56\u7565<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5185\u5b58\u6dd8\u6c70\uff1a\u5c31\u662f\u5f53Redis\u5185\u5b58\u4f7f\u7528\u8fbe\u5230\u8bbe\u7f6e\u7684\u9608\u503c\u65f6\uff0cRedis\u4e3b\u52a8\u6311\u9009<strong>\u90e8\u5206key<\/strong>\u5220\u9664\u4ee5\u91ca\u653e\u66f4\u591a\u5185\u5b58\u7684\u6d41\u7a0b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709\u4e24\u4e2a\u95ee\u9898\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>redis\u4f55\u65f6\u505a\u5185\u5b58\u6dd8\u6c70<\/li>\n\n\n\n<li>redis\u5185\u5b58\u6dd8\u6c70\u6709\u54ea\u4e9b\u65b9\u5f0f\uff0c\u5982\u4f55\u5b9e\u73b0\u7684<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u9488\u5bf9\u7b2c\u4e00\u4e2a\u95ee\u9898\uff1aRedis\u4f1a\u5728\u5904\u7406\u5ba2\u6237\u7aef\u547d\u4ee4\u7684\u65b9\u6cd5processCommand()\u4e2d\u5c1d\u8bd5\u505a\u5185\u5b58\u6dd8\u6c70<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9488\u5bf9\u7b2c\u4e8c\u4e2a\u95ee\u9898\uff1a\u5185\u5b58\u6dd8\u6c70\u7b56\u7565\u6709\u8fd9\u51e0\u79cd\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>no eviction\uff1a\u4e0d\u6dd8\u6c70\u4efb\u4f55key\uff0c\u4f46\u662f\u5185\u5b58\u6ee1\u65f6\u4e0d\u5141\u8bb8\u5199\u5165\u65b0\u6570\u636e\uff0c\u9ed8\u8ba4\u5c31\u662f\u8fd9\u79cd\u7b56\u7565<\/li>\n\n\n\n<li>volatile-til\uff1a\u5bf9\u8bbe\u7f6e\u4e86TTL\u7684key\uff0c\u6bd4\u8f83key\u7684\u5269\u4f59TTL\u503c\uff0cTTL\u8d8a\u5c0f\u8d8a\u5148\u88ab\u6dd8\u6c70<\/li>\n\n\n\n<li>alleys-random\uff1a\u5bf9\u5168\u4f53key\uff0c\u968f\u5373\u8fdb\u884c\u6dd8\u6c70\u3002\u4e5f\u5c31\u662f\u76f4\u63a5\u4ecedb->dict\u4e2d\u968f\u673a\u6311\u9009<\/li>\n\n\n\n<li>volatile-random\uff1a\u5bf9\u8bbe\u7f6e\u4e86TTL\u7684key\uff0c\u968f\u673a\u8fdb\u884c\u6dd8\u6c70\u3002\u4e5f\u5c31\u662f\u4ecedb->expires\u4e2d\u968f\u673a\u6311\u9009<\/li>\n\n\n\n<li>alleys-lru\uff1a\u5bf9\u5168\u4f53key\uff0c\u57fa\u4e8eLRU\u7b97\u6cd5\u8fdb\u884c\u6dd8\u6c70<\/li>\n\n\n\n<li>volatile-lru\uff1a\u5bf9\u8bbe\u7f6e\u4e86TTL\u7684key\uff0c\u57fa\u4e8eLRU\u7b97\u6cd5\u8fdb\u884c\u6dd8\u6c70<\/li>\n\n\n\n<li>alleys-lfu\uff1a\u5bf9\u5168\u4f53key\uff0c\u57fa\u4e8eLFU\u7b97\u6cd5\u8fdb\u884c\u6dd8\u6c70<\/li>\n\n\n\n<li>volatile-flu\uff1a\u5bf9\u8bbe\u7f6e\u4e86TTL\u7684key\uff0c\u57fa\u4e8eLFU\u7b97\u6cd5\u8fdb\u884c\u6dd8\u6c70<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">LRU\uff1a\u6700\u5c11\u6700\u8fd1\u4f7f\u7528\u3002\u7528\u5f53\u524d\u65f6\u95f4\u51cf\u53bb\u6700\u540e\u4e00\u6b21\u8bbf\u95ee\u65f6\u95f4\uff0c\u8fd9\u4e2a\u503c\u8d8a\u5927\u5219\u6dd8\u6c70\u4f18\u5148\u7ea7\u8d8a\u9ad8<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">LFU\uff1a\u6700\u5c11\u9891\u7387\u4f7f\u7528\u3002\u4f1a\u7edf\u8ba1\u6bcf\u4e2akey\u7684\u8bbf\u95ee\u9891\u7387\uff0c\u503c\u8d8a\u5c0f\u6dd8\u6c70\u4f18\u5148\u7ea7\u8d8a\u9ad8<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"540\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-53-1024x540.png\" alt=\"\" class=\"wp-image-2623\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-53-1024x540.png 1024w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-53-300x158.png 300w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-53-768x405.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-53.png 1484w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6dd8\u6c70\u7b56\u7565\u770b\u7740\u529e\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"533\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-54-1024x533.png\" alt=\"\" class=\"wp-image-2624\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-54-1024x533.png 1024w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-54-300x156.png 300w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-54-768x400.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-54-1536x799.png 1536w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/10\/image-54.png 1576w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Redis\u662f\u57fa\u4e8e\u5185\u5b58\u7684\u6570\u636e\u5e93\uff0c\u968f\u7740\u952e\u503c\u6570\u636e\u8d8a\u6765\u8d8a\u591a\uff0c\u8fbe\u5230\u5b58\u50a8\u4e0a\u9650\u7684\u6570\u636e\u4f1a\u5f71\u54cd\u6301\u4e45\u5316\u548c\u4e3b\u4ece\u540c\u6b65\u6027\u80fd\uff0c\u4e3a\u4e86\u4f18\u5316\u7a7a\u95f4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,90],"tags":[],"class_list":["post-2606","post","type-post","status-publish","format-standard","hentry","category-code","category-redis"],"_links":{"self":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/2606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2606"}],"version-history":[{"count":12,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/2606\/revisions"}],"predecessor-version":[{"id":2626,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/2606\/revisions\/2626"}],"wp:attachment":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2606"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}