{"id":637,"date":"2023-02-26T11:45:34","date_gmt":"2023-02-26T03:45:34","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=637"},"modified":"2023-04-29T20:00:01","modified_gmt":"2023-04-29T12:00:01","slug":"redis-partition","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/redis-partition\/","title":{"rendered":"Redis \u5206\u533a"},"content":{"rendered":"<p>\u5206\u533a\u662f\u5206\u5272\u6570\u636e\u5230\u591a\u4e2aRedis\u5b9e\u4f8b\u7684\u5904\u7406\u8fc7\u7a0b\uff0c\u56e0\u6b64\u6bcf\u4e2a\u5b9e\u4f8b\u53ea\u4fdd\u5b58key\u7684\u4e00\u4e2a\u5b50\u96c6\u3002<\/p>\n<h2>\u5206\u533a\u7684\u4f18\u52bf<\/h2>\n<ul>\n<li>\u901a\u8fc7\u5229\u7528\u591a\u53f0\u8ba1\u7b97\u673a\u5185\u5b58\u7684\u548c\u503c\uff0c\u5141\u8bb8\u6211\u4eec\u6784\u9020\u66f4\u5927\u7684\u6570\u636e\u5e93<\/li>\n<li>\u901a\u8fc7\u591a\u6838\u548c\u591a\u53f0\u8ba1\u7b97\u673a\uff0c\u5141\u8bb8\u6211\u4eec\u6269\u5c55\u8ba1\u7b97\u80fd\u529b\uff1b\u901a\u8fc7\u591a\u53f0\u8ba1\u7b97\u673a\u548c\u7f51\u7edc\u9002\u914d\u5668\uff0c\u5141\u8bb8\u6211\u4eec\u6269\u5c55\u7f51\u7edc\u5e26\u5bbd<\/li>\n<\/ul>\n<p><!-- more --><\/p>\n<h2>\u5206\u533a\u7684\u4e0d\u8db3<\/h2>\n<p>Redis\u7684\u4e00\u4e9b\u7279\u6027\u5728\u5206\u533a\u65b9\u9762\u8868\u73b0\u7684\u4e0d\u662f\u5f88\u597d\uff1a<\/p>\n<ul>\n<li>\u6d89\u53ca\u591a\u4e2akey\u7684\u64cd\u4f5c\u901a\u5e38\u662f\u4e0d\u88ab\u652f\u6301\u7684\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5f53\u4e24\u4e2aset\u6620\u5c04\u5230\u4e0d\u540c\u7684redis\u5b9e\u4f8b\u4e0a\u65f6\uff0c\u5c31\u4e0d\u80fd\u5bf9\u8fd9\u4e24\u4e2aset\u6267\u884c\u4ea4\u96c6\u64cd\u4f5c<\/li>\n<li>\u6d89\u53ca\u591a\u4e2akey\u7684redis\u4e8b\u52a1\u4e0d\u80fd\u4f7f\u7528<\/li>\n<li>\u5f53\u4f7f\u7528\u5206\u533a\u65f6\uff0c\u6570\u636e\u5904\u7406\u8f83\u4e3a\u590d\u6742\uff0c\u6bd4\u5982\u4f60\u9700\u8981\u5904\u7406\u591a\u4e2ardb\/aof\u6587\u4ef6\uff0c\u5e76\u4e14\u4ece\u591a\u4e2a\u5b9e\u4f8b\u548c\u4e3b\u673a\u5907\u4efd\u6301\u4e45\u5316\u6587\u4ef6<\/li>\n<li>\u589e\u52a0\u6216\u5220\u9664\u5bb9\u91cf\u4e5f\u6bd4\u8f83\u590d\u6742\u3002redis\u96c6\u7fa4\u5927\u591a\u6570\u652f\u6301\u5728\u8fd0\u884c\u65f6\u589e\u52a0\u3001\u5220\u9664\u8282\u70b9\u7684\u900f\u660e\u6570\u636e\u5e73\u8861\u7684\u80fd\u529b\uff0c\u4f46\u662f\u7c7b\u4f3c\u4e8e\u5ba2\u6237\u7aef\u5206\u533a\u3001\u4ee3\u7406\u7b49\u5176\u4ed6\u7cfb\u7edf\u5219\u4e0d\u652f\u6301\u8fd9\u9879\u7279\u6027\u3002\u7136\u800c\uff0c\u4e00\u79cd\u53eb\u505apresharding\u7684\u6280\u672f\u5bf9\u6b64\u662f\u6709\u5e2e\u52a9\u7684<\/li>\n<\/ul>\n<h2>\u5206\u533a\u7c7b\u578b<\/h2>\n<p>Redis \u6709\u4e24\u79cd\u7c7b\u578b\u5206\u533a\u3002\u5047\u8bbe\u67094\u4e2aRedis\u5b9e\u4f8b R0\uff0cR1\uff0cR2\uff0cR3\uff0c\u548c\u7c7b\u4f3c<code>user:1<\/code>\uff0c<code>user:2<\/code>\u8fd9\u6837\u7684\u8868\u793a\u7528\u6237\u7684\u591a\u4e2akey\uff0c\u5bf9\u65e2\u5b9a\u7684key\u6709\u591a\u79cd\u4e0d\u540c\u65b9\u5f0f\u6765\u9009\u62e9\u8fd9\u4e2akey\u5b58\u653e\u5728\u54ea\u4e2a\u5b9e\u4f8b\u4e2d\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6709\u4e0d\u540c\u7684\u7cfb\u7edf\u6765\u6620\u5c04\u67d0\u4e2akey\u5230\u67d0\u4e2aRedis\u670d\u52a1\u3002<\/p>\n<h3>\u8303\u56f4\u5206\u533a<\/h3>\n<p>\u6700\u7b80\u5355\u7684\u5206\u533a\u65b9\u5f0f\u662f\u6309\u8303\u56f4\u5206\u533a\uff0c\u5c31\u662f\u6620\u5c04\u4e00\u5b9a\u8303\u56f4\u7684\u5bf9\u8c61\u5230\u7279\u5b9a\u7684Redis\u5b9e\u4f8b\u3002<\/p>\n<p>\u6bd4\u5982\uff0cID\u4ece0\u523010000\u7684\u7528\u6237\u4f1a\u4fdd\u5b58\u5230\u5b9e\u4f8bR0\uff0cID\u4ece10001\u5230 20000\u7684\u7528\u6237\u4f1a\u4fdd\u5b58\u5230R1\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002<\/p>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u662f\u53ef\u884c\u7684\uff0c\u5e76\u4e14\u5728\u5b9e\u9645\u4e2d\u4f7f\u7528\uff0c\u4e0d\u8db3\u5c31\u662f\u8981\u6709\u4e00\u4e2a\u533a\u95f4\u8303\u56f4\u5230\u5b9e\u4f8b\u7684\u6620\u5c04\u8868\u3002\u8fd9\u4e2a\u8868\u8981\u88ab\u7ba1\u7406\uff0c\u540c\u65f6\u8fd8\u9700\u8981\u5404\u79cd\u5bf9\u8c61\u7684\u6620\u5c04\u8868\uff0c\u901a\u5e38\u5bf9Redis\u6765\u8bf4\u5e76\u975e\u662f\u597d\u7684\u65b9\u6cd5\u3002<\/p>\n<h3>\u54c8\u5e0c\u5206\u533a<\/h3>\n<p>\u53e6\u5916\u4e00\u79cd\u5206\u533a\u65b9\u6cd5\u662fhash\u5206\u533a\u3002\u8fd9\u5bf9\u4efb\u4f55key\u90fd\u9002\u7528\uff0c\u4e5f\u65e0\u9700\u662f<code>object_name:<\/code>\u8fd9\u79cd\u5f62\u5f0f\uff0c\u50cf\u4e0b\u9762\u63cf\u8ff0\u7684\u4e00\u6837\u7b80\u5355\uff1a<\/p>\n<ul>\n<li>\u7528\u4e00\u4e2ahash\u51fd\u6570\u5c06key\u8f6c\u6362\u4e3a\u4e00\u4e2a\u6570\u5b57\uff0c\u6bd4\u5982\u4f7f\u7528crc32 hash\u51fd\u6570\u3002\u5bf9key foobar\u6267\u884ccrc32(foobar)\u4f1a\u8f93\u51fa\u7c7b\u4f3c93024922\u7684\u6574\u6570<\/li>\n<li>\u5bf9\u8fd9\u4e2a\u6574\u6570\u53d6\u6a21\uff0c\u5c06\u5176\u8f6c\u5316\u4e3a0-3\u4e4b\u95f4\u7684\u6570\u5b57\uff0c\u5c31\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u6574\u6570\u6620\u5c04\u52304\u4e2aRedis\u5b9e\u4f8b\u4e2d\u7684\u4e00\u4e2a\u4e86\u300293024922 % 4 = 2\uff0c\u5c31\u662f\u8bf4key foobar\u5e94\u8be5\u88ab\u5b58\u5230R2\u5b9e\u4f8b\u4e2d\u3002\u6ce8\u610f\uff1a\u53d6\u6a21\u64cd\u4f5c\u662f\u53d6\u9664\u7684\u4f59\u6570\uff0c\u901a\u5e38\u5728\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7528%\u64cd\u4f5c\u7b26\u5b9e\u73b0<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5206\u533a\u662f\u5206\u5272\u6570\u636e\u5230\u591a\u4e2aRedis\u5b9e\u4f8b\u7684\u5904\u7406\u8fc7\u7a0b\uff0c\u56e0\u6b64\u6bcf\u4e2a\u5b9e\u4f8b\u53ea\u4fdd\u5b58key\u7684\u4e00\u4e2a\u5b50\u96c6\u3002 \u5206\u533a\u7684\u4f18\u52bf \u901a\u8fc7\u5229\u7528\u591a\u53f0\u8ba1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-637","post","type-post","status-publish","format-standard","hentry","category-redis"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=637"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/637\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}