{"id":22849,"date":"2025-04-19T06:36:40","date_gmt":"2025-04-18T22:36:40","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/22849.html"},"modified":"2025-04-19T06:36:40","modified_gmt":"2025-04-18T22:36:40","slug":"redis%e9%ab%98%e5%8f%af%e7%94%a8%e9%83%a8%e7%bd%b2%ef%bc%9a3%e5%8f%b0%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%89%93%e9%80%a0%e5%93%a8%e5%85%b5%e9%9b%86%e7%be%a4","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/22849.html","title":{"rendered":"Redis\u9ad8\u53ef\u7528\u90e8\u7f72\uff1a3\u53f0\u670d\u52a1\u5668\u6253\u9020\u54e8\u5175\u96c6\u7fa4"},"content":{"rendered":"<h2>1\u3001Redis\u96c6\u7fa4\u4ecb\u7ecd<\/h2>\n<\/p>\n<p>Redis \u96c6\u7fa4&#xff08;Redis Cluster&#xff09;\u662fRedis\u63d0\u4f9b\u7684\u4e00\u79cd\u5206\u5e03\u5f0f\u90e8\u7f72\u65b9\u5f0f&#xff0c;\u65e8\u5728\u63d0\u4f9b\u9ad8\u53ef\u7528\u6027\u3002\u5982\u679c\u67d0\u4e2a\u4e3b\u8282\u70b9\u53d1\u751f\u6545\u969c&#xff0c;\u96c6\u7fa4\u80fd\u591f\u81ea\u52a8\u8fdb\u884c\u6545\u969c\u8f6c\u79fb&#xff0c;\u5c06\u526f\u672c\u63d0\u5347\u4e3a\u4e3b\u8282\u70b9&#xff0c;\u4ece\u800c\u4fdd\u8bc1\u6570\u636e\u7684\u6301\u7eed\u53ef\u7528&#xff0c;Redis \u96c6\u7fa4\u975e\u5e38\u9002\u5408\u4e8e\u5927\u89c4\u6a21\u7f13\u5b58\u7cfb\u7edf\u548c\u5927\u6570\u636e\u91cf\u573a\u666f\u3002<\/p>\n<\/p>\n<h2>2\u3001\u642d\u5efa\u96c6\u7fa4\u7684\u51e0\u79cd\u65b9\u5f0f<\/h2>\n<\/p>\n<ul>\n<li>\n<p>\u4e3b\u4ece\u590d\u5236&#xff08;Master-Slave&#xff09;&#xff1a;\u8fd9\u79cd\u6a21\u5f0f\u4e0b&#xff0c;\u4e3b\u8282\u70b9&#xff08;Master&#xff09;\u8d1f\u8d23\u6570\u636e\u5199\u5165\u548c\u8bfb\u53d6&#xff0c;\u800c\u4ece\u8282\u70b9&#xff08;Slave&#xff09;\u5219\u53ea\u80fd\u7528\u4e8e\u6570\u636e\u8bfb\u53d6\u548c\u5907\u4efd&#xff0c;\u4e0d\u80fd\u591f\u5199\u5165\u6570\u636e\u3002\u82e5\u4e3b\u8282\u70b9\u53d1\u751f\u6545\u969c&#xff0c;\u9700\u4eba\u5de5\u4ecb\u5165&#xff0c;\u5c06\u67d0\u4e2a\u4ece\u8282\u70b9\u63d0\u5347\u4e3a\u65b0\u7684\u4e3b\u8282\u70b9\u3002\u8be5\u6a21\u5f0f\u6ca1\u6709\u81ea\u52a8\u6545\u969c\u8f6c\u79fb&#xff0c;\u9700\u8981\u624b\u52a8\u5904\u7406\u6545\u969c&#xff0c;\u56e0\u6b64\u53ef\u7528\u6027\u8f83\u5dee\u3002\u6700\u5c11\u9700\u89812\u53f0\u670d\u52a1\u5668\u642d\u5efa\u4e00\u4e3b\u4e00\u4ece\u6216\u8005\u591a\u53f0\u670d\u52a1\u5668\u642d\u5efa\u4e00\u4e3b\u591a\u4ece\u3002\u5728\u8d44\u6e90\u4e0d\u5141\u8bb8\u7684\u60c5\u51b5\u4e0b&#xff0c;\u53ef\u4ee5\u501f\u52a9\u9ad8\u53ef\u7528\u5de5\u5177\u5b9e\u73b0\u81ea\u52a8\u6545\u969c\u8f6c\u79fb\u3002\u5982&#xff1a;Keepalived &#043; Redis\u4e3b\u4ece\u5b9e\u73b0\u4e3b\u5907\u53cc\u6d3b\u3002<\/p>\n<\/li>\n<li>\n<p>\u54e8\u5175\u6a21\u5f0f&#xff08;Redis Sentinel&#xff09;&#xff1a; \u54e8\u5175\u6a21\u5f0f\u4e0b&#xff0c;\u9700\u8981\u989d\u5916\u642d\u5efa\u54e8\u5175&#xff08;Sentinel&#xff09;\u670d\u52a1\u7528\u4e8e\u76d1\u63a7Redis\u96c6\u7fa4\u4e2d\u7684\u4e3b\u8282\u70b9&#xff0c;\u5e76\u4e14\u80fd\u591f\u5728\u4e3b\u8282\u70b9\u53d1\u751f\u6545\u969c\u65f6\u81ea\u52a8\u8fdb\u884c\u6545\u969c\u8f6c\u79fb&#xff0c;\u901a\u8fc7\u9009\u4e3e\u7684\u65b9\u5f0f&#xff0c;\u5c06\u4ece\u8282\u70b9\u5347\u7ea7\u4e3a\u4e3b\u8282\u70b9\u3002\u5b83\u63d0\u4f9b\u9ad8\u53ef\u7528\u6027\u548c\u81ea\u52a8\u6062\u590d\u80fd\u529b\u3002\u5e38\u89c1\u7684\u96c6\u7fa4\u65b9\u5f0f\u4e3a&#xff1a;1\u4e3b2\u4ece &#043; 3\u4e2aSentinel\u8fdb\u7a0b&#xff0c;\u54e8\u5175&#xff08;Sentinel&#xff09;\u8fdb\u7a0b\u53ef\u4ee5\u90e8\u7f72\u5728\u76f8\u540c\u76843\u4e2a\u8282\u70b9\u4e0a&#xff0c;\u4ee5\u51cf\u5c11\u670d\u52a1\u5668\u8d44\u6e90\u3002\u6bd4\u8f83\u9002\u7528\u4e8e\u9700\u8981\u9ad8\u53ef\u7528\u7684\u4e2d\u5c0f\u578b\u5e94\u7528&#xff0c;\u6570\u636e\u91cf\u4e0d\u662f\u7279\u522b\u5927\u7684\u573a\u666f\u3002<\/p>\n<\/li>\n<li>\n<p>\u5206\u7247\u96c6\u7fa4&#xff08;Redis Cluster&#xff09;&#xff1a;\u8fd9\u4e00\u6a21\u5f0f\u652f\u6301\u6570\u636e\u5206\u7247&#xff08;Sharding&#xff09;\u5b58\u50a8\u548c\u591a\u8282\u70b9\u6c34\u5e73\u6269\u5c55&#xff0c;\u6709\u6548\u7684\u63d0\u9ad8\u4e86\u5185\u5b58\u5229\u7528\u7387\u548c\u5199\u5165\u6027\u80fd\u3002\u63d2\u5165\u7684\u6570\u636e\u4f1a\u6839\u636e\u4e00\u5b9a\u7684\u89c4\u5219&#xff08;\u54c8\u5e0c\u69fd&#xff09;\u88ab\u5206\u5e03\u5230\u4e0d\u540c\u7684\u8282\u70b9\u4e0a&#xff0c;\u6bcf\u4e2a\u8282\u70b9\u8d1f\u8d23\u6570\u636e\u7684\u4e00\u4e2a\u5b50\u96c6&#xff08;\u901a\u8fc7\u54c8\u5e0c\u69fd\u7684\u8303\u56f4&#xff09;&#xff0c;\u5b83\u4f1a\u81ea\u52a8\u7ba1\u7406\u6570\u636e\u7684\u5206\u5e03\u548c\u8fc1\u79fb\u3002\u5b83\u91c7\u7528\u4e86\u53bb\u4e2d\u5fc3\u5316\u7684\u591a\u4e3b\u591a\u4ece\u67b6\u6784&#xff0c;\u6700\u4f4e\u914d\u7f6e\u8981\u6c42\u4e3a3\u4e2a\u4e3b\u8282\u70b9&#xff08;Master&#xff09;\u548c3\u4e2a\u4ece\u8282\u70b9&#xff08;Slave&#xff09;&#xff0c;\u901a\u5e38\u60c5\u51b5\u4e0b\u53ef\u4ee5\u57283\u53f0\u670d\u52a1\u5668\u4e2d\u6bcf\u53f0\u670d\u52a1\u5668\u914d\u7f6e\u4e00\u4e3b\u4e00\u4ece\u8fdb\u884c\u642d\u5efa&#xff0c;\u867d\u7136\u8fd9\u6837\u4f1a\u5f71\u54cd\u4e00\u5b9a\u7684\u6027\u80fd&#xff0c;\u4f46\u662f\u53ef\u4ee5\u51cf\u5c11\u670d\u52a1\u5668\u6240\u9700\u7684\u8d44\u6e90\u3002\u5982\u679c\u9700\u8981\u53d1\u6325\u5176\u6700\u5927\u7684\u4ef7\u503c&#xff0c;\u81f3\u5c11\u9700\u89816\u53f0\u670d\u52a1\u5668\u8282\u70b9\u624d\u53ef\u4ee5\u3002\u8be5\u96c6\u7fa4\u975e\u5e38\u9002\u7528\u4e8e\u66f4\u5927\u89c4\u6a21\u548c\u66f4\u9ad8\u8981\u6c42\u7684\u6570\u636e\u5904\u7406\u573a\u666f\u3002<\/p>\n<\/li>\n<\/ul>\n<h2>3\u3001\u9009\u62e9\u96c6\u7fa4\u6a21\u5f0f<\/h2>\n<\/p>\n<p>\u8fd9\u91cc\u6839\u636e\u6240\u5c5e\u7684\u4e1a\u52a1\u7cfb\u7edf\u9700\u8981\u7684Redis\u9700\u6c42\u8fdb\u884c\u5408\u9002\u7684\u9009\u62e9\u3002\u4f7f\u7528Redis Cluster\u00a0\u6a21\u5f0f\u642d\u5efa\u5206\u7247\u96c6\u7fa4\u7684\u8981\u6c42\u6bd4\u8f83\u9ad8&#xff0c;\u5ba2\u6237\u7aef\u5fc5\u987b\u8be5\u652f\u6301\u96c6\u7fa4\u6a21\u5f0f&#xff0c;\u800c\u4e14\u914d\u7f6eRedis Cluster\u00a0\u9700\u8981\u6bd4\u666e\u901a\u7684Redis\u4e3b\u4ece\u6a21\u5f0f\u590d\u6742\u7684\u591a&#xff0c;\u9700\u8981\u7684\u6210\u672c\u6bd4\u8f83\u9ad8\u3002\u53ea\u6709\u5f53\u5e94\u7528\u9700\u8981\u9ad8\u6027\u80fd\u3001\u9ad8\u541e\u5410\u91cf&#xff0c;\u5e76\u4e14\u5bf9\u6570\u636e\u5206\u5e03\u548c\u6269\u5c55\u6027\u6709\u9700\u6c42\u65f6&#xff0c;Redis Cluster\u662f\u66f4\u597d\u7684\u9009\u62e9\u3002\u4f7f\u7528Redis Sentinel\u6a21\u5f0f\u642d\u5efa\u96c6\u7fa4\u76f8\u5bf9\u6765\u8bf4\u4e0d\u662f\u7279\u522b\u590d\u6742&#xff0c;\u53ea\u9700\u8981\u642d\u5efaRedis\u4e3b\u4ece\u6a21\u5f0f\u540e\u5728\u542f\u52a8\u76f8\u5173\u7684Sentinel\u5373\u53ef\u3002\u5982\u679c\u6570\u636e\u91cf\u4e0d\u662f\u7279\u522b\u5927&#xff0c;\u4f7f\u7528Redis\u96c6\u7fa4\u53ea\u662f\u7528\u6765\u63d0\u4f9b\u9ad8\u53ef\u7528\u6027\u548c\u6545\u969c\u8f6c\u79fb&#xff0c;\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u00a0Redis Sentinel\u00a0\u3002\u672c\u7bc7\u4f7f\u7528\u00a0\u54e8\u5175\u6a21\u5f0f&#xff08;Redis Sentinel&#xff09;\u00a0\u8fdb\u884c\u642d\u5efaRedis\u96c6\u7fa4\u3002<\/p>\n<\/p>\n<p>\u54e8\u5175\u6a21\u5f0f&#xff08;Redis Sentinel&#xff09;\u76f8\u5173\u4ecb\u7ecd&#xff1a;<\/p>\n<\/p>\n<p>Redis\u54e8\u5175\u6a21\u5f0f&#xff08;Redis Sentinel&#xff09;\u9996\u6b21\u5f15\u5165\u662f\u5728\u00a0Redis 2.8.0\u00a0\u7248\u672c\u4e2d\u3002\u8be5\u7248\u672c\u4e8e\u00a02013\u5e7412\u6708\u00a0\u53d1\u5e03\u3002Redis Sentinel\u7684\u8bbe\u8ba1\u521d\u8877\u662f\u4e3a\u4e86\u5f25\u8865\u00a0Redis\u00a0\u5728\u9ad8\u53ef\u7528\u6027\u548c\u81ea\u52a8\u6545\u969c\u8f6c\u79fb\u65b9\u9762\u7684\u4e0d\u8db3&#xff0c;\u7279\u522b\u662f\u5bf9\u4e8e\u4e3b\u4ece\u590d\u5236\u67b6\u6784\u4e2d\u7684\u4e3b\u8282\u70b9\u5b95\u673a\u7684\u5bb9\u9519\u5904\u7406\u3002\u901a\u8fc7Redis Sentinel\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u68c0\u6d4b\u6545\u969c\u548c\u81ea\u52a8\u6545\u969c\u8f6c\u79fb&#xff0c;\u4ece\u800c\u63d0\u9ad8\u00a0Redis\u00a0\u7684\u53ef\u7528\u6027\u548c\u53ef\u9760\u6027\u3002\u5728\u8fd9\u4e00\u6a21\u5f0f\u4e2d&#xff0c;\u54e8\u5175\u8d1f\u8d23\u5b9e\u65f6\u76d1\u63a7\u4e3b\u8282\u70b9\u7684\u8fd0\u884c\u72b6\u51b5\u3002\u5982\u679c\u4e3b\u8282\u70b9\u51fa\u73b0\u6545\u969c&#xff0c;\u54e8\u5175\u5c06\u57fa\u4e8e\u9884\u8bbe\u7684\u6295\u7968\u673a\u5236&#xff0c;\u81ea\u52a8\u5c06\u67d0\u4e2a\u4ece\u8282\u70b9\u664b\u5347\u4e3a\u65b0\u7684\u4e3b\u8282\u70b9&#xff0c;\u4ee5\u4fdd\u969c\u670d\u52a1\u7684\u8fde\u7eed\u6027\u548c\u6570\u636e\u7684\u53ef\u7528\u6027\u3002\u54e8\u5175\u672c\u8eab\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u8fdb\u7a0b&#xff0c;\u8fd0\u884c\u5728Redis\u672c\u8eab\u8fdb\u7a0b\u4e4b\u5916\u3002\u5b83\u901a\u8fc7\u6301\u7eed\u76d1\u63a7 Redis \u670d\u52a1\u5668\u7684\u72b6\u6001&#xff0c;\u5305\u62ec\u4e3b\u8282\u70b9\u548c\u4ece\u8282\u70b9&#xff0c;\u5e76\u5b9a\u671f\u901a\u8fc7 ping \u4e3b\u4ece\u8282\u70b9\u6765\u786e\u8ba4\u5b83\u4eec\u662f\u5426\u4ecd\u7136\u53ef\u7528&#xff0c;\u6765\u5224\u65ad\u88ab\u76d1\u63a7\u7684Redis\u5b9e\u4f8b\u662f\u5426\u6b63\u5e38\u8fd0\u884c\u6765\u786e\u4fddRedis\u670d\u52a1\u7684\u7a33\u5b9a\u6027\u3002<\/p>\n<\/p>\n<h2>4\u3001\u73af\u5883\u51c6\u5907<\/h2>\n<\/p>\n<h3>4.1\u3001\u670d\u52a1\u5668\u4fe1\u606f<\/h3>\n<\/p>\n<p>\u6839\u636e\u4ee5\u4e0a\u642d\u5efa\u7684\u51e0\u79cd\u65b9\u5f0f\u548c\u76f8\u5173\u5efa\u8bae&#xff0c;\u57283\u53f0\u670d\u52a1\u5668\u8282\u70b9\u7684\u60c5\u51b5\u4e0b&#xff0c;\u9996\u9009Redis Sentinel\u54e8\u5175\u6a21\u5f0f\u8fdb\u884c\u642d\u5efa\u3002\u4ee5\u4e0b\u662f\u670d\u52a1\u5668\u4fe1\u606f&#xff1a;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"209\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418223639-6802d3f731b0d.png\" width=\"494\" \/><\/p>\n<\/p>\n<h3>4.2\u3001\u8f6f\u4ef6\u7248\u672c<\/h3>\n<\/p>\n<ul>\n<li>\n<p>\u64cd\u4f5c\u7cfb\u7edf:\u00a0CentOS 7.9<\/p>\n<\/li>\n<li>\n<p>Redis \u7248\u672c:\u00a05.0<\/p>\n<\/li>\n<\/ul>\n<h2>5\u3001\u914d\u7f6eRedis\u4e3b\u4ece\u590d\u5236<\/h2>\n<\/p>\n<h3>5.1\u3001\u521b\u5efa\u76ee\u5f55<\/h3>\n<\/p>\n<p>\u5206\u522b\u5728\u4e09\u53f0\u670d\u52a1\u5668\u4e2d\u521b\u5efa\u4ee5\u4e0b\u76ee\u5f55&#xff1a;<\/p>\n<\/p>\n<p># \u9009\u62e9Redis\u5b58\u50a8\u6587\u4ef6\u76ee\u5f55&#xff0c;\u521b\u5efa\u4ee5\u4e0b\u76ee\u5f55<br \/>\nmkdir -p \/root\/docker\/redis\/config \/root\/docker\/redis\/data \/root\/docker\/redis\/sentinel<\/p>\n<p># config \u5b58\u5165redis\u914d\u7f6e\u6587\u4ef6\u4fe1\u606f \u5982&#xff1a;redis.conf<br \/>\n# data \u5b58\u5165\u6301\u4e45\u5316Redis\u6570\u636e<br \/>\n# sentinel \u5b58\u5165\u54e8\u5175\u7684\u914d\u7f6e\u6587\u4ef6\u4fe1\u606f \u5982&#xff1a;sentinel.conf <\/p>\n<p>\u4e0b\u8f7d\u914d\u7f6e\u6587\u4ef6redis.conf\u5230\u672c\u5730&#xff0c;\u5e76\u4e0a\u4f20\u5230\u670d\u52a1\u5668config\u76ee\u5f55&#xff0c;\u4e0b\u8f7d\u5730\u5740&#xff1a;https:\/\/github.com\/redis\/redis\/blob\/5.0.4\/redis.conf<\/p>\n<\/p>\n<h3>5.2\u3001\u914d\u7f6eRedis\u914d\u7f6e\u6587\u4ef6<\/h3>\n<\/p>\n<p>\u5728\u00a0node1\u3001node2\u00a0\u548c\u00a0node3\u00a0\u4e0a\u66f4\u65b0Redis\u914d\u7f6e\u6587\u4ef6\u4fe1\u606f\u00a0vim ~\/docker\/redis\/config\/redis.conf&#xff0c;\u914d\u7f6e\u5bc6\u7801\u548c\u4e3b\u4ece\u5173\u7cfb\u3002<\/p>\n<\/p>\n<h5>\u4e3b\u8282\u70b9&#xff08;node1&#xff09;&#xff1a;<\/h5>\n<\/p>\n<p># \u8fd0\u884c\u7aef\u53e3<br \/>\nport 6379<br \/>\n# \u5141\u8bb8\u5916\u90e8\u6240\u6709IP\u8bbf\u95ee<br \/>\nbind 0.0.0.0<br \/>\n# \u662f\u5426\u4ee5\u5b88\u62a4\u8fdb\u7a0b\u8fd0\u884c&#xff0c;Docker\u8fd0\u884c\u5fc5\u987b\u8bbe\u7f6e\u4e3ano\u3002<br \/>\ndaemonize no<br \/>\n# redis\u5bc6\u7801<br \/>\nrequirepass &#034;1234qwer&#034;<br \/>\n# \u914d\u7f6e\u4e3b\u4ece\u8fde\u63a5\u5bc6\u7801<br \/>\nmasterauth &#034;1234qwer&#034;<br \/>\n# \u5f00\u542f\u6301\u4e45\u5316<br \/>\nappendonly yes<\/p>\n<p>#\u5bf9\u5916\u56fa\u5b9a\u5f00\u653eIP\u5730\u5740<br \/>\nslave-announce-ip 192.168.42.131<br \/>\n#\u5bf9\u5916\u56fa\u5b9a\u5f00\u653e\u7aef\u53e3<br \/>\nslave-announce-port 6379 <\/p>\n<h5>\u4ece\u8282\u70b9&#xff08;node2&#xff09;&#xff1a;<\/h5>\n<\/p>\n<p>port 6379<br \/>\nbind 0.0.0.0<br \/>\ndaemonize no<br \/>\nrequirepass &#034;1234qwer&#034;<br \/>\nmasterauth &#034;1234qwer&#034;<br \/>\nappendonly yes<\/p>\n<p># \u5bf9\u5916\u56fa\u5b9a\u5f00\u653eIP\u5730\u5740<br \/>\nslave-announce-ip 192.168.42.132<br \/>\n# \u5bf9\u5916\u56fa\u5b9a\u5f00\u653e\u7aef\u53e3<br \/>\nslave-announce-port 6379<br \/>\n# \u914d\u7f6e\u4e3b\u8282\u70b9\u7684IP\u548c\u7aef\u53e3<br \/>\nREPLICAOF  192.168.42.131 6379 <\/p>\n<h5>\u4ece\u8282\u70b9&#xff08;node3&#xff09;<\/h5>\n<\/p>\n<p>port 6379<br \/>\nbind 0.0.0.0<br \/>\ndaemonize no<br \/>\nrequirepass &#034;1234qwer&#034;<br \/>\nmasterauth &#034;1234qwer&#034;<br \/>\nappendonly yes<\/p>\n<p># \u5bf9\u5916\u56fa\u5b9a\u5f00\u653eIP\u5730\u5740<br \/>\nslave-announce-ip 192.168.42.133<br \/>\n# \u5bf9\u5916\u56fa\u5b9a\u5f00\u653e\u7aef\u53e3<br \/>\nslave-announce-port 6379<br \/>\n# \u914d\u7f6e\u4e3b\u8282\u70b9\u7684IP\u548c\u7aef\u53e3<br \/>\nREPLICAOF  192.168.42.131 6379 <\/p>\n<h3>5.3\u3001\u542f\u52a8Redis\u5bb9\u5668<\/h3>\n<\/p>\n<h5>\u4e3b\u8282\u70b9&#xff08;node1&#xff09;&#xff1a;<\/h5>\n<\/p>\n<p>docker run -d -p 6379:6379 &#8211;restart&#061;always &#8211;privileged&#061;true &#8211;name redis-master -v ~\/docker\/redis\/config\/redis.conf:\/etc\/redis\/redis.conf -v ~\/docker\/redis\/data:\/data redis:5.0 redis-server \/etc\/redis\/redis.conf <\/p>\n<h5>\u4ece\u8282\u70b9&#xff08;node2&#xff09;&#xff1a;<\/h5>\n<\/p>\n<p>docker run -d -p 6379:6379 &#8211;restart&#061;always &#8211;privileged&#061;true &#8211;name redis-slave -v ~\/docker\/redis\/config\/redis.conf:\/etc\/redis\/redis.conf -v ~\/docker\/redis\/data:\/data redis:5.0 redis-server \/etc\/redis\/redis.conf <\/p>\n<h5>\u4ece\u8282\u70b9&#xff08;node3&#xff09;:<\/h5>\n<\/p>\n<p>docker run -d -p 6379:6379 &#8211;restart&#061;always &#8211;privileged&#061;true &#8211;name redis-slave -v ~\/docker\/redis\/config\/redis.conf:\/etc\/redis\/redis.conf -v ~\/docker\/redis\/data:\/data redis:5.0 redis-server \/etc\/redis\/redis.conf <\/p>\n<h3>5.4\u3001\u9a8c\u8bc1\u4e3b\u4ece\u590d\u5236<\/h3>\n<\/p>\n<p>\u767b\u5f55redis\u8f93\u5165&#xff1a;info replication\u00a0\u53ef\u4ee5\u67e5\u770bRedis\u96c6\u7fa4\u914d\u7f6e\u4fe1\u606f\u3002\u5982\u679c\u642d\u5efa\u6210\u529f&#xff0c;\u4f1a\u663e\u793a\u8282\u70b9\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p>\u4e3b\u8282\u70b9(node1)\u663e\u793a\u4ee5\u4e0b\u4fe1\u606f&#xff1a;<\/p>\n<\/p>\n<p># \u9996\u5148\u901a\u8fc7docker\u8fdb\u5165redis\u5bb9\u5668<br \/>\ndocker exec -it redis-master bash<br \/>\n# \u8fdb\u5165\u6210\u529f\u540e&#xff0c;\u767b\u5f55redis<br \/>\nredis-cli -p 6379<br \/>\n# \u767b\u5f55\u6210\u529f&#xff0c;\u8fdb\u884c\u5bc6\u7801\u8ba4\u8bc1&#xff0c;\u7136\u540e\u67e5\u770b\u96c6\u7fa4\u914d\u7f6e\u4fe1\u606f<br \/>\n127.0.0.1:6379&gt; auth 1234qwer<br \/>\nok<br \/>\n127.0.0.1:6379&gt; info replication<br \/>\n# Replication<br \/>\nrole:master<br \/>\nconnected_slaves:2<br \/>\nslave0:ip&#061;192.168.42.132,port&#061;6379,state&#061;online,offset&#061;280,lag&#061;0<br \/>\nslave1:ip&#061;192.168.42.133,port&#061;6379,state&#061;online,offset&#061;280,lag&#061;0<br \/>\nmaster_replid:a052149baf6e1dbb345f55ceb37476e95efca431<br \/>\nmaster_replid2:0000000000000000000000000000000000000000<br \/>\nmaster_repl_offset:280<br \/>\nsecond_repl_offset:-1<br \/>\nrepl_backlog_active:1<br \/>\nrepl_backlog_size:1048576<br \/>\nrepl_backlog_first_byte_offset:1<br \/>\nrepl_backlog_histlen:280 <\/p>\n<p>\u4ece\u8282\u70b9(node2)\u663e\u793a\u4ee5\u4e0b\u4fe1\u606f&#xff1a;<\/p>\n<\/p>\n<p># \u9996\u5148\u901a\u8fc7docker\u8fdb\u5165redis\u5bb9\u5668<br \/>\ndocker exec -it redis-slave bash<br \/>\n# \u8fdb\u5165\u6210\u529f\u540e&#xff0c;\u767b\u5f55redis<br \/>\nredis-cli -p 6379<br \/>\n# \u767b\u5f55\u6210\u529f&#xff0c;\u8fdb\u884c\u5bc6\u7801\u8ba4\u8bc1&#xff0c;\u7136\u540e\u67e5\u770b\u96c6\u7fa4\u914d\u7f6e\u4fe1\u606f<br \/>\n127.0.0.1:6379&gt; auth 1234qwer<br \/>\nok<br \/>\n127.0.0.1:6379&gt; info replication<br \/>\n# Replication<br \/>\nrole:slave<br \/>\nmaster_host:192.168.42.131<br \/>\nmaster_port:6379<br \/>\nmaster_link_status:up<br \/>\nmaster_last_io_seconds_ago:10<br \/>\nmaster_sync_in_progress:0<br \/>\nslave_repl_offset:448<br \/>\nslave_priority:100<br \/>\nslave_read_only:1<br \/>\nconnected_slaves:0<br \/>\nmaster_replid:a052149baf6e1dbb345f55ceb37476e95efca431<br \/>\nmaster_replid2:0000000000000000000000000000000000000000<br \/>\nmaster_repl_offset:448<br \/>\nsecond_repl_offset:-1<br \/>\nrepl_backlog_active:1<br \/>\nrepl_backlog_size:1048576<br \/>\nrepl_backlog_first_byte_offset:15<br \/>\nrepl_backlog_histlen:434 <\/p>\n<p>\u4ece\u8282\u70b9(node3)\u663e\u793a\u4ee5\u4e0b\u4fe1\u606f&#xff1a;<\/p>\n<\/p>\n<p># \u9996\u5148\u901a\u8fc7docker\u8fdb\u5165redis\u5bb9\u5668<br \/>\ndocker exec -it redis-slave bash<br \/>\n# \u8fdb\u5165\u6210\u529f\u540e&#xff0c;\u767b\u5f55redis<br \/>\nredis-cli -p 6379<br \/>\n# \u767b\u5f55\u6210\u529f&#xff0c;\u8fdb\u884c\u5bc6\u7801\u8ba4\u8bc1&#xff0c;\u7136\u540e\u67e5\u770b\u96c6\u7fa4\u914d\u7f6e\u4fe1\u606f<br \/>\n127.0.0.1:6379&gt; auth 1234qwer<br \/>\nok<br \/>\n127.0.0.1:6379&gt; info replication<br \/>\n# Replication<br \/>\nrole:slave<br \/>\nmaster_host:192.168.42.131<br \/>\nmaster_port:6379<br \/>\nmaster_link_status:up<br \/>\nmaster_last_io_seconds_ago:3<br \/>\nmaster_sync_in_progress:0<br \/>\nslave_repl_offset:532<br \/>\nslave_priority:100<br \/>\nslave_read_only:1<br \/>\nconnected_slaves:0<br \/>\nmaster_replid:a052149baf6e1dbb345f55ceb37476e95efca431<br \/>\nmaster_replid2:0000000000000000000000000000000000000000<br \/>\nmaster_repl_offset:532<br \/>\nsecond_repl_offset:-1<br \/>\nrepl_backlog_active:1<br \/>\nrepl_backlog_size:1048576<br \/>\nrepl_backlog_first_byte_offset:1<br \/>\nrepl_backlog_histlen:532 <\/p>\n<p>\u8f93\u51fa\u4ee5\u4e0a\u4fe1\u606f&#xff0c;\u8bf4\u660eRedis\u4e3b\u4ece\u914d\u7f6e\u5df2\u7ecf\u8fde\u63a5\u6210\u529f\u4e86&#xff0c;\u63a5\u4e0b\u6765\u9a8c\u8bc1\u4e00\u4e0b\u5b58\u53d6\u6570\u636e\u3002<\/p>\n<\/p>\n<h3>5.5\u3001\u9a8c\u8bc1\u5b58\u53d6\u6570\u636e<\/h3>\n<\/p>\n<p>\u5728\u4e24\u4e2a\u4ece\u8282\u70b9\u5b58\u5165\u6570\u636e\u4f1a\u62a5\u9519\u3002<\/p>\n<\/p>\n<p>127.0.0.1:6379&gt; set verify-key &#034;Test Verify is Success&#034;<br \/>\n(error) READONLY You can&#039;t write against a read only replica. <\/p>\n<p>\u56e0\u4e3a\u4ece\u8282\u70b9\u53ea\u53ef\u4ee5\u8bfb\u53d6\u6570\u636e\u4e0d\u53ef\u4ee5\u5199\u5165\u6570\u636e&#xff0c;\u8981\u60f3\u5199\u5165\u6570\u636e\u9700\u8981\u5728\u4e3b\u8282\u70b9\u8fdb\u884c\u3002\u4e3b\u8282\u70b9\u53ef\u4ee5\u8bfb\u5199\u6570\u636e\u3002\u767b\u5f55\u4e3b\u8282\u70b9\u5b58\u5165\u6570\u636e:<\/p>\n<\/p>\n<p>127.0.0.1:6379&gt; set verify-key &#034;Test Verify is Success&#034;<br \/>\nOK<br \/>\n127.0.0.1:6379&gt; get verify-key<br \/>\n&#034;Test Verify is Success&#034; <\/p>\n<p>\u7136\u540e\u5206\u522b\u5728\u4e24\u4e2a\u4ece\u8282\u70b9\u8bfb\u53d6\u6570\u636e&#xff0c;\u770b\u770b\u662f\u5426\u53ef\u4ee5\u8bfb\u53d6\u6210\u529f\u3002<\/p>\n<\/p>\n<p># \u767b\u5f55 192.168.42.132 \u8282\u70b9redis\u4fe1\u606f<br \/>\n127.0.0.1:6379&gt; get verify-key<br \/>\n&#034;Test Verify is Success&#034;<\/p>\n<p># \u767b\u5f55 192.168.42.133 \u8282\u70b9redis\u4fe1\u606f<br \/>\n127.0.0.1:6379&gt; get verify-key<br \/>\n&#034;Test Verify is Success&#034; <\/p>\n<p>\u83b7\u53d6\u6210\u529f&#xff0c;\u8bf4\u660e\u4e3b\u4ece\u590d\u5236\u642d\u5efa\u6210\u529f\u3002<\/p>\n<\/p>\n<h2>6\u3001\u914d\u7f6e Redis \u54e8\u5175<\/h2>\n<\/p>\n<h3>6.1\u3001\u4e3b\u8282\u70b9&#xff08;node1&#xff09;\u914d\u7f6e\u542f\u52a8<\/h3>\n<\/p>\n<p>\u8fdb\u5165&#xff1a;\/root\/docker\/redis\/sentinel\u76ee\u5f55&#xff0c;\u4e0b\u8f7dsentinel.conf\u6587\u4ef6\u5e76\u4e0a\u4f20\u7684\u8be5\u76ee\u5f55&#xff0c;\u914d\u7f6e\u54e8\u5175\u8fde\u63a5\u3002 \u6587\u4ef6\u4e0b\u8f7d\u5730\u5740&#xff1a;\u00a0https:\/\/github.com\/redis\/redis\/blob\/5.0.4\/sentinel.conf<\/p>\n<p>\u4e0b\u8f7d\u6210\u529f\u540e&#xff0c;\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u3002\u6267\u884c\u547d\u4ee4vim \/root\/docker\/redis\/sentinel\/sentinel.conf<\/p>\n<\/p>\n<p># \u54e8\u5175\u8282\u70b9\u7684\u7aef\u53e3\u53f7<br \/>\nport 26379<br \/>\nbind 0.0.0.0<br \/>\nlogfile &#034;\/var\/log\/redis-sentinel.log&#034;<br \/>\n# \u5173\u95ed\u4fdd\u62a4\u6a21\u5f0f&#xff0c;\u5141\u8bb8\u5916\u90e8\u8bbf\u95ee&#xff0c;Docker\u73af\u5883\u4e2d\u5fc5\u987b\u8bbe\u7f6e\u4e3a no<br \/>\nprotected-mode no<br \/>\n# \u7981\u6b62Redis\u4ee5\u5b88\u62a4\u8fdb\u7a0b\u65b9\u5f0f\u8fd0\u884c<br \/>\ndaemonize no<br \/>\n# \u54e8\u5175\u5de5\u4f5c\u76ee\u5f55<br \/>\ndir \/tmp<br \/>\nsentinel monitor mymaster 192.168.42.131 6379 2<br \/>\n# \u89e3\u6790&#xff1a;<br \/>\n# &#8211; mymaster&#xff1a;\u4e3b\u8282\u70b9\u7684\u540d\u79f0\u6807\u8bc6<br \/>\n# &#8211; 49.235.180.130&#xff1a;\u4e3b\u8282\u70b9\u7684IP\u5730\u5740<br \/>\n# &#8211; 6379&#xff1a;\u4e3b\u8282\u70b9\u7684\u7aef\u53e3\u53f7<br \/>\n# &#8211; 2&#xff1a;\u5224\u5b9a\u4e3b\u8282\u70b9\u6545\u969c\u9700\u8981\u7684\u54e8\u5175\u6295\u7968\u6570&#xff08;\u81f3\u5c112\u4e2a\u54e8\u5175\u8ba4\u4e3a\u4e3b\u8282\u70b9\u6545\u969c\u624d\u4f1a\u8fdb\u884c\u6545\u969c\u8f6c\u79fb&#xff09;<br \/>\n#redis\u8282\u70b9\u5bc6\u7801<br \/>\nsentinel auth-pass mymaster 1234qwer<br \/>\n# \u89e3\u6790&#xff1a;<br \/>\n# &#8211; mymaster&#xff1a;\u5bf9\u5e94\u7684\u4e3b\u8282\u70b9\u540d\u79f0<br \/>\n# &#8211; 1234qwer&#xff1a;Redis\u8282\u70b9\u7684\u8bbf\u95ee\u5bc6\u7801<br \/>\n# \u4e3b\u89c2\u4e0b\u7ebf\u65f6\u95f4&#xff0c;\u5355\u4f4d\u6beb\u79d2<br \/>\nsentinel down-after-milliseconds mymaster 10000<br \/>\n# \u89e3\u6790&#xff1a;\u5982\u679c10\u79d2\u5185\u65e0\u6cd5\u8fde\u63a5\u4e3b\u8282\u70b9&#xff0c;\u5219\u8ba4\u4e3a\u4e3b\u8282\u70b9\u4e3b\u89c2\u4e0b\u7ebf<\/p>\n<p># \u540c\u6b65\u914d\u7f6e<br \/>\nsentinel parallel-syncs mymaster 1<br \/>\n# sentinel parallel-syncs&#xff1a;\u5e76\u884c\u540c\u6b65\u914d\u7f6e&#xff0c;mymaster&#xff1a;\u4e3b\u8282\u70b9\u7684\u522b\u540d&#xff0c;1&#xff1a;\u5e76\u884c\u540c\u6b65\u7684\u4ece\u8282\u70b9\u6570\u91cf\u3002<br \/>\n#\u4f5c\u7528\u548c\u5f71\u54cd&#xff1a;<br \/>\n#1. \u63a7\u5236\u6545\u969c\u8f6c\u79fb\u671f\u95f4\u7684\u6570\u636e\u540c\u6b65\u884c\u4e3a&#xff0c;\u5f53\u503c\u4e3a1\u65f6&#xff1a;\u4ece\u8282\u70b9\u9010\u4e2a\u540c\u6b65&#xff0c;\u5f53\u503c\u5927\u4e8e1\u65f6&#xff1a;\u591a\u4e2a\u4ece\u8282\u70b9\u5e76\u884c\u540c\u6b65<br \/>\n#\u793a\u4f8b\u573a\u666f&#xff1a;<br \/>\n# parallel-syncs &#061; 1 \u65f6&#xff1a;\u4e3b\u8282\u70b9\u6545\u969c&#xff0c;slave1\u88ab\u9009\u4e3a\u65b0\u4e3b\u8282\u70b9 slave2\u5f00\u59cb\u4e0eslave1\u540c\u6b65&#xff0c;slave3\u7b49\u5f85slave2\u540c\u6b65\u5b8c\u6210\u540e\u518d\u540c\u6b65&#xff0c;\u8fc7\u7a0b\u8f83\u6162\u4f46\u4e3b\u8282\u70b9\u538b\u529b\u5c0f<br \/>\n# parallel-syncs &#061; 2 \u65f6&#xff1a;\u4e3b\u8282\u70b9\u6545\u969c&#xff0c;slave1\u88ab\u9009\u4e3a\u65b0\u4e3b\u8282\u70b9&#xff0c;slave2\u548cslave3\u540c\u65f6\u4e0eslave1\u540c\u6b65&#xff0c;\u8fc7\u7a0b\u8f83\u5feb\u4f46\u4e3b\u8282\u70b9\u538b\u529b\u5927<\/p>\n<p># \u6545\u969c\u8f6c\u79fb\u8d85\u65f6\u65f6\u95f4<br \/>\nsentinel failover-timeout mymaster 600000<br \/>\n# \u89e3\u6790&#xff1a;\u6545\u969c\u8f6c\u79fb\u7684\u8d85\u65f6\u65f6\u95f4\u4e3a600\u79d2&#xff08;10\u5206\u949f&#xff09;<\/p>\n<p>sentinel deny-scripts-reconfig yes<br \/>\n# \u89e3\u6790&#xff1a;\u7981\u6b62\u901a\u8fc7\u811a\u672c\u4fee\u6539\u54e8\u5175\u914d\u7f6e&#xff0c;\u63d0\u9ad8\u5b89\u5168\u6027<\/p>\n<p># \u5bf9\u5916\u5ba3\u544a\u7684IP\u5730\u5740<br \/>\nsentinel announce-ip &#034;192.168.42.131&#034;<br \/>\n# \u5bf9\u5916\u5ba3\u544a\u7684\u7aef\u53e3\u53f7<br \/>\nsentinel announce-port 26379<br \/>\n# \u89e3\u6790&#xff1a;<br \/>\n# &#8211; \u7528\u4e8e\u5728Docker\u6216NAT\u7f51\u7edc\u73af\u5883\u4e2d&#xff0c;\u58f0\u660e\u54e8\u5175\u8282\u70b9\u7684\u5b9e\u9645\u53ef\u8bbf\u95ee\u5730\u5740<br \/>\n# &#8211; \u786e\u4fdd\u5176\u4ed6\u8282\u70b9\u53ef\u4ee5\u6b63\u786e\u8fde\u63a5\u5230\u8be5\u54e8\u5175\u8282\u70b9 <\/p>\n<p>\u542f\u52a8\u54e8\u5175&#xff1a;<\/p>\n<\/p>\n<p>docker run -d -p 26379:26379 &#8211;restart&#061;always &#8211;privileged&#061;true &#8211;name redis-sentinel  -v \/root\/docker\/redis\/sentinel\/sentinel.conf:\/etc\/redis\/sentinel.conf redis:5.0 redis-sentinel \/etc\/redis\/sentinel.conf <\/p>\n<h3>6.2\u3001\u4ece\u8282\u70b9&#xff08;node2&#xff09;\u914d\u7f6e\u542f\u52a8<\/h3>\n<\/p>\n<p>\u4e0b\u8f7d\u5e76\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u3002\u6267\u884c\u547d\u4ee4vim \/root\/docker\/redis\/sentinel\/sentinel.conf<\/p>\n<\/p>\n<p># \u914d\u7f6e\u6587\u4ef6\u548c\u4e3b\u8282\u70b9\u542f\u52a8\u7684\u54e8\u5175\u914d\u7f6e\u6587\u4ef6\u4e00\u81f4&#xff0c;\u53ea\u9700\u8981\u66f4\u6539\u4e00\u4e0b\u5bf9\u5916\u76d1\u542c\u7684\u54e8\u5175\u5730\u5740\u5373\u53ef<\/p>\n<p># \u5bf9\u5916\u5ba3\u544a\u7684IP\u5730\u5740<br \/>\nsentinel announce-ip &#034;192.168.42.132&#034;<br \/>\n# \u5bf9\u5916\u5ba3\u544a\u7684\u7aef\u53e3\u53f7<br \/>\nsentinel announce-port 26379 <\/p>\n<p>\u542f\u52a8\u54e8\u5175&#xff1a;<\/p>\n<\/p>\n<p>docker run -d -p 26379:26379 &#8211;restart&#061;always &#8211;privileged&#061;true &#8211;name redis-sentinel  -v \/root\/docker\/redis\/sentinel\/sentinel.conf:\/etc\/redis\/sentinel.conf redis:5.0 redis-sentinel \/etc\/redis\/sentinel.conf <\/p>\n<h3>6.3\u3001\u4ece\u8282\u70b9&#xff08;node3&#xff09;\u914d\u7f6e\u542f\u52a8<\/h3>\n<\/p>\n<p>\u4e0b\u8f7d\u5e76\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u3002\u6267\u884c\u547d\u4ee4vim \/root\/docker\/redis\/sentinel\/sentinel.conf<\/p>\n<\/p>\n<p># \u914d\u7f6e\u6587\u4ef6\u548c\u4e3b\u8282\u70b9\u542f\u52a8\u7684\u54e8\u5175\u914d\u7f6e\u6587\u4ef6\u4e00\u81f4&#xff0c;\u53ea\u9700\u8981\u66f4\u6539\u4e00\u4e0b\u5bf9\u5916\u76d1\u542c\u7684\u54e8\u5175\u5730\u5740\u5373\u53ef<\/p>\n<p># \u5bf9\u5916\u5ba3\u544a\u7684IP\u5730\u5740<br \/>\nsentinel announce-ip &#034;192.168.42.133&#034;<br \/>\n# \u5bf9\u5916\u5ba3\u544a\u7684\u7aef\u53e3\u53f7<br \/>\nsentinel announce-port 26379 <\/p>\n<p>\u542f\u52a8\u54e8\u5175&#xff1a;<\/p>\n<\/p>\n<p>docker run -d -p 26379:26379 &#8211;restart&#061;always &#8211;privileged&#061;true &#8211;name redis-sentinel  -v \/root\/docker\/redis\/sentinel\/sentinel.conf:\/etc\/redis\/sentinel.conf redis:5.0 redis-sentinel \/etc\/redis\/sentinel.conf <\/p>\n<h3>6.4\u3001\u9a8c\u8bc1\u54e8\u5175\u96c6\u7fa4<\/h3>\n<\/p>\n<p>\u9996\u5148\u9009\u62e9\u4e00\u53f0\u670d\u52a1\u5668\u8fdb\u884c\u767b\u5f55\u54e8\u5175&#xff0c;\u53ef\u4ee5\u5728\u4e3b\u8282\u70b9\u6216\u4ece\u8282\u70b9\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4&#xff0c;\u8fdb\u5165\u54e8\u5175\u5bb9\u5668&#xff1a;<\/p>\n<\/p>\n<p>docker exec -it redis-sentinel bash <\/p>\n<p>\u8fde\u63a5\u54e8\u5175\u5ba2\u6237\u7aef&#xff1a;<\/p>\n<\/p>\n<p>redis-cli -p 26379 <\/p>\n<p>\u67e5\u770b\u54e8\u5175\u4fe1\u606f&#xff1a;<\/p>\n<\/p>\n<p># info sentinel<br \/>\n127.0.0.1:26379&gt; info sentinel<br \/>\n# Sentinel<br \/>\nsentinel_masters:1<br \/>\nsentinel_tilt:0<br \/>\nsentinel_running_scripts:0<br \/>\nsentinel_scripts_queue_length:0<br \/>\nsentinel_simulate_failure_flags:0<br \/>\nmaster0:name&#061;mymaster,status&#061;ok,address&#061;192.168.42.131:6379,slaves&#061;2,sentinels&#061;3<\/p>\n<p>#\u8f93\u51fa\u4ee5\u4e0a\u4fe1\u606f\u914d\u7f6e\u6210\u529f <\/p>\n<p>\u67e5\u770b\u54e8\u5175\u4fe1\u606f&#xff0c;\u5982\u679c\u53d1\u73b0\u5df2\u7ecf\u96c6\u6210\u6210\u529f\u4e86&#xff0c;\u63a5\u4e0b\u6765\u5c31\u53ef\u4ee5\u9a8c\u8bc1\u54e8\u5175\u6a21\u5f0f\u4e86\u3002\u5728\u54e8\u5175\u6a21\u5f0f\u4e0b&#xff0c;\u5f53master\u670d\u52a1\u5668\u5b95\u673a\u4e4b\u540e&#xff0c;\u54e8\u5175\u81ea\u52a8\u4f1a\u5728\u4ece \u8282\u70b9\u670d\u52a1\u5668\u91cc\u9762\u6295\u7968\u9009\u4e3e\u4e00\u4e2amaster\u670d\u52a1\u5668\u6765&#xff0c;\u8fd9\u4e2amaster\u670d\u52a1\u5668\u4e5f\u53ef\u4ee5\u8fdb\u884c\u8bfb\u5199\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p>\u5148\u628a\u4e3b\u8282\u70b9\u5173\u95ed\u6389&#xff1a;<\/p>\n<\/p>\n<p>docker stop redis-master <\/p>\n<p>\u518d\u6b21\u67e5\u770b\u54e8\u5175\u4fe1\u606f&#xff1a;<\/p>\n<\/p>\n<p>127.0.0.1:26379&gt; info sentinel<br \/>\n# Sentinel<br \/>\nsentinel_masters:1<br \/>\nsentinel_tilt:0<br \/>\nsentinel_running_scripts:0<br \/>\nsentinel_scripts_queue_length:0<br \/>\nsentinel_simulate_failure_flags:0<br \/>\nmaster0:name&#061;mymaster,status&#061;ok,address&#061;192.168.42.132:6379,slaves&#061;2,sentinels&#061;3<\/p>\n<p># \u6839\u636e\u6700\u540e\u4e00\u884c\u4fe1\u606f&#xff0c;\u53ef\u4ee5\u770b\u51fa\u4e3b\u8282\u70b9\u7684IP\u8fdb\u884c\u53d8\u5316\u4e86\u3002\u7531192.168.42.131 -&gt; 192.168.42.132 <\/p>\n<h2>7\u3001SpringBoot\u8fde\u63a5Redis\u54e8\u5175\u6a21\u5f0f<\/h2>\n<\/p>\n<h3>7.1\u3001\u5f15\u5165\u4f9d\u8d56<\/h3>\n<\/p>\n<p>\u5728\u00a0pom.xml\u00a0\u4e2d\u6dfb\u52a0\u4f9d\u8d56:<\/p>\n<\/p>\n<p>&lt;dependency&gt;<br \/>\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;spring-boot-starter-data-redis&lt;\/artifactId&gt;<br \/>\n&lt;\/dependency&gt;<br \/>\n&lt;dependency&gt;<br \/>\n    &lt;groupId&gt;redis.clients&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;jedis&lt;\/artifactId&gt;<br \/>\n&lt;\/dependency&gt; <\/p>\n<h3>7.2\u3001\u914d\u7f6e application.yml<\/h3>\n<\/p>\n<p>spring:<br \/>\n   redis:<br \/>\n    #\u5bc6\u7801<br \/>\n      password: 1234qwer<br \/>\n      timeout: 5000<br \/>\n      sentinel:<br \/>\n       # \u5bf9\u5e94\u524d\u9762sentinel\u7684\u914d\u7f6e\u6587\u4ef6\u4fe1\u606f<br \/>\n        master: mymaster<br \/>\n       # \u4e09\u4e2a\u54e8\u5175\u7684ip\u7aef\u53e3<br \/>\n        nodes: 192.168.42.131:26379,192.168.42.132:26379,192.168.42.133:26379 <\/p>\n<h3>7.3\u3001\u7f16\u5199\u6d4b\u8bd5\u4ee3\u7801<\/h3>\n<\/p>\n<p>\u521b\u5efa RedisConfig\u4f7f\u7528Jedis\u5ba2\u6237\u7aef\u8fde\u63a5<\/p>\n<\/p>\n<p>&#064;Configuration<br \/>\npublic class RedisConfig extends CachingConfigurerSupport {<br \/>\n    &#064;Value(&#034;${spring.redis.timeout}&#034;)<br \/>\n    private int timeout;<br \/>\n    &#064;Value(&#034;${spring.redis.password}&#034;)<br \/>\n    private String password;<br \/>\n    \/\/ \u65b0\u589e\u54e8\u5175\u914d\u7f6e<br \/>\n    &#064;Value(&#034;${spring.redis.sentinel.master}&#034;)<br \/>\n    private String masterName;<br \/>\n    &#064;Value(&#034;${spring.redis.sentinel.nodes}&#034;)<br \/>\n    private String sentinelNodes;<\/p>\n<p>     &#064;Bean<br \/>\n     public JedisSentinelPool jedisSentinelPool() {<br \/>\n        \/\/ \u89e3\u6790\u54e8\u5175\u8282\u70b9<br \/>\n        Set&lt;String&gt; sentinels &#061; new HashSet&lt;&gt;(Arrays.asList(sentinelNodes.split(&#034;,&#034;)));<br \/>\n        \/\/ \u521b\u5efa\u54e8\u5175\u8fde\u63a5\u6c60<br \/>\n        JedisSentinelPool sentinelPool &#061; new JedisSentinelPool(masterName, sentinels, createPoolConfig(), timeout, password,0);<br \/>\n         log.info(&#034;\u4f7f\u7528\u54e8\u5175\u6a21\u5f0f&#xff0c;\u4e3b\u8282\u70b9\u540d\u79f0&#xff1a;{} JedisSentinelPool\u6ce8\u5165\u6210\u529f&#xff01;&#xff01;&#034;, masterName);<br \/>\n         return sentinelPool;<br \/>\n     }<\/p>\n<p>      private JedisPoolConfig createPoolConfig() {<br \/>\n        JedisPoolConfig jedisPoolConfig &#061; new JedisPoolConfig();<br \/>\n        jedisPoolConfig.setMaxIdle(50);<br \/>\n        jedisPoolConfig.setMinIdle(5);<br \/>\n        jedisPoolConfig.setMaxWaitMillis(10000);<br \/>\n        jedisPoolConfig.setJmxEnabled(true);<br \/>\n        return jedisPoolConfig;<br \/>\n    }<br \/>\n} <\/p>\n<p>\u521b\u5efa JedisTemplate\u64cd\u4f5cRedis\u7c7b<\/p>\n<\/p>\n<p>&#064;Component<br \/>\n&#064;ConditionalOnClass(RedisConfig.class)<br \/>\npublic class JedisTemplate {<\/p>\n<p>    &#064;Autowired(required &#061; false)<br \/>\n    private JedisSentinelPool jedisSentinelPool;<\/p>\n<p>   \/**<br \/>\n     * \u4fdd\u5b58\u6570\u636e<br \/>\n     * &#064;param key<br \/>\n     * &#064;param value<br \/>\n     * &#064;param seconds \u5c0f\u4e8e\u7b49\u4e8e0\u65f6\u4e3a\u4e0d\u9650\u5236\u65f6\u957f<br \/>\n     *\/<br \/>\n    public final void setStringData(String key, String value, int seconds) {<br \/>\n        Jedis jedis &#061; null;<br \/>\n        try {<br \/>\n            jedis &#061; jedisSentinelPool.getResource();<br \/>\n            boolean flag &#061; jedis.exists(key);<br \/>\n            if (flag) {<br \/>\n                jedis.del(key);<br \/>\n            }<br \/>\n            jedis.set(key, value);<br \/>\n            if (seconds &gt; 0) {<br \/>\n                jedis.expire(key, seconds);<br \/>\n            }<br \/>\n        } catch (Exception e) {<br \/>\n            e.printStackTrace();<br \/>\n        } finally {<br \/>\n            if (jedis !&#061; null) {<br \/>\n                jedis.close();<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u6839\u636ekey\u83b7\u53d6redis\u91cc\u9762\u7684\u5b57\u7b26\u4e32<br \/>\n     * &#064;param key<br \/>\n     * &#064;return<br \/>\n     *\/<br \/>\n    public String getStringData(String key) {<br \/>\n        String str &#061; null;<br \/>\n        Jedis jedis &#061; null;<br \/>\n        try {<br \/>\n            jedis &#061; jedisSentinelPool.getResource();<br \/>\n            str &#061; jedis.get(key);<br \/>\n        } catch (Exception e) {<br \/>\n            e.printStackTrace();<br \/>\n        } finally {<br \/>\n            if (jedis !&#061; null) {<br \/>\n                jedis.close();<br \/>\n            }<br \/>\n        }<br \/>\n        return str;<br \/>\n    }<\/p>\n<p>   \/**<br \/>\n     * \u5220\u9664\u4e00\u4e2akey<br \/>\n     * &#064;param key<br \/>\n     *\/<br \/>\n    public void deleteKey(String key) {<br \/>\n        Jedis jedis &#061; null;<br \/>\n        try {<br \/>\n            jedis &#061; jedisSentinelPool.getResource();<br \/>\n            jedis.del(key);<br \/>\n        } catch (Exception e) {<br \/>\n            e.printStackTrace();<br \/>\n        } finally {<br \/>\n            if (jedis !&#061; null) {<br \/>\n                jedis.close();<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>\u521b\u5efaRedisTestController\u6d4b\u8bd5Web\u63a7\u5236\u5668<\/p>\n<\/p>\n<p>&#064;RestController<br \/>\npublic class RedisTestController {<br \/>\n    &#064;Autowired<br \/>\n    private JedisTemplate jedisTemplate;<\/p>\n<p>    &#064;GetMapping(&#034;\/redis\/test\/{key}&#034;)<br \/>\n    public Response getRedisSentinelTest(&#064;PathVariable(&#034;key&#034;) String key){<br \/>\n        String randomNumeric &#061; RandomStringUtils.randomNumeric(12);<br \/>\n        jedisTemplate.setStringData(key,&#034;\u54c8\u54c8\u54c8&#034; &#043; randomNumeric, 180);<br \/>\n        String stringData &#061; jedisTemplate.getStringData(key);<br \/>\n        System.out.println(stringData);<br \/>\n        return Response.success(stringData);<br \/>\n    }<br \/>\n} <\/p>\n<h3>7.4\u3001\u542f\u52a8\u9879\u76ee<\/h3>\n<\/p>\n<p>2025-02-22 17:40:14.223 INFO  -[JedisSentinelPool.java:198]- Trying to find master from available Sentinels&#8230;<br \/>\n2025-02-22 17:40:14.328 INFO  -[JedisSentinelPool.java:254]- Redis master running at 192.168.42.131:6379, starting Sentinel listeners&#8230;<br \/>\n2025-02-22 17:40:14.345 INFO  -[JedisSentinelPool.java:188]- Created JedisPool to master at 192.168.42.131:6379<br \/>\n2025-02-22 17:40:14.345 INFO  -[RedisConfig.java:42]- \u4f7f\u7528\u54e8\u5175\u6a21\u5f0f&#xff0c;\u4e3b\u8282\u70b9\u540d\u79f0&#xff1a;mymaster JedisSentinelPool\u6ce8\u5165\u6210\u529f&#xff01;&#xff01;<br \/>\n2025-02-22 17:40:48.609 INFO  -[DirectJDKLog.java:173]- Starting ProtocolHandler [&#034;http-nio-9090&#034;]<br \/>\n2025-02-22 17:40:48.630 INFO  -[TomcatWebServer.java:220]- Tomcat started on port(s): 9090 (http) with context path &#039;&#039;<br \/>\n2025-02-22 17:40:48.642 INFO  -[StartupInfoLogger.java:61]- Started App in 2.892 seconds (JVM running for 3.562)<br \/>\n2025-02-22 17:41:05.914 INFO  -[DirectJDKLog.java:173]- Initializing Spring DispatcherServlet &#039;dispatcherServlet&#039;<br \/>\n2025-02-22 17:41:05.915 INFO  -[FrameworkServlet.java:525]- Initializing Servlet &#039;dispatcherServlet&#039;<br \/>\n2025-02-22 17:41:05.929 INFO  -[FrameworkServlet.java:547]- Completed initialization in 14 ms <\/p>\n<p>\u8c03\u7528\u63a5\u53e3\u4f7f\u7528PostMan\u8c03\u7528\u63a5\u53e3\u8fdb\u884c\u6d4b\u8bd5&#xff1a;http:\/\/localhost:9090\/redis\/test\/1234\u00a0&#xff0c;\u6d4b\u8bd5\u54e8\u5175\u662f\u5426\u521b\u5efa\u6210\u529f\u3002<\/p>\n<\/p>\n<h2>8\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p>\u5230\u6b64Redis\u54e8\u5175\u96c6\u7fa4\u5c31\u642d\u5efa\u5b8c\u6210\u4e86\u3002Redis\u54e8\u5175\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u76d1\u63a7\u548c\u81ea\u52a8\u4fee\u590d\u529f\u80fd&#xff0c;\u8fd9\u4f7f\u5f97Redis\u670d\u52a1\u5728\u9762\u4e34\u5404\u79cd\u6545\u969c\u65f6&#xff0c;\u80fd\u591f\u5feb\u901f\u81ea\u52a8\u6062\u590d&#xff0c;\u51cf\u5c11\u4eba\u5de5\u5e72\u9884\u3002\u56de\u987e\u6574\u4e2a\u642d\u5efa\u8fc7\u7a0b&#xff0c;\u642d\u5efa\u5e76\u4e0d\u662f\u7279\u522b\u590d\u6742&#xff0c;\u4e3b\u8981\u4e5f\u5c313\u4e2a\u6b65\u9aa4&#xff0c;\u5305\u62ec&#xff1a;1\u3001\u914d\u7f6eRedis\u4e3b\u4ece\u590d\u5236\u30022\u3001\u8bbe\u7f6eRedis\u54e8\u5175\u8282\u70b9\u30023\u3001\u9a8c\u8bc1\u9ad8\u53ef\u7528\u6027\u3002\u6700\u540e&#xff0c;\u5e0c\u671b\u672c\u6587\u80fd\u5e2e\u52a9\u4f60\u4e86\u89e3Redis\u54e8\u5175\u6a21\u5f0f\u7684\u642d\u5efa\u6d41\u7a0b&#xff0c;\u5e76\u4e3a\u4f60\u63d0\u4f9b\u53c2\u8003\u3002\u5982\u679c\u4f60\u5728\u642d\u5efa\u8fc7\u7a0b\u4e2d\u9047\u5230\u95ee\u9898&#xff0c;\u6b22\u8fce\u8ba8\u8bba\u6216\u67e5\u9605Redis\u5b98\u65b9\u6587\u6863&#xff0c;\u8fdb\u4e00\u6b65\u4f18\u5316\u914d\u7f6e\u3002<\/p>\n<\/p>\n<p>\u6587\u7ae0\u8f6c\u8f7d\u81ea&#xff1a;sowler<\/p>\n<p>\u539f\u6587\u94fe\u63a5&#xff1a;Redis\u9ad8\u53ef\u7528\u90e8\u7f72&#xff1a;3\u53f0\u670d\u52a1\u5668\u6253\u9020\u54e8\u5175\u96c6\u7fa4 &#8211; sowler &#8211; \u535a\u5ba2\u56ed<\/p>\n<p>\u4f53\u9a8c\u5730\u5740&#xff1a;\u5f15\u8fc8 &#8211; JNPF\u5feb\u901f\u5f00\u53d1\u5e73\u53f0_\u4f4e\u4ee3\u7801\u5f00\u53d1\u5e73\u53f0_\u96f6\u4ee3\u7801\u5f00\u53d1\u5e73\u53f0_\u6d41\u7a0b\u8bbe\u8ba1\u5668_\u8868\u5355\u5f15\u64ce_\u5de5\u4f5c\u6d41\u5f15\u64ce_\u8f6f\u4ef6\u67b6\u6784<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2k\u6b21\uff0c\u70b9\u8d5e24\u6b21\uff0c\u6536\u85cf23\u6b21\u3002\u5230\u6b64Redis\u54e8\u5175\u96c6\u7fa4\u5c31\u642d\u5efa\u5b8c\u6210\u4e86\u3002Redis\u54e8\u5175\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u76d1\u63a7\u548c\u81ea\u52a8\u4fee\u590d\u529f\u80fd\uff0c\u8fd9\u4f7f\u5f97Redis\u670d\u52a1\u5728\u9762\u4e34\u5404\u79cd\u6545\u969c\u65f6\uff0c\u80fd\u591f\u5feb\u901f\u81ea\u52a8\u6062\u590d\uff0c\u51cf\u5c11\u4eba\u5de5\u5e72\u9884\u3002\u56de\u987e\u6574\u4e2a\u642d\u5efa\u8fc7\u7a0b\uff0c\u642d\u5efa\u5e76\u4e0d\u662f\u7279\u522b\u590d\u6742\uff0c\u4e3b\u8981\u4e5f\u5c313\u4e2a\u6b65\u9aa4\uff0c\u5305\u62ec\uff1a1\u3001\u914d\u7f6eRedis\u4e3b\u4ece\u590d\u5236\u30022\u3001\u8bbe\u7f6eRedis\u54e8\u5175\u8282\u70b9\u30023\u3001\u9a8c\u8bc1\u9ad8\u53ef\u7528\u6027\u3002\u6700\u540e\uff0c\u5e0c\u671b\u672c\u6587\u80fd\u5e2e\u52a9\u4f60\u4e86\u89e3Redis\u54e8\u5175\u6a21\u5f0f\u7684\u642d\u5efa\u6d41\u7a0b\uff0c\u5e76\u4e3a\u4f60\u63d0\u4f9b\u53c2\u8003\u3002\u5982\u679c\u4f60\u5728\u642d\u5efa\u8fc7\u7a0b\u4e2d\u9047\u5230\u95ee\u9898\uff0c\u6b22\u8fce\u8ba8\u8bba\u6216\u67e5\u9605Redis\u5b98\u65b9\u6587\u6863\uff0c\u8fdb\u4e00\u6b65\u4f18\u5316\u914d\u7f6e\u3002sowler\u3002_redis\u4e00\u4e3b\u4e24\u4ece\u4e09\u54e8\u5175\u914d\u7f6e<\/p>\n","protected":false},"author":2,"featured_media":22848,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[105,100,43],"topic":[],"class_list":["post-22849","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-redis","tag-100","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Redis\u9ad8\u53ef\u7528\u90e8\u7f72\uff1a3\u53f0\u670d\u52a1\u5668\u6253\u9020\u54e8\u5175\u96c6\u7fa4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/22849.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Redis\u9ad8\u53ef\u7528\u90e8\u7f72\uff1a3\u53f0\u670d\u52a1\u5668\u6253\u9020\u54e8\u5175\u96c6\u7fa4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2k\u6b21\uff0c\u70b9\u8d5e24\u6b21\uff0c\u6536\u85cf23\u6b21\u3002\u5230\u6b64Redis\u54e8\u5175\u96c6\u7fa4\u5c31\u642d\u5efa\u5b8c\u6210\u4e86\u3002Redis\u54e8\u5175\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u76d1\u63a7\u548c\u81ea\u52a8\u4fee\u590d\u529f\u80fd\uff0c\u8fd9\u4f7f\u5f97Redis\u670d\u52a1\u5728\u9762\u4e34\u5404\u79cd\u6545\u969c\u65f6\uff0c\u80fd\u591f\u5feb\u901f\u81ea\u52a8\u6062\u590d\uff0c\u51cf\u5c11\u4eba\u5de5\u5e72\u9884\u3002\u56de\u987e\u6574\u4e2a\u642d\u5efa\u8fc7\u7a0b\uff0c\u642d\u5efa\u5e76\u4e0d\u662f\u7279\u522b\u590d\u6742\uff0c\u4e3b\u8981\u4e5f\u5c313\u4e2a\u6b65\u9aa4\uff0c\u5305\u62ec\uff1a1\u3001\u914d\u7f6eRedis\u4e3b\u4ece\u590d\u5236\u30022\u3001\u8bbe\u7f6eRedis\u54e8\u5175\u8282\u70b9\u30023\u3001\u9a8c\u8bc1\u9ad8\u53ef\u7528\u6027\u3002\u6700\u540e\uff0c\u5e0c\u671b\u672c\u6587\u80fd\u5e2e\u52a9\u4f60\u4e86\u89e3Redis\u54e8\u5175\u6a21\u5f0f\u7684\u642d\u5efa\u6d41\u7a0b\uff0c\u5e76\u4e3a\u4f60\u63d0\u4f9b\u53c2\u8003\u3002\u5982\u679c\u4f60\u5728\u642d\u5efa\u8fc7\u7a0b\u4e2d\u9047\u5230\u95ee\u9898\uff0c\u6b22\u8fce\u8ba8\u8bba\u6216\u67e5\u9605Redis\u5b98\u65b9\u6587\u6863\uff0c\u8fdb\u4e00\u6b65\u4f18\u5316\u914d\u7f6e\u3002sowler\u3002_redis\u4e00\u4e3b\u4e24\u4ece\u4e09\u54e8\u5175\u914d\u7f6e\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/22849.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T22:36:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418223639-6802d3f731b0d.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/22849.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/22849.html\",\"name\":\"Redis\u9ad8\u53ef\u7528\u90e8\u7f72\uff1a3\u53f0\u670d\u52a1\u5668\u6253\u9020\u54e8\u5175\u96c6\u7fa4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T22:36:40+00:00\",\"dateModified\":\"2025-04-18T22:36:40+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/22849.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/22849.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/22849.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Redis\u9ad8\u53ef\u7528\u90e8\u7f72\uff1a3\u53f0\u670d\u52a1\u5668\u6253\u9020\u54e8\u5175\u96c6\u7fa4\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Redis\u9ad8\u53ef\u7528\u90e8\u7f72\uff1a3\u53f0\u670d\u52a1\u5668\u6253\u9020\u54e8\u5175\u96c6\u7fa4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/22849.html","og_locale":"zh_CN","og_type":"article","og_title":"Redis\u9ad8\u53ef\u7528\u90e8\u7f72\uff1a3\u53f0\u670d\u52a1\u5668\u6253\u9020\u54e8\u5175\u96c6\u7fa4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2k\u6b21\uff0c\u70b9\u8d5e24\u6b21\uff0c\u6536\u85cf23\u6b21\u3002\u5230\u6b64Redis\u54e8\u5175\u96c6\u7fa4\u5c31\u642d\u5efa\u5b8c\u6210\u4e86\u3002Redis\u54e8\u5175\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u76d1\u63a7\u548c\u81ea\u52a8\u4fee\u590d\u529f\u80fd\uff0c\u8fd9\u4f7f\u5f97Redis\u670d\u52a1\u5728\u9762\u4e34\u5404\u79cd\u6545\u969c\u65f6\uff0c\u80fd\u591f\u5feb\u901f\u81ea\u52a8\u6062\u590d\uff0c\u51cf\u5c11\u4eba\u5de5\u5e72\u9884\u3002\u56de\u987e\u6574\u4e2a\u642d\u5efa\u8fc7\u7a0b\uff0c\u642d\u5efa\u5e76\u4e0d\u662f\u7279\u522b\u590d\u6742\uff0c\u4e3b\u8981\u4e5f\u5c313\u4e2a\u6b65\u9aa4\uff0c\u5305\u62ec\uff1a1\u3001\u914d\u7f6eRedis\u4e3b\u4ece\u590d\u5236\u30022\u3001\u8bbe\u7f6eRedis\u54e8\u5175\u8282\u70b9\u30023\u3001\u9a8c\u8bc1\u9ad8\u53ef\u7528\u6027\u3002\u6700\u540e\uff0c\u5e0c\u671b\u672c\u6587\u80fd\u5e2e\u52a9\u4f60\u4e86\u89e3Redis\u54e8\u5175\u6a21\u5f0f\u7684\u642d\u5efa\u6d41\u7a0b\uff0c\u5e76\u4e3a\u4f60\u63d0\u4f9b\u53c2\u8003\u3002\u5982\u679c\u4f60\u5728\u642d\u5efa\u8fc7\u7a0b\u4e2d\u9047\u5230\u95ee\u9898\uff0c\u6b22\u8fce\u8ba8\u8bba\u6216\u67e5\u9605Redis\u5b98\u65b9\u6587\u6863\uff0c\u8fdb\u4e00\u6b65\u4f18\u5316\u914d\u7f6e\u3002sowler\u3002_redis\u4e00\u4e3b\u4e24\u4ece\u4e09\u54e8\u5175\u914d\u7f6e","og_url":"https:\/\/www.wsisp.com\/helps\/22849.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T22:36:40+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418223639-6802d3f731b0d.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/22849.html","url":"https:\/\/www.wsisp.com\/helps\/22849.html","name":"Redis\u9ad8\u53ef\u7528\u90e8\u7f72\uff1a3\u53f0\u670d\u52a1\u5668\u6253\u9020\u54e8\u5175\u96c6\u7fa4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T22:36:40+00:00","dateModified":"2025-04-18T22:36:40+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/22849.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/22849.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/22849.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Redis\u9ad8\u53ef\u7528\u90e8\u7f72\uff1a3\u53f0\u670d\u52a1\u5668\u6253\u9020\u54e8\u5175\u96c6\u7fa4"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/22849","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=22849"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/22849\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/22848"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=22849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=22849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=22849"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=22849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}