{"id":379,"date":"2023-09-16T10:57:13","date_gmt":"2023-09-16T02:57:13","guid":{"rendered":""},"modified":"2023-09-16T10:57:13","modified_gmt":"2023-09-16T02:57:13","slug":"Redis\u7684\u5206\u5e03\u5f0f\u90e8\u7f72","status":"publish","type":"post","link":"https:\/\/mushiming.com\/379.html","title":{"rendered":"Redis\u7684\u5206\u5e03\u5f0f\u90e8\u7f72"},"content":{"rendered":"
\u8be5\u6587\u7ae0\u4ece\u5b58\u50a8\u7684\u5206\u5e03\u5f0f\u90e8\u7f72\u5e38\u7528\u601d\u8def\u51fa\u53d1\uff0c\u4ecb\u7ecd\u4e86\u6c34\u5e73\u62c6\u5206\u3001\u4e3b\u4ece\u590d\u5236\u8fd9\u4e24\u79cd\u6838\u5fc3\u601d\u8def\uff0c\u5e76\u4ecb\u7ecd\u4e86redis\u7684\u5b9e\u73b0\uff0c\u5206\u522b\u662f<\/p>\n
\u4ee5\u4e0b\u4e3a\u539f\u6587\u3002<\/p>\n
\u5b66\u4e60\u7b14\u8bb0 | Redis \u5206\u5e03\u5f0f\u90e8\u7f72\u65b9\u6848_\u5927\u864e\u7259\u7684\u535a\u5ba2-CSDN\u535a\u5ba2_redis\u5206\u5e03\u5f0f\u90e8\u7f72<\/p>\n
Redis\u662f\u4e00\u6b3e\u5f00\u6e90\u7684\u57fa\u4e8e\u5185\u5b58\u7684K-V\u578b\u6570\u636e\u5e93\uff0c\u56e0\u4e3a\u5185\u5b58\u8bbf\u95ee\u901f\u5ea6\u5feb\uff0c\u4e00\u822c\u88ab\u7528\u6765\u505a\u7cfb\u7edf\u7684\u7f13\u5b58\u3002<\/p>\n
Redis\u4f5c\u4e3a\u5355\u673a\u90e8\u7f72\u80fd\u591f\u652f\u6301\u4e1a\u52a1\u7b80\u5355\uff0c\u6570\u636e\u91cf\u4e0d\u5927\u7684\u7cfb\u7edf\u9700\u6c42\uff0c\u4f46\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u4e00\u65e6\u7cfb\u7edf\u89c4\u6a21\u4e0a\u6765\uff0c\u5355\u673a\u7684Redis\u5c31\u4f1a\u9047\u5230\u4e0b\u9762\u7684\u6311\u6218\uff1a<\/p>\n
\u4f38\u7f29\u6027\u3002\u7cfb\u7edf\u968f\u7740\u957f\u671f\u8fd0\u884c\u4e0e\u4e1a\u52a1\u589e\u957f\uff0c\u5bf9Redis\u5b58\u50a8\u7684\u6570\u636e\u91cf\u9700\u6c42\u4e5f\u8d8a\u6765\u8d8a\u5927\uff0c\u5355\u673a\u5fc5\u7136\u53d7\u9650\u4e8e\u670d\u52a1\u5668\u7684\u5185\u5b58\u4e0e\u78c1\u76d8\u5927\u5c0f\u3002
\u9ad8\u6027\u80fd\u3002\u7cfb\u7edf\u89c4\u6a21\u53d8\u5927\u540e\uff0c\u5bf9Redis\u7684\u541e\u5410\u91cf\u9700\u6c42\u4e5f\u4f1a\u63d0\u9ad8\uff0c\u800c\u5355\u673a\u7684\u541e\u5410\u91cf\u5fc5\u7136\u6709\u9650\uff0c\u8fd9\u79cd\u60c5\u51b5\u4f1a\u5f71\u54cd\u6574\u4f53\u7cfb\u7edf\u7684\u6027\u80fd\u3002
\u9ad8\u53ef\u7528\u3002Redis\u6301\u4e45\u5316\u673a\u5236\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u80fd\u7f13\u89e3\u5355\u70b9\u95ee\u9898\uff0c\u4f46\u662f\u9700\u8981\u82b1\u8d39\u65f6\u95f4\u53bb\u6062\u590d\uff0c\u5728\u6062\u590d\u7684\u8fc7\u7a0b\u4e2d\u670d\u52a1\u53ef\u80fd\u4e0d\u53ef\u7528\uff0c\u6216\u8005\u6570\u636e\u4f1a\u6709\u4e22\u5931\u3002<\/p>\n
<\/p>\n
\u5206\u5e03\u5f0f\u7684\u89e3\u51b3\u65b9\u6848\u5bf9\u4e8e\u4e1a\u5185\u662f\u901a\u7528\u7684\uff1a<\/p>\n
\u6c34\u5e73\u62c6\u5206\u3002 \u5355\u70b9\u7684\u4e00\u4e2a\u91cd\u8981\u6311\u6218\u5c31\u662f\u6570\u636e\u91cf\u5927\u7684\u65f6\u5019\u5355\u70b9\u5b58\u50a8\u4e0d\u591f\u3002\u76f4\u63a5\u7684\u60f3\u6cd5\u5c31\u662f\u90e8\u7f72\u591a\u4e2a\u5b9e\u4f8b\uff0c\u5c06\u9700\u8981\u5b58\u50a8\u7684\u6570\u636e\u5206\u6563\u5b58\u50a8\u5230\u5404\u4e2a\u5b9e\u4f8b\u4e2d\u3002\u5f53\u5b9e\u4f8b\u5b58\u50a8\u7a7a\u95f4\u4e0d\u591f\u65f6\uff0c\u7ee7\u7eed\u6269\u5927\u5b9e\u4f8b\u4e2a\u6570\u5c31\u53ef\u4ee5\u89e3\u51b3\u6570\u636e\u4f38\u7f29\u6027\u95ee\u9898\u3002\u540c\u65f6\u8fd9\u79cd\u6570\u636e\u6c34\u5e73\u62c6\u5206\u7684\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u89e3\u51b3\u5355\u673a\u6027\u80fd\u95ee\u9898\uff0c\u56e0\u4e3a\u4e0d\u540c\u7684\u6570\u636e\u8bfb\u5199\u53ef\u4ee5\u5206\u914d\u5230\u4e0d\u540c\u7684\u5b9e\u4f8b\u3002
\u4e3b\u4ece\u590d\u5236\u3002 \u5982\u679c\u53ea\u6709\u6c34\u5e73\u62c6\u5206\uff0c\u5982\u679c\u5176\u4e2d\u4e00\u4e2a\u5b9e\u4f8b\u51fa\u73b0\u4e86\u95ee\u9898\uff0c\u90a3\u8be5\u5b9e\u4f8b\u4e0a\u5b58\u50a8\u7684\u6570\u636e\u90fd\u4e0d\u53ef\u8bbf\u95ee\uff0c\u8fd8\u662f\u5b58\u5728\u53ef\u7528\u95ee\u9898\u3002\u4e3a\u6b64\u53ef\u4ee5\u8fdb\u884c\u6240\u6709\u6570\u636e\u7684\u4e3b\u5907\u590d\u5236\uff0c\u540c\u4e00\u4efd\u6570\u636e\u53ef\u4ee5\u6709\u591a\u4e2a\u526f\u672c\uff0c\u5f53\u67d0\u4e2a\u5b9e\u4f8b\u51fa\u73b0\u95ee\u9898\u65f6\uff0c\u53ef\u4ee5\u542f\u7528\u8be5\u5b9e\u4f8b\u7684\u526f\u672c\uff0c\u8fbe\u5230\u9ad8\u53ef\u7528\u7684\u76ee\u7684\u3002\u540c\u65f6\u526f\u672c\u4e5f\u53ef\u4ee5\u5e2e\u52a9\u63d0\u9ad8\u7cfb\u7edf\u7684\u541e\u5410\u80fd\u529b\uff0c\u56e0\u4e3a\u5bf9\u6570\u636e\u7684\u8bbf\u95ee\u4e5f\u53ef\u4ee5\u5206\u53d1\u5230\u526f\u672c\u4e0a\u3002<\/p>\n
\u5b58\u50a8\u7684\u5206\u5e03\u5f0f\u89e3\u51b3\u65b9\u6848\u5927\u62b5\u5982\u4e0a\uff0c\u4e0d\u540c\u7684\u662f\u5404\u79cd\u7cfb\u7edf\u7684\u5b9e\u73b0\u65b9\u6cd5\u4e0d\u540c\u3002\u4e0b\u9762\u6211\u4eec\u6765\u770b\u4e0bRedis\u7684\u5206\u5e03\u5f0f\u89e3\u51b3\u65b9\u6848\u662f\u600e\u6837\u7684\u3002<\/p>\n
<\/p>\n
\u5206\u5e03\u5f0f\u89e3\u51b3\u65b9\u6848\u4e0d\u662f\u4e00\u8e74\u800c\u5c31\u7684\uff0c\u4e5f\u6709\u4e2a\u53d1\u5c55\u7684\u8fc7\u7a0b\uff0c\u4e0d\u540c\u5386\u53f2\u65f6\u671f\u63d0\u4f9b\u7684\u65b9\u6848\u53ef\u80fd\u4e0d\u540c\uff0c\u6700\u65b0\u7684\u89e3\u51b3\u65b9\u6848\u4e5f\u53ef\u80fd\u5728\u4e0d\u8fdc\u7684\u5c06\u6765\u88ab\u66ff\u6362\u3002<\/p>\n
\u4e3b\u4ece\u590d\u5236\uff08replication\uff09 \u662fRedis\u5206\u5e03\u5f0f\u7684\u57fa\u7840\u3002Redis\u4e2d\u5305\u542b\u4e24\u79cd\u8282\u70b9\uff1amaster\u8282\u70b9\u4e0eslave\u8282\u70b9\u3002\u540c\u4e00\u4efd\u6570\u636e\u5b58\u653e\u5728master\u4e0e\u591a\u4e2aslave\u8282\u70b9\u4e0a\uff0cmaster\u5bf9\u5916\u63d0\u4f9b\u8bfb\u5199\uff0cslave\u4e0d\u5bf9\u5916\u63d0\u4f9b\u5199\u64cd\u4f5c\u3002\u5f53master\u5b95\u673a\u65f6\uff0cslave\u8282\u70b9\u8fd8\u80fd\u7ee7\u7eed\u63d0\u4f9b\u670d\u52a1\u3002\u4e3b\u4ece\u590d\u5236\u4e2d\u6700\u91cd\u8981\u7684\u5c31\u662f\u4e3b\u4ece\u6570\u636e\u5982\u4f55\u540c\u6b65\u3002<\/p>\n
<\/p>\n
Redis\u7684\u4e3b\u4ece\u540c\u6b65\u5206\u4e3a\u5168\u91cf\u540c\u6b65\u4e0e\u589e\u91cf\u540c\u6b65\uff0c\u5728\u4e0b\u9762\u7684\u7ae0\u8282\u4f1a\u8be6\u7ec6\u4ecb\u7ecd\u3002
\u5982\u679c\u53ea\u6709\u4e3b\u4ece\u590d\u5236\uff0c\u5f53master\u5b95\u673a\u65f6\uff0c\u9700\u8981\u8fd0\u7ef4\u4eba\u5de5\u5c06slave\u8282\u70b9\u5207\u6362\u6210master\u3002\u8fd9\u5728\u751f\u4ea7\u73af\u5883\u662f\u4e0d\u53ef\u63a5\u53d7\u7684\uff0c\u5728\u8fd9\u8fc7\u7a0b\u4e2d\u7cfb\u7edf\u53ef\u80fd\u65e0\u6cd5\u4f7f\u7528\u3002\u6240\u4ee5\u9700\u8981\u6709\u4e00\u4e2a\u673a\u5236\uff0c\u5f53master\u5b95\u673a\u65f6\u80fd\u81ea\u52a8\u8fdb\u884c\u4e3b\u4ece\u5207\u6362\uff0c\u5e94\u7528\u7a0b\u5e8f\u65e0\u611f\u77e5\uff0c\u7ee7\u7eed\u63d0\u4f9b\u670d\u52a1\u3002\u4e8e\u662fRedis\u5b98\u65b9\u63d0\u4f9b\u4e86\u4e00\u79cd\u65b9\u6848: Redis Sentinel\uff08\u54e8\u5175\u6a21\u5f0f\uff09\u3002<\/p>\n
<\/p>\n
<\/p>\n
\u7b80\u5355\u7684\u8bf4\uff0c\u54e8\u5175\u6a21\u5f0f\u5c31\u662f\u5728\u4e3b\u4ece\u57fa\u7840\u4e0a\u589e\u52a0\u4e86\u54e8\u5175\u8282\u70b9\uff0c\u54e8\u5175\u8282\u70b9\u4e0d\u5b58\u50a8\u4e1a\u52a1\u6570\u636e\uff0c\u5b83\u8d1f\u8d23\u76d1\u63a7\u4e3b\u4ece\u8282\u70b9\u7684\u5065\u5eb7\uff0c\u5f53\u4e3b\u8282\u70b9\u5b95\u673a\u65f6\uff0c\u5b83\u80fd\u53ca\u65f6\u53d1\u73b0\uff0c\u5e76\u81ea\u52a8\u9009\u62e9\u4e00\u4e2a\u4ece\u8282\u70b9\uff0c\u5c06\u5176\u5207\u6362\u6210\u4e3b\u8282\u70b9\u3002\u4e3a\u4e86\u907f\u514d\u54e8\u5175\u672c\u8eab\u6210\u4e3a\u5355\u70b9\uff0c\u54e8\u5175\u4e00\u822c\u4e5f\u7531\u591a\u4e2a\u8282\u70b9\u7ec4\u6210\u3002<\/p>\n
\u4e3b\u4ece\u590d\u5236\u4e0e\u54e8\u5175\u6a21\u5f0f\u89e3\u51b3\u4e86\u9ad8\u53ef\u7528\u95ee\u9898\uff0c\u4f46\u6570\u636e\u7684\u4f38\u7f29\u6027\u8fd8\u4e0d\u884c\uff0c\u8fd8\u9700\u8981\u8fdb\u884c\u6c34\u5e73\u62c6\u5206\u3002\u800c\u8fd9\u4e2a\u65f6\u671f\u5927\u6570\u636e\u9ad8\u5e76\u53d1\u7684\u9700\u6c42\u5728\u5feb\u901f\u589e\u957f\uff0c\u54ea\u91cc\u6709\u9700\u6c42\uff0c\u54ea\u91cc\u5c31\u6709\u5e02\u573a\u3002\u5728Redis\u5b98\u65b9\u81ea\u5df1\u7684\u96c6\u7fa4\u65b9\u6848\u51fa\u6765\u4e4b\u524d\uff0cCodis\u5e94\u8fd0\u800c\u751f\u5e76\u5f97\u5230\u5feb\u901f\u53d1\u5c55\u3002<\/p>\n
Codis\u662f\u4e2d\u56fd\u4eba\u5f00\u53d1\u5e76\u5f00\u6e90\u7684\uff0c\u6765\u81ea\u524d\u8c4c\u8c46\u835a\u4e2d\u95f4\u4ef6\u56e2\u961f\u3002Codis\u548c\u540e\u9762\u7684Redis Cluster\u76f8\u4f3c\uff0c\u5c06\u7279\u5b9a\u7684key\u5206\u53d1\u5230\u7279\u5b9a\u7684Redis\u5b9e\u4f8b\u4e0a\uff0c\u9ed8\u8ba4\u5c06key\u5316\u4e3a1024\u4e2a\u69fd\u4f4d\uff1b\u53e6\u5916Codis\u91c7\u7528zookeeper\u6765\u7ef4\u62a4\u8282\u70b9\u95f4\u6570\u636e\u7684\u4e00\u81f4\u6027\uff1b\u66f4\u65b9\u4fbf\u7684\u662fCodis\u63d0\u4f9b\u4e86\u975e\u5e38\u53cb\u597d\u7684\u540e\u53f0\u7ba1\u7406\u754c\u9762\u3002\u66f4\u6df1\u5165\u7684\u5927\u5bb6\u53ef\u4ee5\u81ea\u884c\u53bb\u4e86\u89e3\u3002\u4f46\u662f\u5f53Redis\u5b98\u65b9\u7684\u96c6\u7fa4\u65b9\u6848 Redis Cluster \u53d1\u5e03\u540e\uff0cCodis\u7684\u5883\u9047\u5c31\u6709\u4e9b\u5c34\u5c2c\u4e86\u3002\u6bd5\u7adf\u4e0d\u662f\u4eb2\u751f\u7684\uff0c\u5f88\u591a\u65b0\u7684\u7279\u6027\u603b\u6bd4Redis\u5b98\u65b9\u6162\u4e00\u62cd\u3002<\/p>\n
\u6b63\u662f\u56e0\u4e3a\u5206\u5e03\u5f0f\u662f\u521a\u9700\uff0c\u6240\u4ee5Redis\u5b98\u65b9\u57283.0\u7248\u672c\u63a8\u51fa\u4e86\u81ea\u5df1\u7684\u5206\u5e03\u5f0f\u65b9\u6848\uff0c\u8fd9\u5c31\u662fRedis Cluster\u3002\u8fd9\u4e2a\u540d\u8bcd\u53ef\u80fd\u6709\u4e9b\u6b67\u4e49\uff0c\u5b83\u4e0d\u662f\u7b80\u5355\u5730\u4ee3\u8868Redis\u96c6\u7fa4\uff0c\u800c\u662fRedis\u7684\u4e00\u79cd\u5206\u5e03\u5f0f\u65b9\u6848\uff0c\u8be5\u65b9\u6848\u7684\u540d\u79f0\u5c31\u53ebRedis Cluster\u3002\u4e0b\u9762\u6211\u4eec\u5c31\u91cd\u70b9\u4ecb\u7ecd\u4e0b\u8be5\u65b9\u6848\u3002<\/p>\n
<\/p>\n
<\/p>\n
Redis Cluster \u63d0\u4f9b\u4e86\u4e00\u79cd\u53bb\u4e2d\u5fc3\u5316\u7684\u5206\u5e03\u5f0f\u65b9\u6848\uff0c\u8be5\u65b9\u6848\u53ef\u4ee5\u5b9e\u73b0\u6c34\u5e73\u62c6\u5206\uff0c\u6545\u969c\u8f6c\u79fb\u7b49\u9700\u6c42\u3002<\/p>\n
\u4e00\u4e2aRedis Cluster\u7531\u591a\u4e2aRedis\u8282\u70b9\u7ec4\u6210\uff0c\u8fd9\u91cc\u7684\u8282\u70b9\u6307\u7684\u662fRedis\u5b9e\u4f8b\uff0c\u4e00\u53f0\u670d\u52a1\u5668\u4e0a\u53ef\u80fd\u6709\u591a\u4e2a\u5b9e\u4f8b\u3002\u8fd9\u4e9b\u8282\u70b9\u53ef\u6309\u8282\u70b9\u7ec4\u5212\u5206\uff0c\u6bcf\u4e2a\u8282\u70b9\u7ec4\u91cc\u7684\u8282\u70b9\u5b58\u653e\u76f8\u540c\u7684\u6570\u636e\uff0c\u91cc\u9762\u6709\u4e14\u53ea\u6709\u4e00\u4e2a\u662fmaster\u8282\u70b9\uff0c\u540c\u65f6\u67090\u5230\u591a\u4e2aslave\u8282\u70b9\u3002\u4e0d\u540c\u8282\u70b9\u7ec4\u5b58\u653e\u7684\u6570\u636e\u6ca1\u6709\u4ea4\u96c6\uff0c\u800c\u6240\u6709\u8282\u70b9\u7ec4\u7684\u6570\u636e\u7ec4\u6210\u8fd9\u4e2aRedis Cluster\u7684\u5168\u90e8\u6570\u636e\u96c6\u5408\u3002<\/p>\n
\u5982\u56fe\u6240\u793a\uff0c\u8fd9\u91cc\u67093\u53f0\u670d\u52a1\u5668\uff0c\u6bcf\u53f0\u670d\u52a1\u5668\u4e0a\u67092\u4e2a Redis \u5b9e\u4f8b\u3002\u6807\u53f7\u76f8\u540c\u7684\u8282\u70b9\u7ec4\u6210\u4e00\u4e2a\u8282\u70b9\u7ec4\uff0c\u4ed6\u4eec\u5b58\u653e\u76f8\u540c\u7684\u6570\u636e\uff0c\u5982\u6807\u53f7\u4e3a1\u76842\u4e2a\u8282\u70b9\u7ec4\u6210\u4e00\u4e2a\u8282\u70b9\u7ec4\uff0c\u5176\u4e2d\u6df1\u8272\u7684\u4e3amaster\u8282\u70b9\uff0c\u53e6\u5916\u4e00\u4e2a\u4e3aslave\u8282\u70b9\u3002\u4e5f\u5c31\u662f\u5168\u91cf\u6570\u636e\u88ab\u5212\u5206\u4e3a3\u4efd\uff0c\u5206\u522b\u6807\u53f71\/2\/3\u3002\u6bcf\u4efd\u6570\u636e\u53c8\u67091\u4e2a slave \u8282\u70b9\uff0c\u4ed6\u4eec\u901a\u8fc7\u4e3b\u4ece\u590d\u5236\u4fdd\u5b58\u548c master \u8282\u70b9\u76f8\u540c\u7684\u6570\u636e\u3002\u8fd9\u91cc\u4e3b\u8981\u6709\u4e24\u65b9\u9762\uff1a\u4e00\u662f\u4e3b\u4ece\u590d\u5236\uff0c\u4e8c\u662f\u6570\u636e\u6a2a\u5411\u5212\u5206\uff0c\u5728 Redis \u4e2d\u79f0\u4e3a\u5206\u7247 Sharding\u3002<\/p>\n
<\/p>\n
\u4e3b\u4ece\u8282\u70b9\u6700\u91cd\u8981\u7684\u662f\u5982\u4f55\u4fdd\u8bc1\u4e3b\u4ece\u8282\u70b9\u6570\u636e\u7684\u4e00\u81f4\u6027\u3002\u53ea\u6709 master \u8282\u70b9\u63d0\u4f9b\u6570\u636e\u7684\u5199\u64cd\u4f5c\uff0c\u6570\u636e\u88ab\u5199\u5230 master \u8282\u70b9\u540e\uff0c\u518d\u540c\u6b65\u5230 slave \u8282\u70b9\u3002<\/p>\n
\u4e3b\u4ece\u4e4b\u95f4\u7684\u6570\u636e\u540c\u6b65\u53ef\u4ee5\u5206\u4e3a\u5168\u91cf\u540c\u6b65\u4e0e\u589e\u91cf\u540c\u6b65\u3002<\/p>\n
\u5168\u91cf\u540c\u6b65\u4e5f\u79f0\u4e3a\u5feb\u7167\u540c\u6b65\uff0c\u4e3b\u8282\u70b9\u4e0a\u8fdb\u884c\u4e00\u6b21 bgsave \u64cd\u4f5c\uff0c\u5c06\u5f53\u524d\u5185\u5b58\u7684\u6570\u636e\u5168\u90e8\u5feb\u7167\u5199\u5230\u78c1\u76d8\u6587\u4ef6\u4e2d\uff0c\u7136\u540e\u5c06\u6587\u4ef6\u540c\u6b65\u7ed9\u4ece\u8282\u70b9\u3002\u4ece\u8282\u70b9\u6e05\u7a7a\u5f53\u524d\u5185\u5b58\u5168\u90e8\u6570\u636e\u540e\u5168\u91cf\u52a0\u8f7d\u8be5\u6587\u4ef6\uff0c\u8fd9\u6837\u8fbe\u5230\u4e0e\u4e3b\u8282\u70b9\u6570\u636e\u540c\u6b65\u7684\u76ee\u7684\u3002<\/p>\n
\u4f46\u662f\u5728\u4ece\u8282\u70b9\u52a0\u8f7d\u5feb\u7167\u6587\u4ef6\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4e3b\u8282\u70b9\u8fd8\u5728\u5bf9\u5916\u63d0\u4f9b\u5199\u670d\u52a1\u3002\u6240\u4ee5\u5f53\u4ece\u8282\u70b9\u52a0\u8f7d\u5b8c\u5feb\u7167\u540e\uff0c\u4f9d\u65e7\u53ef\u80fd\u4e0e\u4e3b\u8282\u70b9\u6570\u636e\u4e0d\u4e00\u81f4\uff0c\u8fd9\u65f6\u5c31\u9700\u8981\u589e\u91cf\u540c\u6b65\u4e0a\u573a\u4e86\u3002<\/p>\n
\u589e\u91cf\u540c\u6b65\u7684\u4e0d\u662f\u6570\u636e\uff0c\u800c\u662f\u6307\u4ee4\u6d41\u3002\u4e3b\u8282\u70b9\u4f1a\u5c06\u5bf9\u5f53\u524d\u6570\u636e\u72b6\u6001\u4ea7\u751f\u4fee\u6539\u7684\u6307\u4ee4\u8bb0\u5f55\u5728\u5185\u5b58\u7684\u4e00\u4e2abuffer\u4e2d\uff0c\u7136\u540e\u5f02\u6b65\u5730\u5c06buffer\u540c\u6b65\u5230\u4ece\u8282\u70b9\uff0c\u4ece\u8282\u70b9\u901a\u8fc7\u6267\u884cbuffer\u4e2d\u7684\u6307\u4ee4\uff0c\u8fbe\u5230\u4e0e\u4e3b\u8282\u70b9\u6570\u636e\u4e00\u81f4\u7684\u76ee\u7684\u3002<\/p>\n
Redis\u7684buffer\u662f\u4e00\u4e2a\u5b9a\u957f\u7684\u73af\u5f62\u7ed3\u6784\uff0c\u5f53\u6307\u4ee4\u6d41\u6ee1\u7684\u65f6\u5019\uff0c\u4f1a\u8986\u76d6\u6700\u524d\u9762\u7684\u5185\u5bb9\u3002\u6240\u4ee5\u5f53\u4ece\u8282\u70b9\u4e0a\u6b21\u589e\u91cf\u540c\u6b65\u7531\u4e8e\u5404\u79cd\u539f\u56e0\uff0c\u5bfc\u81f4\u82b1\u8d39\u65f6\u95f4\u8f83\u957f\u65f6\uff0c\u518d\u6b21\u540c\u6b65\u6307\u4ee4\u6d41\u65f6\uff0c\u5c31\u6709\u53ef\u80fd\u524d\u9762\u6ca1\u6709\u540c\u6b65\u7684\u6307\u4ee4\u88ab\u8986\u76d6\u6389\u4e86\u3002\u8fd9\u79cd\u60c5\u51b5\u5c31\u9700\u8981\u8fdb\u884c\u5168\u91cf\u540c\u6b65\u4e86\u3002<\/p>\n
\u6240\u4ee5\u5168\u91cf\u540c\u6b65\u4e0e\u589e\u91cf\u540c\u6b65\u662f\u76f8\u8f85\u76f8\u6210\u7684\u5173\u7cfb\u3002\u5168\u91cf\u540c\u6b65\u65f6\u4e00\u4e2a\u5f88\u8017\u8d44\u6e90\u4e0e\u65f6\u95f4\u7684\u64cd\u4f5c\uff0c\u5982\u679c\u5355\u9760\u5168\u91cf\u540c\u6b65\uff0c\u540c\u6b65\u64cd\u4f5c\u4f1a\u5f88\u91cd\uff0c\u5728\u540c\u6b65\u7684\u957f\u65f6\u95f4\u8fc7\u7a0b\u4e2d\u4e0d\u80fd\u63d0\u4f9b\u670d\u52a1\u3002\u800c\u589e\u91cf\u540c\u6b65\u6709buffer\u5bb9\u91cf\u9650\u5236\uff0c\u4ec5\u4ec5\u9760\u589e\u91cf\u540c\u6b65\u53ef\u80fd\u9020\u6210\u6570\u636e\u4e22\u5931\uff0c\u5bfc\u81f4\u4e3b\u4ece\u6570\u636e\u4e0d\u4e00\u81f4\u3002<\/p>\n
<\/p>\n
<\/p>\n
\u6240\u8c13\u5206\u7247\uff0c\u5c31\u662f\u5c06\u6570\u636e\u96c6\u6309\u7167\u4e00\u5b9a\u89c4\u5219\uff0c\u5206\u6563\u5b58\u50a8\u5728\u5404\u4e2a\u8282\u70b9\u4e0a\u3002\u8fd9\u91cc\u6d89\u53ca\u4e24\u4e2a\u95ee\u9898\uff1a<\/p>\n
1.\u5206\u7247\u89c4\u5219\u662f\u4ec0\u4e48\uff1f
2.\u5982\u4f55\u5b58\u50a8\u5728\u5404\u4e2a\u8282\u70b9\u4e0a\uff1f
Redis\u5c06\u6240\u6709\u6570\u636e\u5206\u4e3a16384\u4e2ahash slot\uff08\u69fd\uff09\uff0c\u6bcf\u6761\u6570\u636e\uff08key-value\uff09\u6839\u636ekey\u503c\u901a\u8fc7\u7b97\u6cd5\u6620\u5c04\u5230\u5176\u4e2d\u4e00\u4e2aslot\u4e0a\uff0c\u8fd9\u6761\u6570\u636e\u5c31\u5b58\u50a8\u5728\u8be5slot\u4e2d\u3002\u6620\u5c04\u7b97\u6cd5\u662f\uff1a<\/p>\n
slotId=crc16(key)%16384<\/code><\/pre>\n Redis\u7684\u6bcf\u4e2akey\u90fd\u4f1a\u57fa\u4e8e\u8be5\u5206\u7247\u89c4\u5219\uff0c\u843d\u5230\u7279\u5b9a\u7684slot\u4e0a\u3002\u800c\u5728\u96c6\u7fa4\u90e8\u7f72\u5b8c\u6210\u65f6\uff0cslot\u7684\u5206\u5e03\u5c31\u5df2\u7ecf\u786e\u5b9a\u4e86\u3002<\/p>\n
172.16.190.78:7001> cluster nodes\n08a5e808d2e6f6b231d73519bd4f05f74614c2a2 172.16.190.77:7000@17000 master - 0 1592218859545 3 connected 10923-16383\n2c75029ab638a48537a4c02ed0ca77a19fc4106b 172.16.190.78:7000@17000 master - 0 1592218860448 1 connected 0-5460\n50884e234c5f1ccf03f5a6d1cc4e6e6dc4779752 172.16.242.36:7000@17000 master - 0 1592218860000 2 connected 5461-10922\nd0381ef4aad364c42e08bf1c2d78168f4901bd90 172.16.190.78:7001@17001 myself,slave 08a5e808d2e6f6b231d73519bd4f05f74614c2a2 0 1592218859000 4 connected\ne5c154dcf02526b807c67bebf0a63b4c98118ffe 172.16.190.77:7001@17001 slave 50884e234c5f1ccf03f5a6d1cc4e6e6dc4779752 0 1592218861048 6 connected\n4a1b49cd77dbd18eba677663777f211be6f68dae 172.16.242.36:7001@17001 slave 2c75029ab638a48537a4c02ed0ca77a19fc4106b 0 1592218860000 5 connected\n<\/code><\/pre>\n \u5982\u4e0a\u56fe\uff0c3\u4e2amaster\u8282\u70b9\uff0c172.16.190.77:7000\u8282\u70b9\u5b58\u653e10923-16383 slot\uff0c172.16.190.78:7000\u8282\u70b9\u5b58\u653e0-5460 slot\uff0c172.16.242.36:7000\u5b58\u653e5461-10922 slot\u3002<\/p>\n
\u5bf9\u4e8e\u4e00\u4e2a\u7a33\u5b9a\u7684\u96c6\u7fa4\uff0cslot\u7684\u5206\u5e03\u4e5f\u662f\u56fa\u5b9a\u7684\u3002\u4f46\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0cslot\u7684\u5206\u5e03\u9700\u8981\u53d1\u751f\u6539\u53d8\uff1a <\/p>\n
\n- \u65b0\u7684master\u52a0\u5165<\/li>\n
- \u8282\u70b9\u5206\u7ec4\u9000\u51fa\u96c6\u7fa4<\/li>\n
- slot\u5206\u5e03\u4e0d\u5747\u5300<\/li>\n<\/ul>\n
\u8fd9\u4e9b\u60c5\u51b5\u4e0b\u5c31\u9700\u8981\u8fdb\u884cslot\u7684\u8fc1\u79fb\u3002slot\u8fc1\u79fb\u7684\u89e6\u53d1\u4e0e\u8fc7\u7a0b\u63a7\u5236\u90fd\u662f\u7531\u5916\u90e8\u7cfb\u7edf\u5b8c\u6210\uff0cRedis\u53ea\u63d0\u4f9b\u80fd\u529b\uff0c\u4f46\u4e0d\u81ea\u52a8\u8fdb\u884cslot\u8fc1\u79fb\u3002<\/p>\n
MOVE & ASKING<\/h1>\n
MOVED\/ASKING \u7c7b\u4f3chttp\u7684\u91cd\u5b9a\u5411\u78013xx\uff0c\u662f\u64cd\u4f5c\u7684\u4e00\u79cd\u9519\u8bef\u8fd4\u56de\u3002<\/p>\n
\u5f53\u5ba2\u6237\u7aef\u5411\u67d0\u4e2a\u8282\u70b9\u53d1\u51fa\u6307\u4ee4\uff0c\u8be5\u8282\u70b9\u53d1\u73b0\u6307\u4ee4\u7684key\u5bf9\u5e94\u7684slot\u4e0d\u5728\u5f53\u524d\u8282\u70b9\u4e0a\uff0c\u8fd9\u65f6Redis\u4f1a\u5411\u5ba2\u6237\u7aef\u53d1\u9001\u4e00\u4e2aMOVED\u6307\u4ee4\uff0c\u544a\u8bc9\u5b83\u6b63\u786e\u7684\u8282\u70b9\uff0c\u7136\u540e\u5ba2\u6237\u7aef\u53bb\u8fde\u8fd9\u4e2a\u6b63\u786e\u7684\u8282\u70b9\u5e76\u8fdb\u884c\u518d\u6b21\u64cd\u4f5c\u3002\u5982\u4e0b\uff0c15495\u4e3akey a\u6240\u5728\u7684slot id\u3002<\/p>\n
172.16.190.78:7001> get a\n(error) MOVED 15495 172.16.190.77:7000<\/code><\/pre>\nASKING \u662f\u5728slot\u8fc1\u79fb\u8fc7\u7a0b\u4e2d\u7684\u4e00\u79cd\u9519\u8bef\u8fd4\u56de\u3002\u5f53\u67d0\u4e2aslot\u5728\u8fc1\u79fb\u8fc7\u7a0b\u4e2d\uff0c\u5ba2\u6237\u7aef\u53d1\u4e86\u4e00\u4e2a\u4f4d\u4e8e\u8be5slot\u7684\u67d0\u4e2akey\u7684\u64cd\u4f5c\u8bf7\u6c42\uff0c\u8bf7\u6c42\u88ab\u8def\u7531\u5230\u65e7\u7684\u8282\u70b9\u3002\u6b64\u65f6\u8be5key\u5982\u679c\u5728\u65e7\u8282\u70b9\u4e0a\u5b58\u5728\uff0c\u5219\u6b63\u5e38\u64cd\u4f5c\uff1b\u5982\u679c\u5728\u65e7\u7684\u8282\u70b9\u4e0a\u627e\u4e0d\u5230\uff0c\u90a3\u4e48\u53ef\u80fd\u8be5key\u5df2\u88ab\u8fc1\u79fb\u5230\u65b0\u7684\u8282\u70b9\u4e0a\uff0c\u4e5f\u53ef\u80fd\u5c31\u6ca1\u6709\u8be5key\uff0c\u6b64\u65f6\u4f1a\u8fd4\u56deASKING\uff0c\u8ba9\u5ba2\u6237\u7aef\u8df3\u8f6c\u5230\u65b0\u7684\u8282\u70b9\u4e0a\u53bb\u6267\u884c\u3002<\/p>\n
MOVED \u4e0e ASKING \u7684\u5171\u540c\u70b9\u662f\u4e24\u8005\u90fd\u662f\u91cd\u5b9a\u5411\uff0c\u533a\u522b\u5728\u4e8e MOVED \u662f\u6c38\u4e45\u91cd\u5b9a\u5411\uff0c\u4e0b\u6b21\u5bf9\u540c\u6837\u7684key
\u8fdb\u884c\u64cd\u4f5c\uff0c\u5ba2\u6237\u7aef\u5c31\u5c06\u8bf7\u6c42\u53d1\u9001\u5230\u6b63\u786e\u7684\u8282\u70b9\uff0c\u800c ASKING \u662f\u4e34\u65f6\u91cd\u5b9a\u5411\uff0c\u5b83\u53ea\u5bf9\u8fd9\u6b21\u64cd\u4f5c\u8d77\u4f5c\u7528\uff0c\u4e0d\u4f1a\u66f4\u65b0\u5ba2\u6237\u7aef\u7684\u69fd\u4f4d\u5173\u7cfb\u8868\u3002<\/p>\n
<\/p>\n
<\/p>\n
\u6545\u969c\u6062\u590d<\/h1>\n
\u524d\u9762\u63d0\u5230Redis Cluster\u662f\u4e00\u4e2a\u53bb\u4e2d\u5fc3\u5316\u7684\u96c6\u7fa4\u65b9\u6848\u3002\u6bd4\u5982Codis\u91c7\u7528zookeeper\u6765\u7ef4\u62a4\u8282\u70b9\u95f4\u72b6\u6001\u4e00\u81f4\u6027\uff0cRedis\u54e8\u5175\u6a21\u5f0f\u662f\u54e8\u5175\u6765\u7ba1\u7406\u8282\u70b9\u7684\u72b6\u6001\uff0c\u8fd9\u4e9b\u90fd\u662f\u4e2d\u5fc3\u5316\u7684\u4f8b\u5b50\u3002Redis Cluster\u6ca1\u6709\u4e13\u95e8\u7528\u4e8e\u7ef4\u62a4\u8282\u70b9\u72b6\u6001\u7684\u8282\u70b9\uff0c\u800c\u662f\u6240\u6709\u8282\u70b9\u901a\u8fc7Gossip\u534f\u8bae\u76f8\u4e92\u901a\u4fe1\uff0c\u5e7f\u64ad\u81ea\u5df1\u7684\u72b6\u6001\u4ee5\u53ca\u81ea\u5df1\u5bf9\u6574\u4e2a\u96c6\u7fa4\u8ba4\u77e5\u7684\u6539\u53d8\u3002<\/p>\n
\u5982\u679c\u4e00\u4e2a\u8282\u70b9\u5b95\u6389\u4e86\uff0c\u5176\u4ed6\u8282\u70b9\u548c\u5b83\u8fdb\u884c\u901a\u4fe1\u65f6\uff0c\u4f1a\u53d1\u73b0\u6539\u8282\u70b9\u5931\u8054\u3002\u5f53\u67d0\u4e2a\u8282\u70b9\u53d1\u73b0\u5176\u4ed6\u8282\u70b9\u5931\u8054\u65f6\uff0c\u4f1a\u5c06\u8fd9\u4e2a\u5931\u8054\u8282\u70b9\u72b6\u6001\u53d8\u6210PFail\uff08possible fail\uff09\uff0c\u5e76\u5e7f\u64ad\u7ed9\u5176\u4ed6\u8282\u70b9\u3002\u5f53\u4e00\u4e2a\u8282\u70b9\u6536\u5230\u67d0\u4e2a\u8282\u70b9PFail\u7684\u6570\u91cf\u8fbe\u5230\u4e86\u4e3b\u8282\u70b9\u7684\u5927\u591a\u6570\uff0c\u5c31\u6807\u8bb0\u8be5\u8282\u70b9\u4e3aFail\uff0c\u5e76\u8fdb\u884c\u5e7f\u64ad\uff0c\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u786e\u8ba4\u8282\u70b9\u6545\u969c\u3002<\/p>\n
\u5f53slave\u53d1\u73b0\u5176master\u72b6\u6001\u4e3aFail\u540e\uff0c\u5b83\u4f1a\u53d1\u8d77\u9009\u4e3e\uff0c\u5982\u679c\u5176\u4ed6master\u8282\u70b9\u90fd\u540c\u610f\uff0c\u5219\u8be5slave\u8fdb\u884c\u4ece\u4e3b\u5207\u6362\uff0c\u53d8\u6210master\u8282\u70b9\u3002\u540c\u65f6\u4f1a\u5c06\u81ea\u5df1\u7684\u72b6\u6001\u5e7f\u64ad\u7ed9\u5176\u4ed6\u8282\u70b9\uff0c\u8fbe\u5230\u5927\u5bb6\u4fe1\u606f\u4e00\u81f4\u6027\u3002<\/p>\n
\u6839\u636e\u4e0a\u9762\u7684\u539f\u7406\uff0c\u4e0b\u9762\u60c5\u51b5\u4e0b\u662f\u65e0\u6cd5\u81ea\u52a8\u4ece\u4e3b\u5207\u6362\uff0c\u8fbe\u5230\u96c6\u7fa4\u7ee7\u7eed\u53ef\u7528\u76ee\u7684\u7684\uff0c\u5728\u5b9e\u9645\u90e8\u7f72\u65f6\u5e94\u907f\u514d\uff1a<\/p>\n
\u5982\u679c\u4e00\u4e2a\u8282\u70b9\u7ec4\u4e2d\u7684master\u4e0eslave\u90e8\u7f72\u5728\u540c\u4e00\u670d\u52a1\u5668\u4e0a\uff0c\u5f53\u670d\u52a1\u5668\u53d1\u751f\u6545\u969c\u65f6\uff0cmaster\u4e0esalve\u540c\u65f6Fail\u3002
\u6bd4\u5982\u603b\u51713\u4e2amaster\uff0c\u5176\u4e2d2\u4e2amaster\u90e8\u7f72\u5728\u540c\u4e00\u670d\u52a1\u5668\u4e0a\uff0c\u5f53\u670d\u52a1\u5668\u53d1\u751f\u6545\u969c\u65f6\uff0c\u8fd9\u4e24\u4e2amaster\u540c\u65f6Fail\uff0cslave\u65e0\u6cd5\u5b8c\u6210\u4ece\u4e3b\u5207\u6362\uff0c\u56e0\u4e3aPFail\u7684\u6570\u91cf\u65e0\u6cd5\u8fbe\u5230\u4e3b\u8282\u70b9\u7684\u5927\u591a\u6570\u3002
\u5f53\u96c6\u7fa4\u8282\u70b9\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u9700\u8981\u5c06\u53d8\u5316\u540c\u6b65\u5230\u5ba2\u6237\u7aef\uff0c\u5ba2\u6237\u7aef\u624d\u80fd\u6839\u636e\u65b0\u7684\u96c6\u7fa4\u62d3\u6251\u6765\u5411\u6b63\u786e\u7684\u8282\u70b9\u53d1\u9001\u8bf7\u6c42\u3002<\/p>\n
\u6bd4\u5982Redis\u5ba2\u6237\u7aefLettuce\uff0c\u5728\u8fde\u63a5\u914d\u7f6e\u4e2d\u914d\u7f6e\u4e86\u591a\u4e2a\u8282\u70b9\uff0cLettuce\u4f1a\u9009\u62e9\u5176\u4e2d\u4e00\u4e2a\u53ef\u7528\u8282\u70b9\u8fdb\u884c\u8fde\u63a5\u3002\u5728\u8fde\u63a5\u65ad\u5f00\u4e4b\u524d\uff0c\u5982\u679c\u8be5\u8282\u70b9\u6302\u6389\uff0cLettuce\u4e0d\u4f1a\u81ea\u52a8\u8fdb\u884c\u8282\u70b9\u5207\u6362\uff0c\u6b64\u65f6\u4f1a\u4e0d\u65ad\u5730\u629b\u8fde\u63a5\u5f02\u5e38\uff0c\u65e0\u6cd5\u7ee7\u7eed\u8bfb\u5199\u3002Lettuce\u63d0\u4f9b\u4e86\u5728\u8fde\u63a5\u8fc7\u7a0b\u4e2d\u81ea\u9002\u5e94\u5237\u65b0\u96c6\u7fa4\u62d3\u6251\uff0c\u5373\u5728\u8fde\u63a5\u5931\u8d25\u65f6\u81ea\u52a8\u5237\u65b0\uff0c\u4e5f\u53ef\u4ee5\u8bbe\u8ba1\u5b9a\u65f6\u5237\u65b0\u3002<\/p>\n
ClusterTopologyRefreshOptions topologyRefreshOptions = ClusterTopologyRefreshOptions.builder()\n .enablePeriodicRefresh(Duration.ofMinutes(10))\n .enableAllAdaptiveRefreshTriggers()\n .adaptiveRefreshTriggersTimeout(Duration.ofSeconds(30)).build();\n<\/code><\/pre>\n
\u53c2\u8003\uff1a
1.\u300a\u6df1\u5165\u5206\u5e03\u5f0f\u7f13\u5b58 \u4ece\u539f\u7406\u5230\u5b9e\u6218\u300b\u4e8e\u541b\u6cfd \u66f9\u6d2a\u4f1f \u90b1\u7855\u7b49\u8457<\/p>\n
2.\u300aRedis \u6df1\u5ea6\u5386\u9669\uff1a\u6838\u5fc3\u539f\u7406\u4e0e\u5e94\u7528\u5b9e\u8df5\u300b\u8001\u94b1<\/p>\n
3.Redis\u5b98\u7f51\uff1ahttps:\/\/lettuce.io\/core\/release\/reference\/index.html
<\/p>\n","protected":false},"excerpt":{"rendered":"Redis\u7684\u5206\u5e03\u5f0f\u90e8\u7f72\u8be5\u6587\u7ae0\u4ece\u5b58\u50a8\u7684\u5206\u5e03\u5f0f\u90e8\u7f72\u5e38\u7528\u601d\u8def\u51fa\u53d1\uff0c\u4ecb\u7ecd\u4e86\u6c34\u5e73\u62c6\u5206\u3001\u4e3b\u4ece\u590d\u5236\u8fd9\u4e24\u79cd\u6838\u5fc3\u601d\u8def\uff0c\u5e76\u4ecb\u7ecd\u4e86redis\u7684\u5b9e\u73b0\uff0c...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[83],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/379"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=379"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/379\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}