{"id":201555,"date":"2025-05-10T10:25:41","date_gmt":"2025-05-10T02:25:41","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201555\/"},"modified":"2025-05-10T10:25:41","modified_gmt":"2025-05-10T02:25:41","slug":"%e4%b8%80%e6%96%87%e8%81%8a%e8%81%8a-redis-%e7%9a%84%e7%bc%93%e5%ad%98%e5%9c%ba%e6%99%af","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201555\/","title":{"rendered":"\u4e00\u6587\u804a\u804a Redis \u7684\u7f13\u5b58\u573a\u666f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u4e00\u6587\u804a\u804a Redis \u7684\u7f13\u5b58\u573a\u666f<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u6765\u5230golang\u5b66\u4e60\u7f51\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6570\u636e\u5e93\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300a\u4e00\u6587\u804a\u804a Redis \u7684\u7f13\u5b58\u573a\u666f\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\u7f13\u5b58\u3001\u6570\u636e\u3001\u67b6\u6784\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.17golang.com\/uploads\/20230224\/167723647663f898fcaa42d.jpg\" style=\"max-width:100%\"> <\/p>\n<h2>\u5e8f\u8a00<\/h2>\n<p><span style=\"font-size: 15px\">\u590f\u65e5\u708e\u708e\uff0c\u65e0\u98ce\u3002\u4ece\u7a7a\u8c03\u623f\u95f4\u51fa\u6765\uff0c\u518d\u5230\u63a5\u8fd1\u56db\u5341\u5ea6\u7684\u9ad8\u6e29\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u7f13\u5b58\u9884\u70ed\u4e86\u89e3\u4e00\u4e0b\u2026\u2026<\/span><\/p>\n<p><span style=\"font-size: 15px\"><strong>\u4e3a\u4ec0\u4e48\u8981\u7528\u7f13\u5b58\uff1f<\/strong>\u56e0\u4e3a\u8ffd\u6c42\u6027\u80fd\uff0c\u56e0\u4e3a\u8981\u8ffd\u6c42\u6781\u81f4\u7684\u7528\u6237\u4f53\u9a8c\u3002<\/span><\/p>\n<h2>\u7f13\u5b58\u7406\u8bba<\/h2>\n<p><strong>1\u3001\u7f13\u5b58\u9002\u5408\u7684\u573a\u666f<\/strong><\/p>\n<p><span style=\"font-size: 15px\">\u7f13\u5b58\uff0c\u5c31\u662f\u5c06\u4e00\u4e9b\u9700\u8981\u8bfb\u53d6\u6570\u636e\u653e\u5728\u78c1\u76d8\u6216\u8005\u5185\u5b58\u4e2d\uff0c\u7531\u4e8e\u662f\u8ffd\u6c42\u901f\u5ea6\uff0c\u4ece\u800c\u4e00\u822c\u653e\u5728\u5185\u5b58\u4e2d\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u5728\u8bfb\u53d6\u6570\u636e\u7684\u65f6\u5019\uff0c\u4e00\u822c\u662f\u4ece\u5173\u7cfb\u578b\u6570\u636e\u5e93\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u5728\u6570\u636e\u5e93\u5c42\u9762\u4e5f\u53ef\u4ee5\u8fdb\u884c\u5404\u79cd\u4f18\u5316\uff0c\u4f8b\u5982\u8bfb\u6027\u80fd\u4e0d\u8db3\uff0c\u90a3\u4e48\u53ef\u4ee5\u6dfb\u52a0\u51e0\u4e2a\u4ece\u5e93\uff0c\u4ece\u800c\u6570\u636e\u5e93\u7684\u4e00\u4e3b\u591a\u4ece\uff1b\u4f8b\u5982\u5199\u6027\u80fd\u4e0d\u8db3\uff0c\u90a3\u4e48\u53ef\u4ee5\u5206\u5e93\u5206\u8868\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u5728\u6709\u4e9b\u573a\u666f\u4e2d\uff0c\u8981\u4f7f\u7528\u7f13\u5b58\uff0c\u662f\u56e0\u4e3a\u65e0\u6cd5\u89e3\u51b3\u8bfb\u7684\u901f\u5ea6\uff0c\u4f8b\u5982<\/span><code><span style=\"font-size: 15px\">count\uff08*\uff09<\/span><\/code><span style=\"font-size: 15px\">\u7684\u64cd\u4f5c\uff0c\u65e0\u8bba\u4ece\u6570\u636e\u5e93\u7684\u5c42\u9762\u5982\u4f55\u4f18\u5316\uff0c\u90fd\u4e0d\u53ef\u80fd\u63d0\u9ad8\uff1b\u8fd8\u6709\u4e00\u79cd\u5c31\u662f<strong>sql\u7684\u6267\u884c\u672c\u8eab\u5c31\u5fc5\u987b\u6d88\u8017\u5f88\u591a\u8d44\u6e90\u548c\u65f6\u95f4<\/strong>\uff0c\u4f8b\u5982\u5404\u79cd\u5173\u8054\u67e5\u8be2\u5b50\u67e5\u8be2\uff0c\u8fd9\u4e9b\u65f6\u5019\uff0c\u90fd\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u6570\u636e\u653e\u5728\u7f13\u5b58\u5f53\u4e2d\uff0c\u4ece\u800c\u5927\u5927\u7684\u51cf\u8f7b\u6570\u636e\u5e93\u7684\u538b\u529b\u3002<\/span><\/p>\n<p><strong>2\u3001\u7f13\u5b58\u7a7f\u900f\u95ee\u9898<\/strong><\/p>\n<p><span style=\"font-size: 15px\">\u5728\u4f7f\u7528\u7f13\u5b58\u7684\u65f6\u5019\uff0c\u7b2c\u4e00\u4e2a\u95ee\u9898\u5c31\u662f\u7f13\u5b58\u7a7f\u900f\u7684\u95ee\u9898\uff0c\u5c31\u662f\u4f7f\u7528\u4e86\u7f13\u5b58\u548c\u6ca1\u4f7f\u7528\u7f13\u5b58\u662f\u4e00\u6837\u7684\uff0c\u5e94\u7528\u7a0b\u5e8f\u5230\u7f13\u5b58\u4e2d\u67e5\u8be2\u6570\u636e\uff0c\u53d1\u73b0\u6570\u636e\u4e48\u6709\uff0c\u90a3\u4e48\u5c31\u53bb\u6570\u636e\u5e93\u67e5\u8be2\uff0c\u5728\u8fd9\u91cc\uff0c\u7a7f\u900f\u4e86\u7f13\u5b58\uff0c\u7f13\u5b58\u6ca1\u8d77\u5230\u4fdd\u62a4\u6570\u636e\u5e93\u7684\u4f5c\u7528\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u5728\u722c\u866b\u722c\u53d6\u7f51\u9875\u7684\u65f6\u5019\uff0c\u6bcf\u4e2a\u5206\u9875\u90fd\u4f1a\u722c\u53d6\uff0c\u800c\u5bf9\u4e8e\u7f13\u5b58\u7684\u5206\u9875\u6570\u636e\uff0c\u4e00\u822c\u53ea\u7f13\u5b58\u4e86\u70ed\u70b9\u6570\u636e\uff0c\u4e5f\u5c31\u662f\u524d\u51e0\u9875\u7684\u6570\u636e\u5728\u7f13\u5b58\u5f53\u4e2d\uff0c\u5982\u679c\u5168\u90e8\u722c\u53d6\uff0c\u90a3\u4e48\u5c31\u4f1a\u9020\u6210\u7f13\u5b58\u4e0d\u547d\u4e2d\uff0c\u5bfc\u81f4\u67e5\u8be2\u6570\u636e\u5e93\uff1b\u8fd8\u6709\u4e00\u79cd\u5c31\u662f\u6545\u610f\u641c\u7d22\u4e00\u4e9b\u4e0d\u5b58\u5728\u7684\u5173\u952e\u5b57\uff0c\u800c\u8fd9\u4e9b\u641c\u7d22\u7684\u7ed3\u679c\u90fd\u6ca1\u6709\u6570\u636e\uff0c\u5728\u6570\u636e\u5e93\u4e2d\u4e5f\u4e0d\u5b58\u5728\u6570\u636e\uff0c\u4ece\u800c\u9020\u6210\u7f13\u5b58\u7a7f\u900f\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u6b64\u79cd\u89e3\u51b3\u65b9\u6cd5\u5c31\u662f\uff1a\u5f53\u7528\u6237\u8fdb\u884c\u7b2c\u4e00\u6b21\u67e5\u8be2\u7684\u65f6\u5019\u53d1\u73b0\u7ed3\u679c\u4e3a\u7a7a\uff0c\u90a3\u4e48\u53ef\u4ee5\u5c06\u7ed3\u679c\u653e\u5728\u7f13\u5b58\u4e2d\uff0c\u8bbe\u7f6e\u4e00\u4e2a\u77ed\u6682\u7684\u8fc7\u671f\u65f6\u95f4\uff0c\u4ece\u800c\u53ef\u4ee5\u7f13\u89e3\u7a7f\u900f\u7684\u95ee\u9898\uff1b\u800c\u5bf9\u4e8e\u722c\u866b\u7684\u722c\u53d6\u6570\u636e\uff0c\u53ea\u80fd\u8fdb\u884c\u76d1\u63a7\uff0c\u7136\u540e\u8fdb\u884c\u8bbf\u95ee\u7684IP\uff0c\u4f9d\u65e7\u53ea\u80fd\u7f13\u89e3\uff0c\u4e0d\u80fd\u5b8c\u5168\u89e3\u51b3\u3002<\/span><\/p>\n<p><strong>3\u3001\u7f13\u5b58\u96ea\u5d29\u7684\u95ee\u9898<\/strong><\/p>\n<p><span style=\"font-size: 15px\">\u7f13\u5b58\u96ea\u5d29\u6307\u7684\u662f\u5f53\u7f13\u5b58\u5931\u6548\u4e4b\u540e\uff0c\u4ece\u800c\u5f15\u8d77\u7cfb\u7edf\u6027\u80fd\u7684\u6025\u5267\u4e0b\u964d\uff0c\u5bfc\u81f4\u6570\u636e\u5e93\u4e0d\u53ef\u7528\u4ece\u800c\u7cfb\u7edf\u6302\u6389\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u7f13\u5b58\u6700\u5173\u952e\u7684\u5730\u65b9\u5c31\u662f\u5185\u5b58\uff0c\u5f53\u5185\u5b58\u6ee1\u4e86\u4e4b\u540e\uff0c\u4f1a\u6709\u5404\u79cd\u7b56\u7565\u5c06\u7f13\u5b58\u8fdb\u884c\u5931\u6548\uff0c\u5728\u5206\u5e03\u5f0f\u73af\u5883\u4e0b\uff0c\u5982\u679c\u6709\u4e00\u4e2a\u7f13\u5b58\u5931\u6548\uff0c\u800c\u6070\u597d\u8fd9\u4e2a\u7f13\u5b58\u662f\u4e00\u4e2a\u70ed\u70b9\u6570\u636e\uff0c\u524d\u7aef\u670910\u4e2a\u5e94\u7528\u90fd\u9700\u8981\u8bbf\u95ee\u8fd9\u4e2a\u7f13\u5b58\uff0c\u5e76\u4e14TPS\u5f88\u9ad8\u7684\u8bdd\uff0c\u90a3\u4e48\u5168\u90e8\u7684\u7ebf\u7a0b\u90fd\u4f1a\u53bb\u8bbf\u95ee\u6570\u636e\u5e93\uff0c\u4ece\u800c\u80fd\u76f4\u63a5\u5c06\u6570\u636e\u5e93\u62d6\u57ae\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u5e94\u5bf9\u7f13\u5b58\u96ea\u5d29\uff0c\u6709\u5f88\u591a\u7b56\u7565\uff0c\u4f8b\u5982\u53ef\u4ee5\u8bbe\u7f6e\u4e24\u4e2a\u7f13\u5b58\u7684key\uff0c\u800c\u5177\u6709\u4e0d\u540c\u7684\u5931\u6548\u65f6\u95f4\uff0c\u5f53key1\u5931\u6548\u4e4b\u540e\uff0c\u8bbf\u95eekey2\uff0c\u7136\u540e\u66f4\u65b0key1\u548ckey2\uff1b\u53ef\u4ee5\u4f7f\u7528\u5206\u5e03\u5f0f\u9501\uff0c\u4ece\u800c\u5f53\u5e94\u7528\u53d1\u73b0\u7f13\u5b58\u5931\u6548\u4e4b\u540e\uff0c\u62ff\u5230\u9501\u7684\u7ebf\u7a0b\u624d\u53bb\u66f4\u65b0\u7f13\u5b58\uff1b\u53ef\u4ee5\u4f7f\u7528\u6d88\u606f\u901a\u77e5\u673a\u5236\uff0c\u5f53\u5e94\u7528\u53d1\u73b0\u7f13\u5b58\u5931\u6548\u4e4b\u540e\uff0c\u53d1\u9001\u6d88\u606f\uff0c\u7136\u540e\u540e\u53f0\u7ebf\u7a0b\u8fdb\u884c\u66f4\u65b0\u7f13\u5b58\uff0c\u540e\u53f0\u7ebf\u7a0b\u4f1a\u68c0\u6d4b\u7f13\u5b58\u4e2d\u662f\u5426\u5b58\u5728\u7f13\u5b58\uff0c\u5982\u679c\u5b58\u5728\u5c31\u4e0d\u66f4\u65b0\uff1b\u4e13\u95e8\u7528\u4e00\u4e2a\u540e\u53f0\u7ebf\u7a0b\u6765\u66f4\u65b0\u7f13\u5b58\uff0c\u5feb\u901f\u7684\u68c0\u6d4b\u7f13\u5b58\u662f\u5426\u5b58\u5728\uff0c\u7136\u540e\u66f4\u65b0\u7f13\u5b58\uff0c\u6b64\u79cd\u4e5f\u53ef\u4ee5\u89e3\u51b3\u7f13\u5b58\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002<\/span><\/p>\n<p><strong>4\u3001\u7f13\u5b58\u547d\u540d\u548c\u5931\u6548\u65f6\u95f4<\/strong><\/p>\n<p><span style=\"font-size: 15px\">\u5728\u4f7f\u7528\u7f13\u5b58\u7684\u65f6\u5019\uff0c\u90fd\u9700\u8981\u4e00\u4e2akey\uff0c\u90a3\u4e48\u8fd9\u4e2akey\u600e\u4e48\u547d\u540d\u5462\uff1fkey\u592a\u957f\uff0c\u5360\u7528\u5185\u5b58\uff0c\u4f1a\u4f7f\u5f97\u7f13\u5b58\u4e2d\u80fd\u5b58\u50a8\u7684\u6570\u636e\u51cf\u5c11\uff1bkey\u4e00\u822c\u7684\u547d\u540d\u89c4\u5219\u53ef\u4ee5\u4e3aSQL:1782\uff0c\u8868\u793a\u4e3a\u8fd9\u662f\u7f13\u5b58\u4e00\u4e2asql\u7684\u7ed3\u679c\uff0c\u7136\u540e\u7528\u5192\u53f7\u5206\u5272\uff0c\u7136\u540e\u8868\u793a\u4e3a\u7f13\u5b58\u7684\u7f16\u53f7\uff0c\u53ef\u4ee5\u4e3a\u5404\u79cdsql\u6761\u4ef6\u7684hash\u540e\u7684\u7ed3\u679c\uff0c\u8fd9\u79cd\u547d\u540d\u89c4\u5219\u7684\u597d\u5904\u5c31\u662f\uff0c\u5728\u6bcf\u6b21\u5728\u7f13\u5b58\u91cc\u67e5\u8be2\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u4f7f\u7528\u901a\u914d\u7b26\uff0c\u4ece\u800c\u53ef\u4ee5\u67e5\u8be2\u5230\u6709\u591a\u5c11\u4e2a\u7f13\u5b58\u5728\u7cfb\u7edf\u4e2d\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u7f13\u5b58\u7684\u5931\u6548\u65f6\u95f4\uff0c\u8fd9\u4e2a\u548c\u4e1a\u52a1\u5f3a\u76f8\u5173\uff0c\u5bf9\u4e8e\u4e00\u4e9b\u65f6\u6548\u6027\u6bd4\u8f83\u9ad8\u7684\u6570\u636e\uff0c\u5c31\u4e0d\u80fd\u653e\u5728\u7f13\u5b58\u5f53\u4e2d\uff0c\u800c\u5bf9\u4e8e\u4e00\u4e9b\u4e0d\u7ecf\u5e38\u53d8\u5316\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u653e\u5728\u7f13\u5b58\u5f53\u4e2d\uff0c\u4f8b\u5982\u4e00\u5929\uff0c\u7f13\u5b58\u4e3b\u8981\u662f\u5e94\u5bf9\u8bfb\u591a\u5199\u4e0a\u7684\u5e94\u7528\uff0c\u4ece\u800c\u5927\u90e8\u5206\u7684\u6570\u636e\u4f8b\u5982\u5728\u641c\u7d22\u7684\u7ed3\u679c\u7684\u5206\u9875\u6570\u636e\uff0c\u8fd9\u79cd\u5b9e\u65f6\u6027\u65e0\u987b\u592a\u9ad8\uff0c\u53ef\u4ee5\u653e\u5728\u7f13\u5b58\u5f53\u4e2d\u3002\u3002\u3002\u4e3b\u8981\u770b\u4e1a\u52a1\u7684\u5bb9\u5fcd\u7a0b\u5ea6\uff0c\u4e5f\u5f71\u54cd\u5230\u4e00\u90e8\u5206\u7684\u7528\u6237\u4f53\u9a8c\uff0c\u53ef\u80fd\u6211\u653e\u5165\u4e86\u7f13\u5b58\uff0c\u66f4\u65b0\u4e86\uff0c\u5237\u65b0\u4e0b\uff0c\u8fd8\u6ca1\u6709\u66f4\u65b0\u3002<\/span><\/p>\n<p><strong>5\u3001\u7f13\u5b58\u9884\u70ed\u548c\u7f13\u5b58\u70ed\u70b9\u95ee\u9898<\/strong><\/p>\n<p><span style=\"font-size: 15px\">\u7f13\u5b58\u9884\u70ed\uff0c\u5728\u7cfb\u7edf\u5b95\u673a\u521a\u4e0a\u7ebf\u7684\u65f6\u5019\uff0c\u6d41\u91cf\u5168\u90e8\u6d8c\u5165\uff0c\u800c\u6b64\u65f6\u7f13\u5b58\u4e2d\u8fd8\u6ca1\u6709\u7f13\u5b58\u6570\u636e\uff0c\u4ece\u800c\u53ef\u80fd\u5bfc\u81f4\u76f4\u63a5\u538b\u57ae\u6570\u636e\u5e93\uff0c\u4ece\u800c\u5728\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u4e4b\u540e\uff0c\u8981\u8fdb\u884c\u7f13\u5b58\u9884\u70ed\uff0c\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u5c31\u662f\u70b9\u70b9\u754c\u9762\uff0c\u7136\u540e\u641c\u7d22\u4e00\u4e0b\u7ed3\u679c\uff1b<\/span><span style=\"font-size: 15px\">\u6700\u597d\u7684\u65b9\u5f0f\uff0c\u5c31\u662f\u5199\u4e00\u4e2a\u540e\u53f0\u7ebf\u7a0b\uff0c\u8fdb\u884c\u7f13\u5b58\u9884\u70ed\uff0c\u5728\u8fd9\u4e2a\u540e\u53f0\u7ebf\u7a0b\u91cc\uff0c\u4f1a\u5c06\u5e38\u7528\u7684\u70ed\u70b9\u6570\u636e\u90fd\u76f4\u63a5\u52a0\u8f7d\u8fdb\u7f13\u5b58\u5f53\u4e2d\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u7f13\u5b58\u70ed\u70b9\uff0c\u5f53\u4f7f\u7528\u7684\u662f\u7f13\u5b58\u96c6\u7fa4\u7684\u65f6\u5019\uff0c\u5982\u679c\u7f13\u5b58\u5206\u5e03\u7684\u6709\u95ee\u9898\uff0c\u90a3\u4e48\u53ef\u80fd\u4e00\u53f0\u7f13\u5b58\u670d\u52a1\u5668\u627f\u62c5\u4e86\u5927\u90e8\u5206\u7684\u538b\u529b\uff0c\u800c\u53e6\u5916\u4e00\u4e9b\u7f13\u5b58\u670d\u52a1\u5668\u5219\u6ca1\u6709\u538b\u529b\uff0c\u4ece\u800c\u4e5f\u6709\u53ef\u80fd\u5bfc\u81f4\u7f13\u5b58\u96ea\u5d29\uff0c\u76f4\u63a5\u538b\u57ae\u4e00\u53f0\u7f13\u5b58\u670d\u52a1\u5668\uff0c\u4e0a\u7ebf\uff0c\u53c8\u538b\u57ae\u4e00\u53f0\uff0c\u6b7b\u5faa\u73af\u3002<\/span><span style=\"font-size: 15px\">\u3002<\/span><span style=\"font-size: 15px\">\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u5728\u8fdb\u884c\u7f13\u5b58\u6570\u636e\u7684\u65f6\u5019\uff0c\u9700\u8981\u5206\u6790\u70ed\u70b9\u6570\u636e\uff0c\u5e76\u4e14\u8981\u5206\u6790\u7f13\u5b58\u7684\u6570\u636e\u91cf\u7684\u5927\u5c0f\uff0c\u5426\u5219\u65e0\u8bba\u662f\u7f51\u7edc\u8fd8\u662f\u5185\u5b58\uff0c\u90fd\u53ef\u80fd\u9020\u6210\u7f13\u5b58\u96ea\u5d29\u7684\u6f5c\u5728\u5f71\u54cd\u70b9\u3002<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.17golang.com\/uploads\/20230224\/167723647763f898fd24215.png\"> <\/p>\n<h2>redis\u4e3b\u5907<\/h2>\n<p><span style=\"font-size: 15px\">reids\u662f\u4e00\u4e2a\u952e\u503c\u5b58\u50a8\u7684\u5185\u5b58cache\u6216\u8005\u6301\u4e45\u5316\u5b58\u50a8\uff0c\u7528redis\u505a\u7f13\u5b58\u662f\u7b80\u5355\u7684\u3002\u800credis\u518d\u6b64\u65f6\u4e5f\u65e0\u9700\u6301\u4e45\u5316\u673a\u5236\uff0c\u4ece\u800c\u76f4\u63a5\u5728\u5bb9\u5668\u4e2d\u4f7f\u7528\u3002<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.17golang.com\/uploads\/20230224\/167723647763f898fd979db.jpg\"> <\/p>\n<p><span style=\"font-size: 15px\">\u4e24\u6761\u6307\u4ee4\u8fd0\u884c\u4e00\u4e2aredis\u7684\u4e3b\u4ece\u7f13\u5b58\uff0c\u914d\u7f6e\u6587\u4ef6\u4f7f\u7528\u9ed8\u8ba4\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5728master\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u4fee\u6539bind\u5373\u53ef\uff0c\u5728slave\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u4fee\u6539bind\u548cslaveof\u5373\u53ef\u3002<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.17golang.com\/uploads\/20230224\/167723647863f898fe056a4.png\"> <\/p>\n<p><span style=\"font-size: 15px\">\u5982\u4f55\u6765\u68c0\u6d4b\u8fd9\u4e2aredis\u662fok\uff1f\u7528\u5bb9\u5668\u6765\u8fd0\u884c\u4e00\u4e2a\u6d4b\u8bd5redis\u7684\u529f\u80fd\uff0c\u6267\u884c\u7684\u6548\u679c\u5982\u4e0b\u6240\u793a\uff1a<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.17golang.com\/uploads\/20230224\/167723647863f898fe6b37c.png\"> <\/p>\n<p><span style=\"font-size: 15px\">\u4e13\u95e8\u4f7f\u7528\u4e00\u4e2atestredis\u7684\u5bb9\u5668\u6765\u8fd0\u884c\u4e00\u4e2a\u6d4b\u8bd5\u4efb\u52a1\uff0c\u5728\u6b63\u5e38\u7684\u60c5\u51b5\u4e0b\uff0c\u5bb9\u5668\u7684\u9000\u51fa\u7801\u4e3a0\uff0c\u5f53redis\u5f02\u5e38\u7684\u65f6\u5019\uff0c\u5bb9\u5668\u7684\u9000\u51fa\u7801\u4e3a1\uff0c\u4ece\u800c\u53ef\u4ee5\u5728\u751f\u4ea7\u4e2d\u8fdb\u884c\u529f\u80fd\u6027\u6d4b\u8bd5\uff0c\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u8fdb\u884c\u81ea\u52a8\u4fee\u590d\uff0c\u4f8b\u5982\u62c9\u8d77\u5931\u8d25\u7684redis\u5bb9\u5668\u5373\u53ef\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u68c0\u6d4b\u811a\u672c\u7684\u5185\u5bb9\uff1a<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.17golang.com\/uploads\/20230224\/167723647863f898fedf358.png\"> <\/p>\n<p><span style=\"font-size: 15px\">\u5728\u8fd0\u884c\u8fd9\u4e2a\u6d4b\u8bd5\u5bb9\u5668\u7684\u65f6\u5019\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8981\u4f7f\u7528host\u7684\u7f51\u7edc\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.17golang.com\/uploads\/20230224\/167723647963f898ff51183.png\"> <\/p>\n<p><span style=\"font-size: 15px\">\u4ee5\u540e\u8981\u8fdb\u884c\u8fd0\u884c\u6d4b\u8bd5\u5bb9\u5668\u7684\u65f6\u5019\uff0c\u53ea\u8981start\u8fd9\u4e2a\u5bb9\u5668\u5373\u53ef\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u6b64\u79cd\u8fc7\u7a0b\u8fdb\u884c\u4f18\u5316\uff0c\u4f8b\u5982\u4f7f\u7528\u4e00\u4e2a\u811a\u672c\uff0c\u5c31\u76f4\u63a5\u521b\u5efamaster\uff0cslave\u548c\u6d4b\u8bd5\u5bb9\u5668\uff0c\u8fd8\u80fd\u8fdb\u4e00\u6b65\u5c06master\u548cslave\u5206\u5e03\u5728\u4e0d\u540c\u7684\u673a\u5668\u4e0a\uff0c\u8fd8\u80fd\u8fdb\u4e00\u6b65\u76f4\u63a5\u521b\u5efasentinel\u8fdb\u884c\u81ea\u52a8\u5207\u6362\u548c\u6545\u969c\u8f6c\u79fb\uff0c\u8fd8\u80fd\u76f4\u63a5\u521b\u5efa\u4e00\u4e2aredis cluster\u6a21\u5f0f\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u5728\u4f7f\u7528config rewrite\u5199\u5165\u914d\u7f6e\u6587\u4ef6\u7684\u65f6\u5019\uff0c\u6ce8\u610fselinux\u53ef\u80fd\u4f1a\u963b\u6b62\u4f60\u5199\u5165\u914d\u7f6e\u6587\u4ef6\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u5728\u4f7f\u7528\u7684\u7f13\u5b58\u7b56\u7565\u4e3anoeviction\u7684\u65f6\u5019\uff0c\u90a3\u4e48\u4e00\u65e6\u53ef\u7528\u5185\u5b58\u4f7f\u7528\u5b8c\u6bd5\uff0c\u5c31\u4f1a\u663e\u793aOOM\uff0c\u5185\u5b58\u8d85\u8fc7\u4e86\u6700\u5927\u4f7f\u7528\u5185\u5b58\uff0c\u9ed8\u8ba4\u914d\u7f6e\u5e76\u4e0d\u4f1a\u4f7f\u7528LRU\u7b97\u6cd5\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u5728\u67e5\u770b\u952e\u7684\u6570\u91cf\u7684\u65f6\u5019\uff0c\u5207\u8bb0keys\u662f\u9ad8\u5371\u6307\u4ee4\uff0c\u4f1a\u963b\u585e\u6240\u6709\u7684\u8bf7\u6c42\uff0c\u5f71\u54cd\u751f\u4ea7\u73af\u5883\u7684\u670d\u52a1\uff0c\u4e0d\u4fe1\uff1f<\/span><span style=\"font-size: 15px\">\u5230\u751f\u4ea7\u4e0a\u8bd5\u8bd5\uff0c\u6307\u4ee4\u4e3akeys *\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u5728\u67e5\u770b\u5927\u91cf\u952e\u7684\u65f6\u5019\uff0c\u4f7f\u7528scan\u6307\u4ee4\uff0c\u6bcf\u6b21\u8fd4\u56de\u4e00\u4e2a\u6e38\u6807\uff0c\u76f8\u5f53\u4e8e\u5206\u9875\u67e5\u770b\u54af\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u5728\u8fdb\u884c\u8f6c\u50a8\u7684\u65f6\u5019\uff0c\u4e0d\u8981\u7528save\u6307\u4ee4\uff0c\u5207\u8bb0\u8981\u4f7f\u7528bgsave\u548cbgrewriteaof\uff0c\u867d\u7136\u8fd9\u4e24\u4e2a\u4e0d\u4f1a\u963b\u585e\u670d\u52a1\uff0c\u5176\u5b9e\u4e5f\u4f1a\u963b\u585e\uff0c\u4e0d\u8fc7\u65f6\u95f4\u5f88\u77ed\uff0c\u4e3b\u8981\u8017\u8d39\u7684\u65f6\u95f4\u5728fork\u7684\u65f6\u5019\uff0c400ms\u4e86\u89e3\u4e00\u4e0b\u3002<\/span><span style=\"font-size: 15px\">\u3002<\/span><span style=\"font-size: 15px\">\u3002<\/span><span style=\"font-size: 15px\">fork\u4e00\u822c\u9700\u8981\u591a\u5c11ms\uff1f<\/span><span style=\"font-size: 15px\">\u6c42\u89e3<\/span><\/p>\n<h2>\u95f2\u804a<\/h2>\n<p><span style=\"font-size: 15px\">\u7f13\u5b58\u547d\u4e2d\u7387\uff1f<\/span><span style=\"font-size: 15px\">\u4e0d\u53ef\u80fd\u7684\u3002<\/span><span style=\"font-size: 15px\">\u3002<\/span><span style=\"font-size: 15px\">\u3002<\/span><span style=\"font-size: 15px\">\u8fd9\u8f88\u5b50\u90fd\u4e0d\u53ef\u80fd\u547d\u4e2d\u7684\u2026\u2026<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u4f9d\u7a00\u8bb0\u5f97\u6709\u4eba\u6311\u6218\uff0c\u4f46\u662f\u6211\u5fd8\u8bb0\u4e86\u662f\u4e2a\u5177\u4f53\u4ec0\u4e48\u6837\u7684\u95ee\u9898\u3002<\/span><span style=\"font-size: 15px\">\u5176\u5b9e\u634d\u536b\u4e0d\u634d\u536b\u771f\u7684\u65e0\u6240\u8c13\uff0c\u4e0d\u634d\u536b\u81ea\u5df1\u7684\u89c2\u70b9\u5728\u4e8e\uff0c\u66b4\u9732\u5bf9\u65b9\u7684\u65e0\u77e5\uff0c\u5982\u679c\u634d\u536b\u6211\u81ea\u5df1\u7684\u89c2\u70b9\uff0c\u90a3\u5c31\u4f1a\u66b4\u9732\u81ea\u5df1\u7684\u65e0\u77e5\uff0c\u5f53\u7136\uff0c\u4e00\u822c\u6211\u90fd\u662f\u5148\u8868\u73b0\u51fa\u6211\u7684\u65e0\u77e5\uff0c\u8fd9\u6837\u624d\u80fd\u5f15\u5165\u65b0\u5947\u7684\u89c2\u70b9\uff0c\u5426\u5219\uff0c\u4e00\u65e0\u6240\u83b7\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u518d\u8c08\u81ea\u52a8\u5316\u8fd0\u7ef4\uff0c\u6709\u4eba\u8bf4\uff0c\u4f60\u5c31\u4e24\u4e2a\u547d\u4ee4\u7684\u4e8b\u513f\uff0c\u4f60\u8fd8\u8d39\u52b2\u5df4\u62c9\u7684\u5199\u6210\u4e00\u4e2a\u754c\u9762\uff0c\u5199\u6210\u4e00\u4e2a\u6309\u94ae\uff0c\u6709\u610f\u601d\u4e48\uff0c\u6709\u610f\u601d\uff0c\u76f8\u5f53\u6709\u610f\u601d\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u9632\u6b62\u8bef\u64cd\u4f5c\uff0c\u8fd9\u662f\u4e3b\u8981\u529f\u80fd\uff0c\u81ea\u52a8\u5316\u5e73\u53f0\u627f\u62c5\u5927\u90e8\u5206\u8d23\u4efb\uff0c\u5c01\u88c5\u6240\u6709\u7684\u9ad8\u5371\u64cd\u4f5c\u6307\u4ee4\uff0c\u53ef\u4ee5\u8fdb\u884c\u4e8c\u6b21\u786e\u8ba4\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u6743\u9650\u63a7\u5236\uff0c\u54ea\u4e9b\u4eba\u80fd\u4f7f\u7528\u8fd9\u4e2a\uff0c\u54ea\u4e9b\u4eba\u4e0d\u80fd\u4f7f\u7528\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u4e00\u53f0\u673a\u5668\u4e24\u4e2a\u6307\u4ee4\uff0c\u4e09\u53f0\u4f60\u8bd5\u8bd5\uff0c\u4e09\u767e\u53f0\u4f60\u8bd5\u8bd5\uff0c\u4e09\u5343\u53f0\u5462\uff1f<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u6709\u7684\u65f6\u5019\uff0c\u611f\u89c9\u601d\u7ef4\u5c42\u6b21\u4e0d\u540c\uff0c\u4e0d\u60f3\u89e3\u91ca\uff0c\u89e3\u91ca\u5c31\u662f\u63a9\u9970<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u4e00\u4e2a\u7f13\u5b58\u7cfb\u7edf\uff0c\u80fd\u73a9\u591a\u4e45\uff1f<\/span><span style=\"font-size: 15px\">\u80fd\u73a9\u5f88\u4e45\u5f88\u4e45\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u4e00\u4e2a\u7cfb\u7edf\uff0c\u91cc\u9762\u5305\u542b\u7740\u65e0\u6570\u4e2a\u5c0f\u7cfb\u7edf\uff0c\u7f13\u5b58\u7cfb\u7edf\uff1f<\/span><span style=\"font-size: 15px\">\u53ef\u4ee5\u7528redis\u548cmemcache\uff0c\u4f60\u600e\u4e48\u9009\uff1f<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u4e00\u4e2a\u7cfb\u7edf\uff0c\u91cc\u9762\u53c8\u5305\u542b\u7740\u65e0\u6570\u7684\u77e5\u8bc6\u70b9\uff0credis\u662f\u5355\u8fdb\u7a0b\u5355\u7ebf\u7a0b\u7684\u670d\u52a1\uff0c\u90a3\u4e48\u90a3\u4e9b\u4f1a\u963b\u585e\u670d\u52a1\uff1f<\/span><span style=\"font-size: 15px\">\u5728\u5ba2\u6237\u7aef\u8bf7\u6c42\u8fc7\u6765\uff0ctcp\u8fde\u63a5\u6ee1\u4e86\u600e\u4e48\u529e\uff1f<\/span><span style=\"font-size: 15px\">\u53c2\u6570backlop\u662f\u5426\u8981\u54cd\u5e94\u589e\u52a0\uff1f<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u4e00\u4e2a\u7cfb\u7edf\uff0c\u8981\u8ffd\u6c42\u9ad8\u53ef\u7528\uff0c\u9ad8\u6027\u80fd\uff0c\u90a3\u4e48\u5c31\u4f1a\u5f15\u5165\u5176\u4ed6\u7684\u7ec4\u4ef6\uff0c\u4f8b\u5982\u4f7f\u7528sentinel\u8fbe\u6210\u9ad8\u53ef\u7528\uff0c\u4f7f\u7528redis cluster\u6765\u8fdb\u884c\u642d\u5efa\uff0c\u4f7f\u7528\u524d\u7aef\u7684\u5404\u79cd\u4e2d\u95f4\u4ef6\u3002<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u4e00\u4e2a\u7cfb\u7edf\u7684\u914d\u7f6e\uff0c\u53c8\u5305\u542b\u4e86\u5404\u79cd\u6837\u7684\u4e1c\u897f\uff0credis\u7684\u6301\u4e45\u5316\u6709\u4e24\u79cd\uff0c\u4e00\u79cd\u662frdb\uff0c\u4e00\u79cd\u662faof\uff0c\u6709\u4f55\u533a\u522b\uff0c\u54ea\u79cd\u66f4\u597d\uff1f<\/span><span style=\"font-size: 15px\">\u5982\u679c\u6301\u4e45\u5316\u4f1a\u4e22\u5931\u6570\u636e\u5426\uff1f<\/span><span style=\"font-size: 15px\">\u4e22\u5931\u591a\u4e45\u7684\u6570\u636e\u53ef\u4ee5\u63a5\u53d7\uff1f<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u4e00\u4e2a\u7cfb\u7edf\u7684\u6784\u6210\uff0c\u5404\u79cd\u5404\u6837\u7684\u65b9\u5f0f\uff0c\u5982\u4f55\u8fdb\u884c\u4e3b\u5907\u590d\u5236\uff1f<\/span><span style=\"font-size: 15px\">sentinel\u5982\u4f55\u6765\u68c0\u6d4bmaster\u662f\u5426\u5b95\u673a\uff1f<\/span><span style=\"font-size: 15px\">sentinel\u4e3a\u4f55\u8981\u75283\u4e2a\u6216\u80055\u4e2a\u8282\u70b9\uff1f<\/span><\/p>\n<p><span style=\"font-size: 15px\">\u5b50\u5b50\u5b59\u5b59\u65e0\u7a77\u5c3d\u4e5f\uff0c\u53ef\u80fd\u5f88\u591a\u65f6\u5019\uff0c\u90fd\u78b0\u4e0d\u5230\u8fd9\u79cd\u573a\u666f\uff1f<\/span><span style=\"font-size: 15px\">\u9ad8\u5e76\u53d1\uff0c\u4e0d\u53ef\u80fd\u7684\uff0c\u8fd9\u8f88\u5b50\u90fd\u4e0d\u53ef\u80fd\u7684\uff0c\u98ce\u90fd\u4e48\u6709\uff0c\u5907\u7528\u77e5\u8bc6\u547d\u4e2d\u7387\uff0c\u4e86\u89e3\u4e00\u4e0b\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u6587\u804a\u804a Redis \u7684\u7f13\u5b58\u573a\u666f&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201555","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201555"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201555\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}