{"id":5817,"date":"2024-11-14T08:13:01","date_gmt":"2024-11-14T00:13:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5817\/"},"modified":"2024-11-14T08:13:01","modified_gmt":"2024-11-14T00:13:01","slug":"redis%e6%80%8e%e4%b9%88%e5%a4%84%e7%90%86%e5%a4%a7key","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5817\/","title":{"rendered":"redis\u600e\u4e48\u5904\u7406\u5927key"},"content":{"rendered":"<blockquote><p>\n  \u5904\u7406 redis \u4e2d\u7684\u5927 key \u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u8bc6\u522b\u5927 key\uff1a\u4f7f\u7528 redis-cli &#8211;scan \u547d\u4ee4\u626b\u63cf\u952e\uff0c\u8bc6\u522b\u6700\u5927\u952e\u3002\u62c6\u5206\u5927 key\uff1a\u4f7f\u7528\u54c8\u5e0c\u5206\u7247\u6216\u524d\u7f00\u6811\u5c06\u5927 key \u62c6\u5206\u6210\u66f4\u5c0f\u7684\u952e\uff0c\u5e76\u5b58\u50a8\u5728\u4e0d\u540c\u7684\u5b9e\u4f8b\u6216\u5c42\u7ea7\u4e2d\u3002\u4f7f\u7528 lru \u7f13\u5b58\uff1a\u8ddf\u8e2a\u6700\u8fd1\u8bbf\u95ee\u8fc7\u7684 key\uff0c\u5220\u9664\u6700\u4e0d\u5e38\u7528\u7684 key\u3002\u538b\u7f29\uff1a\u4f7f\u7528 lzf\u3001quicklz \u6216 gzip \u7b97\u6cd5\u538b\u7f29\u5927 key \u7684\u503c\u3002\u5176\u4ed6\u5efa\u8bae\uff1a\u51cf\u5c11 key \u957f\u5ea6\u3001\u4f7f\u7528\u590d\u5408\u952e\u3001\u62c6\u5206\u5217\u8868\u3001\u4f7f\u7528 hyperloglog\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/03\/2024060320040591211.jpg\" class=\"aligncenter\" title=\"redis\u600e\u4e48\u5904\u7406\u5927key\u63d2\u56fe\" alt=\"redis\u600e\u4e48\u5904\u7406\u5927key\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5904\u7406 Redis \u4e2d\u7684\u5927 Key<\/strong><\/p>\n<p>Redis \u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u952e\u503c\u5b58\u50a8\u7cfb\u7edf\uff0c\u4f46\u5f53\u5904\u7406\u5927 Key \u65f6\uff0c\u5b83\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u6027\u80fd\u95ee\u9898\u3002\u5927 Key \u901a\u5e38\u662f\u6307\u952e\u7684\u503c\u5f88\u5927\uff0c\u6216\u8005\u952e\u672c\u8eab\u5f88\u957f\u3002<\/p>\n<p><strong>\u8bc6\u522b\u5927 Key<\/strong><\/p>\n<p>\u7b2c\u4e00\u6b65\u662f\u8bc6\u522b Redis \u4e2d\u7684\u5927 Key\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>redis-cli --scan --pattern '*' --count 1000000<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5b83\u5c06\u626b\u63cf Redis \u4e2d\u7684\u6240\u6709\u952e\uff0c\u5e76\u8fd4\u56de\u524d 100 \u4e07\u4e2a\u952e\u7684\u5927\u5c0f\u6700\u5927\u7684\u952e\u3002<\/p>\n<p><strong>\u62c6\u5206\u5927 Key<\/strong><\/p>\n<p>\u5904\u7406\u5927 Key \u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u5c06\u5176\u62c6\u5206\u6210\u66f4\u5c0f\u7684 Key\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u5b9e\u73b0\uff1a<\/p>\n<ul>\n<li> <strong>\u54c8\u5e0c\u5206\u7247\uff1a<\/strong>\u4f7f\u7528\u54c8\u5e0c\u51fd\u6570\u5c06\u5927 Key \u62c6\u5206\u6210\u591a\u4e2a\u5c0f Key\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5728\u4e0d\u540c\u7684 Redis \u5b9e\u4f8b\u4e2d\u3002<\/li>\n<li> <strong>\u524d\u7f00\u6811\uff1a<\/strong>\u4f7f\u7528\u524d\u7f00\u6811\u5c06\u5927 Key \u62c6\u5206\u6210\u591a\u4e2a\u5c42\u7ea7\u7ed3\u6784\uff0c\u6bcf\u4e2a\u5c42\u7ea7\u7684 Key \u90fd\u66f4\u5c0f\u3002<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528 LRU\uff08\u6700\u8fd1\u6700\u5c11\u4f7f\u7528\uff09\u7f13\u5b58<\/strong><\/p>\n<p>LRU \u7f13\u5b58\u53ef\u4ee5\u5e2e\u52a9\u51cf\u5c11\u5927 Key \u7684\u5f71\u54cd\u3002\u5b83\u8ddf\u8e2a\u6700\u8fd1\u8bbf\u95ee\u8fc7\u7684 Key\uff0c\u5e76\u5728\u9700\u8981\u91ca\u653e\u5185\u5b58\u65f6\u9996\u5148\u5220\u9664\u6700\u4e0d\u5e38\u7528\u7684 Key\u3002<\/p>\n<p><strong>\u4f7f\u7528\u538b\u7f29<\/strong><\/p>\n<p>\u53ef\u4ee5\u5c06\u5927 Key \u7684\u503c\u538b\u7f29\uff0c\u4ece\u800c\u51cf\u5c11\u5176\u5360\u7528\u7a7a\u95f4\u3002Redis \u652f\u6301\u4f7f\u7528 LZF\u3001QUICKLZ \u548c GZIP \u7b97\u6cd5\u8fdb\u884c\u538b\u7f29\u3002<\/p>\n<p><strong>\u5176\u4ed6\u5efa\u8bae<\/strong><\/p>\n<ul>\n<li> <strong>\u907f\u514d\u4f7f\u7528\u975e\u5e38\u957f\u7684 Key\uff1a<\/strong>\u7406\u60f3\u60c5\u51b5\u4e0b\uff0cKey \u7684\u957f\u5ea6\u5e94\u5c0f\u4e8e 100 \u5b57\u8282\u3002<\/li>\n<li> <strong>\u4f7f\u7528\u590d\u5408\u952e\uff1a<\/strong>\u4f7f\u7528\u591a\u4e2a\u5b57\u6bb5\uff08\u4f8b\u5982\uff0c\u7528\u6237 ID \u548c\u5e16\u5b50 ID\uff09\u7ec4\u5408\u6210\u4e00\u4e2a\u952e\uff0c\u53ef\u4ee5\u51cf\u5c11\u5355\u4e2a\u952e\u7684\u957f\u5ea6\u3002<\/li>\n<li> <strong>\u4f7f\u7528\u5b50\u5217\u8868\uff1a<\/strong>\u5c06\u5927\u5217\u8868\u62c6\u5206\u6210\u591a\u4e2a\u5b50\u5217\u8868\uff0c\u6bcf\u4e2a\u5b50\u5217\u8868\u7684\u5143\u7d20\u8f83\u5c11\u3002<\/li>\n<li> <strong>\u4f7f\u7528 HyperLogLog\uff1a<\/strong>HyperLogLog \u662f\u4e00\u79cd\u6982\u7387\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u8fd1\u4f3c\u8ba1\u7b97\u5927\u96c6\u5408\u4e2d\u7684\u552f\u4e00\u5143\u7d20\u6570\u91cf\uff0c\u5b83\u5360\u7528\u7684\u7a7a\u95f4\u975e\u5e38\u5c0f\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u5904\u7406\u5927key\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>\u5904\u7406 redis \u4e2d\u7684\u5927 key \u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u8bc6\u522b\u5927 key\uff1a\u4f7f\u7528 redis-cli &#8211;scan \u547d\u4ee4\u626b\u63cf\u952e\uff0c\u8bc6\u522b\u6700\u5927\u952e\u3002\u62c6\u5206\u5927 key\uff1a\u4f7f\u7528\u54c8\u5e0c\u5206\u7247\u6216\u524d\u7f00\u6811\u5c06\u5927 key \u62c6\u5206\u6210\u66f4\u5c0f\u7684\u952e\uff0c\u5e76\u5b58\u50a8\u5728\u4e0d\u540c\u7684\u5b9e\u4f8b\u6216\u5c42\u7ea7\u4e2d\u3002\u4f7f\u7528 lru \u7f13\u5b58\uff1a\u8ddf\u8e2a\u6700\u8fd1\u8bbf\u95ee\u8fc7\u7684 key\uff0c\u5220\u9664\u6700\u4e0d\u5e38\u7528\u7684 key\u3002\u538b\u7f29\uff1a\u4f7f\u7528 lzf\u3001quicklz \u6216 gzip \u7b97\u6cd5\u538b\u7f29\u5927 key \u7684\u503c\u3002\u5176\u4ed6\u5efa\u8bae\uff1a\u51cf\u5c11 key \u957f\u5ea6\u3001\u4f7f\u7528\u590d\u5408\u952e\u3001\u62c6\u5206\u5217\u8868\u3001\u4f7f\u7528 hyperloglog\u3002 \u5982\u4f55\u5904\u7406 Redis \u4e2d\u7684\u5927 Key Redis \u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u952e\u503c\u5b58\u50a8\u7cfb\u7edf\uff0c\u4f46\u5f53\u5904\u7406\u5927 Key \u65f6\uff0c\u5b83\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u6027\u80fd\u95ee\u9898\u3002\u5927 Key \u901a\u5e38\u662f\u6307\u952e\u7684\u503c\u5f88\u5927\uff0c\u6216\u8005\u952e\u672c\u8eab\u5f88\u957f\u3002 \u8bc6\u522b\u5927 Key \u7b2c\u4e00\u6b65\u662f\u8bc6\u522b Redis \u4e2d\u7684\u5927 Key\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a redis-cli &#8211;scan &#8211;pattern &#8216;*&#8217; &#8211;count 1000000 \u767b\u5f55\u540e\u590d\u5236 \u5b83\u5c06\u626b\u63cf Redis \u4e2d\u7684\u6240\u6709\u952e\uff0c\u5e76\u8fd4\u56de\u524d 100 \u4e07\u4e2a\u952e\u7684\u5927\u5c0f\u6700\u5927\u7684\u952e\u3002 \u62c6\u5206\u5927 Key [&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-5817","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5817","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=5817"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5817\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}