{"id":327,"date":"2025-01-10T11:32:05","date_gmt":"2025-01-10T03:32:05","guid":{"rendered":"https:\/\/blessingcr.com\/?p=327"},"modified":"2025-01-10T13:41:22","modified_gmt":"2025-01-10T05:41:22","slug":"redis-%e9%9b%86%e7%be%a4%e6%a8%a1%e5%bc%8f-%e6%89%b9%e9%87%8f%e5%88%a0%e9%99%a4-%e5%89%8d%e7%bc%80%e5%88%a0%e9%99%a4","status":"publish","type":"post","link":"https:\/\/blessingcr.com\/?p=327","title":{"rendered":"Redis \u96c6\u7fa4\u6a21\u5f0f \u6279\u91cf\u5220\u9664\/\u524d\u7f00\u5220\u9664"},"content":{"rendered":"<h1>Redis \u96c6\u7fa4\u5c0f\u5751<\/h1>\n<h3>Redis \u96c6\u7fa4\u7684\u6838\u5fc3\u673a\u5236\uff1a\u54c8\u5e0c\u69fd<\/h3>\n<p>Redis \u96c6\u7fa4\u91c7\u7528\u4e86 <strong>\u54c8\u5e0c\u69fd\uff08Hash Slots\uff09<\/strong> \u6765\u7ba1\u7406\u952e\u7684\u5206\u5e03\u3002\u96c6\u7fa4\u4e2d\u603b\u5171\u6709 <strong>16384 \u4e2a\u54c8\u5e0c\u69fd<\/strong>\uff0c\u6bcf\u4e2a\u952e\u6839\u636e\u5176\u540d\u79f0\u901a\u8fc7\u54c8\u5e0c\u7b97\u6cd5\u8ba1\u7b97\u51fa\u4e00\u4e2a\u69fd\u53f7\uff0c\u5e76\u88ab\u5206\u914d\u5230\u67d0\u4e2a\u8282\u70b9\u4e0a\u8fdb\u884c\u5b58\u50a8\u3002<\/p>\n<ul>\n<li>\u5f53\u4f60\u6267\u884c\u7c7b\u4f3c <code>SET<\/code> \u6216 <code>GET<\/code> \u8fd9\u6837\u7684\u547d\u4ee4\u65f6\uff0cRedis \u6839\u636e\u952e\u7684\u540d\u79f0\u901a\u8fc7\u4e00\u81f4\u6027\u54c8\u5e0c\u8ba1\u7b97\u51fa\u8be5\u952e\u5e94\u8be5\u5c5e\u4e8e\u54ea\u4e2a\u69fd\uff08slot\uff09\uff0c\u7136\u540e\u5c06\u8be5\u952e\u5b58\u50a8\u5728\u8d1f\u8d23\u8fd9\u4e2a\u69fd\u7684\u8282\u70b9\u4e0a\u3002<\/li>\n<li>\u6bcf\u4e2a\u8282\u70b9\u8d1f\u8d23\u7ba1\u7406\u82e5\u5e72\u4e2a\u54c8\u5e0c\u69fd\uff0c\u56e0\u6b64\u6bcf\u4e2a\u8282\u70b9\u53ea\u5b58\u50a8\u4e00\u90e8\u5206\u6570\u636e\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0cRedis \u96c6\u7fa4\u80fd\u5c06\u6570\u636e\u5206\u5e03\u5728\u591a\u4e2a\u8282\u70b9\u4e0a\uff0c\u4ece\u800c\u5b9e\u73b0\u6c34\u5e73\u6269\u5c55\u3002<\/li>\n<\/ul>\n<h3>\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u901a\u8fc7\u524d\u7f00\u76f4\u63a5\u5220\u9664\uff1f<\/h3>\n<p><strong>1. \u952e\u5206\u5e03\u5728\u4e0d\u540c\u8282\u70b9\u4e0a\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728 Redis \u96c6\u7fa4\u4e2d\uff0c\u952e\u5e76\u4e0d\u5168\u90e8\u5b58\u50a8\u5728\u4e00\u4e2a\u8282\u70b9\u4e0a\uff0c\u800c\u662f\u6839\u636e\u54c8\u5e0c\u69fd\u673a\u5236\u5206\u5e03\u5728\u591a\u4e2a\u8282\u70b9\u4e0a\u3002\u6bcf\u4e2a\u8282\u70b9\u53ea\u8d1f\u8d23\u81ea\u5df1\u54c8\u5e0c\u69fd\u8303\u56f4\u5185\u7684\u952e\u3002<\/li>\n<li>\u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u524d\u7f00 <code>&quot;user:&quot;<\/code>\uff0c\u5e76\u4e14\u8981\u5220\u9664\u6240\u6709\u4ee5 <code>&quot;user:&quot;<\/code> \u5f00\u5934\u7684\u952e\u3002\u5728 Redis \u96c6\u7fa4\u4e2d\uff0c\u952e <code>user:1<\/code> \u53ef\u80fd\u5206\u5e03\u5728\u8282\u70b9 A \u4e0a\uff0c\u800c <code>user:2<\/code> \u53ef\u80fd\u5206\u5e03\u5728\u8282\u70b9 B \u4e0a\uff0c<code>user:3<\/code> \u53ef\u80fd\u53c8\u5206\u5e03\u5728\u8282\u70b9 C \u4e0a\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002<\/li>\n<\/ul>\n<p><strong>2. \u6ca1\u6709\u5168\u5c40\u89c6\u56fe\uff1a<\/strong><\/p>\n<ul>\n<li>Redis \u96c6\u7fa4\u7684\u8bbe\u8ba1\u5e76\u6ca1\u6709\u63d0\u4f9b\u5168\u5c40\u7684\u952e\u5217\u8868\u89c6\u56fe\u3002\u5728\u96c6\u7fa4\u4e2d\uff0c<code>SCAN<\/code> \u547d\u4ee4\u6216 <code>DEL<\/code> \u547d\u4ee4\u662f\u9650\u5b9a\u5728\u5355\u4e2a\u8282\u70b9\u4e0a\u7684\uff0c\u4e0d\u4f1a\u81ea\u52a8\u8de8\u8282\u70b9\u64cd\u4f5c\u3002\u56e0\u6b64\uff0c\u65e0\u6cd5\u5728\u6240\u6709\u8282\u70b9\u4e0a\u540c\u65f6\u67e5\u8be2\u6216\u5220\u9664\u5e26\u6709\u7279\u5b9a\u524d\u7f00\u7684\u6240\u6709\u952e\u3002<\/li>\n<li>\u5f53\u4f60\u5c1d\u8bd5\u901a\u8fc7\u524d\u7f00\u5220\u9664\u65f6\uff0cRedis \u96c6\u7fa4\u7684\u547d\u4ee4\u5e76\u4e0d\u4f1a\u8de8\u8d8a\u591a\u4e2a\u8282\u70b9\u6765\u67e5\u627e\u548c\u5220\u9664\u5e26\u6709\u524d\u7f00\u7684\u6240\u6709\u952e\u3002\u6bcf\u4e2a\u8282\u70b9\u4ec5\u80fd\u64cd\u4f5c\u81ea\u5df1\u5b58\u50a8\u7684\u952e\uff0c\u5e76\u4e14\u5b83\u4e0d\u77e5\u9053\u5176\u4ed6\u8282\u70b9\u4e0a\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n<p><strong>3. <code>SCAN<\/code> \u547d\u4ee4\u9650\u5236\uff1a<\/strong><\/p>\n<ul>\n<li>Redis \u7684 <code>SCAN<\/code> \u547d\u4ee4\u867d\u7136\u652f\u6301\u589e\u91cf\u8fed\u4ee3\u6765\u904d\u5386\u5f53\u524d\u8282\u70b9\u4e2d\u7684\u6240\u6709\u952e\uff0c\u4f46\u5b83\u5e76\u4e0d\u4f1a\u81ea\u52a8\u626b\u63cf\u6574\u4e2a\u96c6\u7fa4\u4e2d\u7684\u6240\u6709\u952e\u3002<code>SCAN<\/code> \u4ec5\u5bf9\u5f53\u524d\u8282\u70b9\u6709\u6548\uff0c\u5982\u679c\u4f60\u8981\u5220\u9664\u4e00\u4e2a\u5e26\u524d\u7f00\u7684\u952e\uff0c\u5fc5\u987b\u9010\u4e2a\u8282\u70b9\u5730\u626b\u63cf\u3002<\/li>\n<li>\u5728\u96c6\u7fa4\u6a21\u5f0f\u4e0b\uff0c<code>SCAN<\/code> \u547d\u4ee4\u5e76\u4e0d\u4f1a\u5728\u6240\u6709\u8282\u70b9\u4e0a\u5e76\u884c\u6267\u884c\uff0c\u5b83\u53ea\u4f1a\u5728\u67d0\u4e2a\u7279\u5b9a\u8282\u70b9\u4e0a\u8fd0\u884c\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5373\u4f7f\u4f60\u4f7f\u7528\u4e86\u5e26\u6709\u524d\u7f00\u5339\u914d\u7684 <code>SCAN<\/code>\uff0c\u4f60\u4ecd\u7136\u9700\u8981\u624b\u52a8\u8fde\u63a5\u548c\u626b\u63cf\u6bcf\u4e2a\u8282\u70b9\u4e0a\u7684\u6570\u636e\uff0c\u5e76\u627e\u51fa\u7b26\u5408\u6761\u4ef6\u7684\u952e\u3002<\/li>\n<\/ul>\n<h3>\u4e3e\u4e2a\u4f8b\u5b50<\/h3>\n<p>\u5047\u8bbe\u4f60\u6709\u4ee5\u4e0b\u4e09\u4e2a Redis \u96c6\u7fa4\u8282\u70b9\uff0c\u6570\u636e\u5206\u522b\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li><strong>\u8282\u70b9 A<\/strong>\uff1a\u8d1f\u8d23\u54c8\u5e0c\u69fd 0-5000\uff0c\u5b58\u50a8\u952e <code>user:1<\/code>, <code>user:2<\/code><\/li>\n<li><strong>\u8282\u70b9 B<\/strong>\uff1a\u8d1f\u8d23\u54c8\u5e0c\u69fd 5001-10000\uff0c\u5b58\u50a8\u952e <code>user:3<\/code>, <code>user:4<\/code><\/li>\n<li><strong>\u8282\u70b9 C<\/strong>\uff1a\u8d1f\u8d23\u54c8\u5e0c\u69fd 10001-16383\uff0c\u5b58\u50a8\u952e <code>user:5<\/code>, <code>user:6<\/code><\/li>\n<\/ul>\n<p>\u5f53\u4f60\u5c1d\u8bd5\u901a\u8fc7\u524d\u7f00 <code>&quot;user:&quot;<\/code> \u5220\u9664\u952e\u65f6\uff0cRedis \u96c6\u7fa4\u65e0\u6cd5\u4e00\u6b21\u6027\u5220\u9664\u6240\u6709\u8282\u70b9\u4e0a\u7684\u8fd9\u4e9b\u952e\u3002\u4f60\u9700\u8981\uff1a<\/p>\n<ol>\n<li>\u5728\u8282\u70b9 A \u6267\u884c <code>SCAN<\/code> \u67e5\u627e\u5339\u914d\u524d\u7f00\u7684\u952e <code>user:1<\/code>, <code>user:2<\/code>\u3002<\/li>\n<li>\u5728\u8282\u70b9 B \u6267\u884c <code>SCAN<\/code> \u67e5\u627e\u5339\u914d\u524d\u7f00\u7684\u952e <code>user:3<\/code>, <code>user:4<\/code>\u3002<\/li>\n<li>\u5728\u8282\u70b9 C \u6267\u884c <code>SCAN<\/code> \u67e5\u627e\u5339\u914d\u524d\u7f00\u7684\u952e <code>user:5<\/code>, <code>user:6<\/code>\u3002<\/li>\n<\/ol>\n<p>\u6bcf\u4e2a\u8282\u70b9\u4e0a\u7684\u6570\u636e\u5fc5\u987b\u5355\u72ec\u5904\u7406\uff0c\u8fd9\u5c31\u5bfc\u81f4\u4e86\u65e0\u6cd5\u50cf\u5728\u5355\u8282\u70b9\u6a21\u5f0f\u4e0b\u90a3\u6837\u76f4\u63a5\u4f7f\u7528\u524d\u7f00\u4e00\u6b21\u6027\u5220\u9664\u6240\u6709\u5339\u914d\u7684\u952e\u3002<\/p>\n<h3>\u89e3\u51b3\u65b9\u6848<\/h3>\n<p>\u4e3a\u4e86\u5728 Redis \u96c6\u7fa4\u4e2d\u5220\u9664\u5177\u6709\u7279\u5b9a\u524d\u7f00\u7684\u6240\u6709\u952e\uff0c\u901a\u5e38\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<ol>\n<li><strong>\u624b\u52a8\u904d\u5386\u6bcf\u4e2a\u8282\u70b9\uff1a<\/strong>\n<ul>\n<li>\u4f7f\u7528 <code>SCAN<\/code> \u547d\u4ee4\u904d\u5386\u6bcf\u4e2a\u8282\u70b9\u4e0a\u7684\u952e\uff0c\u5e76\u68c0\u67e5\u5b83\u4eec\u662f\u5426\u5339\u914d\u7ed9\u5b9a\u7684\u524d\u7f00\u3002\u5339\u914d\u7684\u952e\u5c06\u88ab\u5220\u9664\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u9700\u8981\u4f60\u624b\u52a8\u8bbf\u95ee\u6bcf\u4e2a\u8282\u70b9\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u5206\u5e03\u5f0f\u5220\u9664\u5de5\u5177\uff1a<\/strong>\n<ul>\n<li>\u4f7f\u7528\u4e00\u4e9b Redis \u96c6\u7fa4\u7ba1\u7406\u5de5\u5177\uff08\u5982 <a href=\"https:\/\/github.com\/redisson\/redisson\">Redisson<\/a>\uff09\u6216\u5176\u4ed6\u7b2c\u4e09\u65b9\u5e93\uff0c\u6765\u8de8\u8282\u70b9\u626b\u63cf\u952e\u5e76\u6267\u884c\u5220\u9664\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u5b9a\u671f\u6e05\u7406\u673a\u5236\uff1a<\/strong>\n<ul>\n<li>\u8bbe\u5b9a TTL\uff08\u8fc7\u671f\u65f6\u95f4\uff09\u7b49\u7b56\u7565\uff0c\u51cf\u5c11\u4e0d\u9700\u8981\u7684\u952e\u7684\u5b58\u6d3b\u65f6\u95f4\uff0c\u4ece\u800c\u51cf\u8f7b\u6279\u91cf\u5220\u9664\u7684\u9700\u6c42\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u6279\u91cf\u5220\u9664\u64cd\u4f5c\uff1a<\/strong>\n<ul>\n<li>\u5206\u6279\u6b21\u5220\u9664\u952e\uff0c\u5e76\u5728\u6bcf\u6b21\u5220\u9664\u65f6\u786e\u4fdd\u904d\u5386\u6bcf\u4e2a\u8282\u70b9\u4e0a\u7684\u6570\u636e\u3002\u53ef\u4ee5\u7ed3\u5408\u5f02\u6b65\u6216\u5e76\u884c\u5904\u7406\u6280\u672f\uff0c\u4f18\u5316\u6027\u80fd\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\uff08\u63a8\u8350\uff09key\u4e2d\u76f4\u63a5\u52a0\u5927\u62ec\u53f7\uff1a<\/strong>\n<ul>\n<li>\u901a\u8fc7 {} \u6765\u6307\u5b9a Redis \u8def\u7531<br \/>\n\u4f8b\u5982\uff1a<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<pre><code>SET user:{1001}:name &amp;quot;John Doe&amp;quot;\nSET user:{1001}:email &amp;quot;john.doe@example.com&amp;quot;\nSET user:{1002}:name &amp;quot;Jane Smith&amp;quot;\nuser:{1001}:name \u548c user:{1001}:email \u4f1a\u88ab\u8def\u7531\u5230\u540c\u4e00\u4e2a\u8282\u70b9\u3002\nuser:{1002}:name \u4f1a\u88ab\u8def\u7531\u5230\u53e6\u4e00\u4e2a\u8282\u70b9\uff0c\u548c user:{1001}:name \u5904\u4e8e\u4e0d\u540c\u7684\u54c8\u5e0c\u69fd\u3002<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Redis \u96c6\u7fa4\u5c0f\u5751 Redis \u96c6\u7fa4\u7684\u6838\u5fc3\u673a\u5236\uff1a\u54c8\u5e0c\u69fd Redis \u96c6\u7fa4\u91c7\u7528\u4e86 \u54c8\u5e0c\u69fd\uff08Hash Slots [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,87],"tags":[],"class_list":["post-327","post","type-post","status-publish","format-standard","hentry","category-redis","category-87"],"_links":{"self":[{"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/posts\/327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blessingcr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=327"}],"version-history":[{"count":2,"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/posts\/327\/revisions"}],"predecessor-version":[{"id":334,"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/posts\/327\/revisions\/334"}],"wp:attachment":[{"href":"https:\/\/blessingcr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blessingcr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blessingcr.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}