{"id":201659,"date":"2025-05-10T10:13:47","date_gmt":"2025-05-10T02:13:47","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201659\/"},"modified":"2025-05-10T10:13:47","modified_gmt":"2025-05-10T02:13:47","slug":"%e8%81%8a%e8%81%8aredis%e7%9a%84%e6%8c%81%e4%b9%85%e5%8c%96%e3%80%81rdb%e5%bf%ab%e7%85%a7%e5%92%8caof%e6%97%a5%e5%bf%97%ef%bc%88%e5%9b%be%e6%96%87%e8%af%a6%e8%a7%a3%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201659\/","title":{"rendered":"\u804a\u804aRedis\u7684\u6301\u4e45\u5316\u3001RDB\u5feb\u7167\u548cAOF\u65e5\u5fd7\uff08\u56fe\u6587\u8be6\u89e3\uff09"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u804a\u804aRedis\u7684\u6301\u4e45\u5316\u3001RDB\u5feb\u7167\u548cAOF\u65e5\u5fd7\uff08\u56fe\u6587\u8be6\u89e3\uff09<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>golang\u5b66\u4e60\u7f51\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;font-family:\">\u300a\u804a\u804aRedis\u7684\u6301\u4e45\u5316\u3001RDB\u5feb\u7167\u548cAOF\u65e5\u5fd7\uff08\u56fe\u6587\u8be6\u89e3\uff09\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;font-family:\">Redis\u3001\u6570\u636e\u5e93<\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;font-family:\">\u6570\u636e\u5e93<\/span>\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230313\/1678670103640e791736f6a.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p>\u4eca\u5929\u5206\u4eab\u4e00\u4e0bRedis\u7684\u6301\u4e45\u5316\u3001\u4e8b\u52a1\u3001\u7ba1\u9053\u76f8\u5173\u7684\u77e5\u8bc6\u70b9\uff0c\u5b9e\u73b0\u5feb\u901f\u5165\u95e8\uff0c\u4e30\u5bcc\u4e2a\u4eba\u7b80\u5386\uff0c\u63d0\u9ad8\u9762\u8bd5level\uff0c\u7ed9\u81ea\u5df1\u589e\u52a0\u4e00\u70b9\u8c08\u8d44\uff0c\u79d2\u53d8\u9762\u8bd5\u5c0f\u8fbe\u4eba\uff0cBAT\u4e0d\u662f\u68a6\u3002<\/p>\n<p>Redis\u662f\u4e00\u4e2a\u952e\u503c\u5bf9\u6570\u636e\u5e93\uff0c\u670d\u52a1\u5668\u4e2d\u901a\u5e38\u5305\u542b\u7740\u4efb\u610f\u4e2a\u975e\u7a7a\u6570\u636e\u5e93\uff0c\u800c\u6bcf\u4e2a\u975e\u7a7a\u6570\u636e\u5e93\u4e2d\u53c8\u53ef\u4ee5\u5305\u542b\u4efb\u610f\u4e2a\u952e\u503c\u5bf9\uff0c\u6211\u4eec\u5c06\u662f\u670d\u52a1\u5668\u4e2d\u7684\u975e\u7a7a\u6570\u636e\u5e93\u4ee5\u53ca\u5b83\u4eec\u7684\u952e\u503c\u5bf9\u7edf\u79f0\u4e3a\u6570\u636e\u5e93\u72b6\u6001\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230313\/1678670103640e79179d813.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p>Redis\u662f\u5185\u5b58\u6570\u636e\u5e93\uff0c\u5b83\u5c06\u6570\u636e\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u5982\u679c\u4e0d\u80fd\u5c06\u5185\u5b58\u4e2d\u7684\u6570\u636e\u6301\u4e45\u5316\u5230\u78c1\u76d8\u4e2d\uff0cRedis\u7a81\u7136\u5b95\u673a\uff0c\u4f1a\u5bfc\u81f4\u6570\u636e\u4e22\u5931\u3002<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0cRedis\u63d0\u4f9b\u4e86RDB\u6301\u4e45\u5316\u529f\u80fd\uff0c<span style=\"text-decoration:underline\">RDB\u6301\u4e45\u5316\u4f1a\u5c06Redis\u5728\u5185\u5b58\u4e2d\u7684\u6570\u636e\u5e93\u72b6\u6001\u4fdd\u5b58\u5230\u78c1\u76d8\u4e2d\uff0c\u907f\u514d\u6570\u636e\u610f\u5916\u4e22\u5931\u3002<\/span><\/p>\n<h3>\u4e00\u3001RDB\u6301\u4e45\u5316<\/h3>\n<p>RDB\uff0c\u82f1\u6587\u5168\u79f0Redis DataBase\uff0c\u5728\u6307\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\uff0c\u5c06\u5185\u5b58\u4e2d\u7684\u6570\u636e\u5199\u5165\u78c1\u76d8\uff0c\u5f85\u6062\u590d\u65f6\u518d\u5c06\u78c1\u76d8\u4e2d\u7684\u6570\u636e\u5199\u5165\u5185\u5b58\u3002<\/p>\n<h4>1\u3001\u81ea\u52a8\u89e6\u53d1<\/h4>\n<p>redis.conf\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0csave<\/p>\n<h4>2\u3001\u624b\u52a8\u89e6\u53d1<\/h4>\n<p>\u901a\u8fc7save\u548cbgsave\u624b\u52a8\u89e6\u53d1RDB\u5907\u4efd\u3002<\/p>\n<p>\uff081\uff09<strong>save<\/strong>\uff0c\u5728\u4e3b\u7a0b\u5e8f\u4e2d\u6267\u884c\u4f1a\u963b\u585e\u5f53\u524dRedis\u670d\u52a1\u5668\uff0c\u76f4\u5230RDB\u6301\u4e45\u5316\u5b8c\u6210\uff0c\u4e5f\u5c31\u662f\u8bf4save\u6301\u4e45\u5316\u671f\u95f4\uff0cRedis\u5c31\u4e0d\u80fd\u7528\u4e86\uff0c\u7981\u6b62\u4f7f\u7528\u3002<\/p>\n<p>\uff082\uff09<strong>bgsave<\/strong>\uff0c\u4e0d\u963b\u585e\u5f53\u524dRedis\u670d\u52a1\u5668\uff0cRedis\u4f1afork\u4e00\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u5f02\u6b65\u8fdb\u884c\u5feb\u7167\u64cd\u4f5c\u3002<\/p>\n<p>\u7981\u7528\u5feb\u7167\uff1aredis-cli config set save &#8220;&#8221;\u3002<\/p>\n<h4>3\u3001\u8bbe\u7f6e\u4fdd\u5b58\u6761\u4ef6<\/h4>\n<p>\u670d\u52a1\u5668\u7a0b\u5e8f\u4f1a\u6839\u636esave\u9009\u9879\u6240\u8bbe\u7f6e\u7684\u4fdd\u5b58\u6761\u4ef6\uff0c\u8bbe\u7f6e\u670d\u52a1\u5668\u72b6\u6001redisServer\u7ed3\u6784\u7684saveparams\u5c5e\u6027\u3002<\/p>\n<p>dirty\u8ba1\u6570\u5668\u8bb0\u5f55\u8ddd\u79bb\u4e0a\u6b21\u6210\u529f\u6267\u884csave\u547d\u4ee4\u540e\uff0c\u670d\u52a1\u5668\u5bf9\u6570\u636e\u72b6\u6001\u8fdb\u884c\u4e86\u591a\u5c11\u6b21\u4fee\u6539\u3002<\/p>\n<p>lastsave\u5c5e\u6027\u662f\u4e00\u4e2aUNIX\u65f6\u95f4\u6233\uff0c\u8bb0\u5f55\u4e86\u670d\u52a1\u5668\u4e0a\u4e00\u6b21\u6210\u529f\u6267\u884csave\u547d\u4ee4\u7684\u65f6\u95f4\u3002<\/p>\n<p>\u5c5e\u6027\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2asaveparam\u7ed3\u6784\uff0c\u6bcf\u4e2asaveparam\u7ed3\u6784\u90fd\u4fdd\u5b58\u4e86\u4e00\u4e2asave\u9009\u9879\u8bbe\u7f6e\u7684\u4fdd\u5b58\u6761\u4ef6\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230313\/1678670103640e7917e7e04.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fRedis\u670d\u52a1\u5668\u6839\u636esave\u9009\u9879\u6240\u8bbe\u7f6e\u7684\u4fdd\u5b58\u6761\u4ef6\uff0c\u81ea\u52a8\u6267\u884cbgsave\u547d\u4ee4\uff0c\u8fdb\u884c\u95f4\u9694\u6027\u6570\u636e\u4fdd\u5b58\u7684\u5b9e\u73b0\u539f\u7406\u3002<\/p>\n<h4>4\u3001\u52a0\u89e3\u5bc6<\/h4>\n<p>RDB\u6301\u4e45\u5316\u529f\u80fd\u6240\u751f\u6210\u7684RDB\u6587\u4ef6\u662f\u4e00\u4e2a\u7ecf\u8fc7\u538b\u7f29\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u901a\u8fc7\u8be5\u6587\u4ef6\u53ef\u4ee5\u8fd8\u539f\u751f\u6210RDB\u6587\u4ef6\u65f6\u7684\u6570\u636e\u5e93\u72b6\u6001\u3002<\/p>\n<h4>5\u3001RDB\u6301\u4e45\u5316\u4f18\u7f3a\u70b9<\/h4>\n<p>\uff081\uff09\u4f18\u70b9<\/p>\n<ol>\n<li>\n<p>\u9002\u5408\u5927\u89c4\u6a21\u7684\u6570\u636e\u5907\u4efd\u3001\u6062\u590d\u3002<\/p>\n<\/li>\n<li>\n<p>\u53ef\u4ee5\u5b9a\u65f6\u5907\u4efd\u3002<\/p>\n<\/li>\n<li>\n<p>\u5bf9\u6570\u636e\u4e00\u81f4\u6027\u3001\u5b8c\u6574\u6027\u8981\u6c42\u4e0d\u9ad8\u7684\u573a\u666f\u53ef\u4ee5\u4f7f\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>RDB\u6587\u4ef6\u5728\u5185\u5b58\u4e2d\u7684\u52a0\u8f7d\u901f\u5ea6\u8981\u6bd4AOF\u5757\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\uff082\uff09\u7f3a\u70b9<\/p>\n<ol>\n<li>\n<p>\u56e0\u4e3a\u662f\u5b9a\u65f6\u5907\u4efd\uff0c\u5982\u679cRedis\u5b95\u673a\u7684\u8bdd\uff0c\u4f1a\u4e22\u5931\u4e00\u90e8\u5206\u6570\u636e\u3002<\/p>\n<\/li>\n<li>\n<p>\u56e0\u4e3a\u662f\u6570\u636e\u7684\u5168\u91cf\u540c\u6b65\uff0c\u5982\u679c\u6570\u636e\u91cf\u8fc7\u5927\uff0c\u4f1a\u4ea7\u751f\u5927\u91cfIO\uff0c\u4e25\u91cd\u5f71\u54cd\u670d\u52a1\u5668\u6027\u80fd\u3002<\/p>\n<\/li>\n<li>\n<p>RDB\u6301\u4e45\u5316\u65f6\uff0c\u4f1afork\u4e00\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u5982\u679c\u6570\u636e\u8fc7\u5927\uff0c \u53ef\u80fd\u4f1a\u5bfc\u81f4\u670d\u52a1\u5668\u7684\u77ac\u95f4\u5ef6\u8fdf\uff1bfork\u7684\u65f6\u5019\u5185\u5b58\u4e2d\u7684\u6570\u636e\u4f1a\u88ab\u514b\u9686\u4e00\u4efd\uff0c\u662f\u5426\u4f1a\u9020\u6210\u5185\u5b58\u6ea2\u51fa\uff0c\u503c\u5f97\u8003\u8651\u3002<\/p>\n<\/li>\n<\/ol>\n<h4>6\u3001\u54ea\u4e9b\u60c5\u51b5\u4f1a\u89e6\u53d1RDB\u6301\u4e45\u5316\uff1f<\/h4>\n<p>\uff081\uff09redis.conf\u4e2d\u7684\u5b9a\u65f6\u914d\u7f6e\u3002<\/p>\n<p>\uff082\uff09\u624b\u52a8\u6267\u884csave\u3001bgsave\u547d\u4ee4\u3002<\/p>\n<p>\uff083\uff09\u6267\u884cflushall\u3001flushdb\u547d\u4ee4\uff0c\u4ea7\u751f\u7684.rdb\u6587\u4ef6\u662f\u7a7a\u7684\u3002<\/p>\n<p>\uff084\uff09\u6267\u884cshutdown\u547d\u4ee4\uff0c\u4e14\u6ca1\u6709\u8bbe\u7f6eAOF\u6301\u4e45\u5316\u3002<\/p>\n<p>\uff085\uff09\u4e3b\u52a8\u590d\u5236\u65f6\uff0c\u4e3b\u8282\u70b9\u81ea\u52a8\u89e6\u53d1\u3002<\/p>\n<p>\u6ce8\u610f\uff1asave\u548cbgsave\u4e0d\u80fd\u540c\u65f6\u6267\u884c\uff0c\u5982\u679cbgsave\u547d\u4ee4\u6b63\u5728\u6267\u884c\uff0c\u90a3\u4e48\u5ba2\u6237\u7aef\u53d1\u9001\u7684save\u547d\u4ee4\u4f1a\u88ab\u62d2\u7edd\u6267\u884c\uff0c\u670d\u52a1\u5668\u7981\u6b62save\u548cbgsave\u540c\u65f6\u6267\u884c\u662f\u4e3a\u4e86\u907f\u514d\u7236\u8fdb\u7a0b\u548c\u5b50\u8fdb\u7a0b\u540c\u65f6\u6267\u884c\u4e24\u4e2ardbSave\u8c03\u7528\uff0c\u9632\u6b62\u4ea7\u751f\u7ade\u4e89\u6761\u4ef6\u3002<\/p>\n<p>\u521b\u5efaRDB\u6587\u4ef6\u7684\u5b9e\u9645\u5de5\u4f5c\u662f\u7531rdb.c\/rdbSave\u51fd\u6570\u5b8c\u6210\uff0csave\u548cbgsave\u4f1a\u4ee5\u4e0d\u540c\u7684\u65b9\u5f0f\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\u3002<\/p>\n<h3>\u4e8c\u3001AOF\u6301\u4e45\u5316<\/h3>\n<p>AOF\uff0cAppend Only File\uff0c\u4ee5\u65e5\u5fd7\u7684\u65b9\u5f0f\u8bb0\u5f55\u6bcf\u4e00\u4e2a\u64cd\u4f5c\u547d\u4ee4\uff0c\u53ea\u8ffd\u52a0\u4e0d\u4fee\u6539\uff0cRedis\u542f\u52a8\u65f6\u4f1a\u8bfb\u53d6\u8be5\u6587\u4ef6\uff0c\u91cd\u65b0\u6267\u884c\u4e00\u904d\u4e4b\u524d\u7684\u5199\u64cd\u4f5c\u547d\u4ee4\uff0c\u8fbe\u5230\u6062\u590d\u6570\u636e\u7684\u6548\u679c\u3002<\/p>\n<p>\u9ed8\u8ba4\u4e0d\u5f00\u542f\uff0c\u9700\u8981\u66f4\u6539\u4e3aappendonly yes\uff0c\u5f00\u542fAOF\u5feb\u7167\u529f\u80fd\u3002<\/p>\n<h4>1\u3001AOF\u6301\u4e45\u5316\u8fc7\u7a0b<\/h4>\n<p>\uff081\uff09\u5728\u6267\u884cRedis\u547d\u4ee4\u65f6\uff0cRedis\u4f1a\u5c06\u8fd9\u4e9b\u547d\u4ee4\u653e\u5165AOF\u7f13\u5b58\u4e2d\uff0cAOF\u7f13\u5b58\u662f\u4f4d\u4e8e\u5185\u5b58\u4e2d\u7684\u4e00\u4e2a\u533a\u57df\uff0cAOF\u7f13\u5b58\u4e2d\u7684\u547d\u4ee4\u8fbe\u5230\u4e00\u5b9a\u6570\u91cf\u540e\uff0c\u6279\u91cf\u5199\u5165\u78c1\u76d8\uff0c\u907f\u514d\u9891\u7e41\u7684\u78c1\u76d8IO\u64cd\u4f5c\u3002<\/p>\n<p>\uff082\uff09\u6839\u636eAOF\u7f13\u51b2\u533a\u540c\u6b65\u6587\u4ef6\u7684\u4e09\u79cd\u5199\u56de\u7b56\u7565\uff0c\u5c06\u547d\u4ee4\u5199\u5230\u78c1\u76d8\u7684AOF\u6587\u4ef6\u4e2d\u3002<\/p>\n<p>\uff083\uff09\u968f\u7740\u5199\u5165AOF\u5185\u5bb9\u7684\u589e\u52a0\uff0c\u4f1a\u6839\u636e\u89c4\u5219\u8fdb\u884c\u547d\u4ee4\u7684\u5408\u5e76\uff0c\u8d77\u5230\u538b\u7f29AOF\u6587\u4ef6\u7684\u6548\u679c\u3002<\/p>\n<p>\uff084\uff09\u5f53Redis\u91cd\u542f\u65f6\uff0c\u4f1a\u6839\u636eAOF\u6587\u4ef6\uff0c\u4f9d\u6b64\u6267\u884c\u547d\u4ee4\uff0c\u6062\u590d\u5185\u5b58\u6570\u636e\u3002<\/p>\n<p>\u5f88\u591a\u4eba\u4f1a\u95ee\uff0c\u5982\u679c\u52a0\u5165\u5230AOF\u7f13\u5b58\u7684\u6570\u636e\u8fd8\u6ca1\u5199\u5165\u78c1\u76d8\uff0c\u6b64\u65f6\u670d\u52a1\u5668\u5b95\u673a\u4e86\uff0c\u6570\u636e\u4e0d\u4f1a\u4ea7\u751f\u4e22\u5931\u5417\uff1f<\/p>\n<p>\u7cfb\u7edf\u63d0\u4f9b\u4e86fsync\u548cfdatasync\u4e24\u4e2a\u540c\u6b65\u51fd\u6570\uff0c\u4ed6\u4eec\u53ef\u4ee5\u5f3a\u5236\u64cd\u4f5c\u7cfb\u7edf\u7acb\u5373\u5c06\u7f13\u5b58\u533a\u4e2d\u7684\u6570\u636e\u5199\u5165\u5230\u78c1\u76d8\u91cc\uff0c\u786e\u4fdd\u5199\u5165\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002<\/p>\n<h4>2\u3001appendfsync\u7684\u9009\u9879\u503c<\/h4>\n<p>\uff081\uff09<strong>Always<\/strong>\uff0c\u540c\u6b65\u5199\u56de\uff0c\u6bcf\u4e2a\u5199\u547d\u4ee4\u6267\u884c\u5b8c\u7acb\u523b\u540c\u6b65\u5230\u78c1\u76d8\uff1b\u6700\u591a\u53ea\u4f1a\u4e22\u5931\u4e00\u4e2a\u547d\u4ee4\u7684\u6570\u636e\uff0c\u6700\u5b89\u5168\uff0c\u4f46\u662f\u6548\u7387\u6700\u4f4e\u3002<\/p>\n<p>\uff082\uff09<strong>everysec<\/strong>\uff0c\u6bcf\u79d2\u5199\u56de\uff1b\u5b83\u6700\u591a\u4e22\u59311\u79d2\u7684\u6570\u636e\u3002<\/p>\n<p>\uff083\uff09<strong>no<\/strong>\uff0c\u64cd\u4f5c\u7cfb\u7edf\u63a7\u5236\u7684\u5199\u56de\uff0c\u6bcf\u4e2a\u547d\u4ee4\u6267\u884c\u5b8c\uff0c\u5b58\u5230AOF\u7f13\u5b58\u4e2d\uff0c\u7531\u64cd\u4f5c\u7cfb\u7edf\u51b3\u5b9a\uff0c\u5565\u65f6\u5019\u5c06\u547d\u4ee4\u5199\u5165\u5230\u78c1\u76d8AOF\u6587\u4ef6\u4e2d\u3002<\/p>\n<h4>3\u3001AOF\u6301\u4e45\u5316\u4f18\u7f3a\u70b9<\/h4>\n<p>\uff081\uff09\u4f18\u70b9<\/p>\n<p>\u66f4\u597d\u7684\u4fdd\u62a4\u6570\u636e\u4e0d\u4e22\u5931\uff0c\u6027\u80fd\u9ad8\uff0c\u53ef\u505a\u7d27\u6062\u590d\u3002<\/p>\n<p>\uff082\uff09\u7f3a\u70b9<\/p>\n<ol>\n<li>\n<p>\u7b49\u91cf\u7ea7\u7684\u547d\u4ee4\uff0cAOF\u6301\u4e45\u5316\u6587\u4ef6\u8981\u5927\u4e8eRDB\u6301\u4e45\u5316\u6587\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>\u6062\u590d\u901f\u5ea6\u6162\u4e8eRDB\uff1b<\/p>\n<\/li>\n<\/ol>\n<h4>4\u3001\u6570\u636e\u6062\u590d\u987a\u5e8f\u548c\u52a0\u8f7d\u6d41\u7a0b<\/h4>\n<p>\u5f53\u540c\u65f6\u5f00\u542fAOF\u548cRDB\u7684\u65f6\u5019\uff0c\u4f1a\u4f18\u5148\u52a0\u8f7dAOF\u6587\u4ef6\u6765\u6062\u590d\u6570\u636e\uff0c\u56e0\u4e3a\u901a\u5e38\u60c5\u51b5\u4e0bAOF\u6587\u4ef6\u6bd4RDB\u6587\u4ef6\u5907\u4efd\u7684\u6570\u636e\u8981\u5b8c\u6574\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230313\/1678670104640e79183b3bb.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<h3>\u4e09\u3001Redis\u4e8b\u52a1<\/h3>\n<h4>1\u3001Redis\u4e8b\u52a1\u662f\u4ec0\u4e48\uff1f<\/h4>\n<p>\u53ef\u4ee5\u4e00\u6b21\u6027\u987a\u5e8f\u6267\u884c\u591a\u4e2a\u547d\u4ee4\uff0c\u4e0d\u53ef\u88ab\u5176\u5b83\u547d\u4ee4\u63d2\u961f\uff0c\u4f46\u662f\uff0cRedis\u7684\u4e8b\u52a1\u4e0d\u80fd\u56de\u6eda\u3002<\/p>\n<h4>2\u3001Redis\u4e8b\u52a1\u5e38\u7528\u547d\u4ee4<\/h4>\n<p>\uff081\uff09<strong>discard<\/strong>\uff0c\u53d6\u6d88\u4e8b\u52a1\uff0c\u653e\u5f03\u6267\u884c\u4e8b\u52a1\u5185\u7684\u6240\u6709\u547d\u4ee4\u3002<\/p>\n<p>\uff082\uff09<strong>exec<\/strong>\uff0c\u6267\u884c\u6240\u6709\u547d\u4ee4\u3002<\/p>\n<p>\uff083\uff09<strong>multi<\/strong>\uff0c\u6807\u8bb0\u4e00\u4e2a\u4e8b\u52a1\u5757\u7684\u5f00\u59cb\u3002<\/p>\n<p>\uff084\uff09<strong>unwatch<\/strong>\uff0c\u53d6\u6d88watch\u547d\u4ee4\u5bf9\u6240\u6709key\u7684\u76d1\u89c6\u3002<\/p>\n<p>\uff085\uff09<strong>watch key<\/strong>\uff0c\u76d1\u89c6\u67d0\u4e2akey\uff0c\u5982\u679c\u8fd9\u4e2akey\u5728\u4e8b\u52a1\u6267\u884c\u4e4b\u524d\u88ab\u5176\u5b83\u547d\u4ee4\u6539\u52a8\uff0c\u90a3\u4e48\u4e8b\u52a1\u5c06\u88ab\u6253\u65ad\u3002<\/p>\n<h4>3\u3001\u4e8b\u52a1\u547d\u4ee4\u6267\u884c\u987a\u5e8f<\/h4>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230313\/1678670104640e79188b306.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<h4>4\u3001\u4e8b\u52a1\u7684ACID\u7279\u6027<\/h4>\n<p>\u5728Redis\u4e2d\uff0c\u4e8b\u52a1\u603b\u662f\u5177\u6709\u539f\u5b50\u6027\uff08Atomicity\uff09\u3001\u4e00\u81f4\u6027\uff08Consistency\uff09\u3001\u9694\u79bb\u6027\uff08Isolation\uff09\uff0c\u5e76\u4e14Redis\u8fd0\u884c\u5728\u67d0\u4e9b\u7279\u6b8a\u6a21\u5f0f\u4e0b\uff0c\u4e5f\u5177\u6709\u6301\u4e45\u6027\uff08Durability\uff09\u3002<\/p>\n<p><strong>\uff081\uff09\u539f\u5b50\u6027<\/strong><\/p>\n<p>\u4e8b\u52a1\u5177\u6709\u539f\u5b50\u6027\uff0c\u6307\u7684\u662f\u4e8b\u52a1\u4e2d\u7684\u591a\u4e2a\u64cd\u4f5c\u5f53\u505a\u4e00\u4e2a\u6574\u4f53\u6765\u6267\u884c\uff0c\u670d\u52a1\u5668\u8981\u4e48\u5c31\u6267\u884c\u4e8b\u52a1\u4e2d\u7684\u5168\u90e8\u64cd\u4f5c\uff0c\u8981\u4e48\u5c31\u4e00\u4e2a\u64cd\u4f5c\u4e5f\u4e0d\u6267\u884c\u3002<\/p>\n<p><strong>\uff082\uff09\u4e00\u81f4\u6027<\/strong><\/p>\n<p>\u5982\u679c\u6570\u636e\u5e93\u5728\u6267\u884c\u4e8b\u52a1\u4e4b\u524d\u662f\u4e00\u81f4\u7684\uff0c\u90a3\u4e48\u5728\u4e8b\u52a1\u6267\u884c\u4e4b\u540e\uff0c\u65e0\u8bba\u4e8b\u52a1\u6267\u884c\u662f\u5426\u6210\u529f\uff0c\u6570\u636e\u5e93\u4e5f\u5e94\u8be5\u662f\u4e00\u81f4\u7684\u3002<\/p>\n<p><strong>\uff083\uff09\u9694\u79bb\u6027<\/strong><\/p>\n<p>\u9694\u79bb\u6027\u6307\u5373\u4f7f\u6570\u636e\u5e93\u4e2d\u6709\u591a\u4e2a\u4e8b\u52a1\u5e76\u53d1\u5730\u6267\u884c\uff0c\u5404\u4e2a\u4e8b\u52a1\u4e4b\u95f4\u4e5f\u4e0d\u4f1a\u4e92\u76f8\u5f71\u54cd\uff0c\u5e76\u4e14\u5728\u5e76\u53d1\u72b6\u6001\u4e0b\u6267\u884c\u7684\u4e8b\u52a1\u548c\u4e32\u884c\u6267\u884c\u7684\u4e8b\u52a1\u4ea7\u751f\u7684\u7ed3\u679c\u5b8c\u5168\u76f8\u540c\u3002<\/p>\n<p><strong>\uff084\uff09\u6301\u4e45\u6027<\/strong><\/p>\n<p>\u5f53\u4e00\u4e2a\u4e8b\u52a1\u6267\u884c\u5b8c\u6bd5\u65f6\uff0c\u6267\u884c\u8fd9\u4e2a\u4e8b\u52a1\u6240\u5f97\u7684\u7ed3\u679c\u5df2\u7ecf\u88ab\u4fdd\u5b58\u5230\u786c\u76d8\u91cc\uff0c\u5373\u4f7f\u670d\u52a1\u5668\u6b64\u65f6\u5b95\u673a\uff0c\u6267\u884c\u4e8b\u52a1\u6240\u5f97\u7684\u7ed3\u679c\u4e5f\u4e0d\u4f1a\u4e22\u5931\u3002<\/p>\n<h3>\u56db\u3001Redis\u7ba1\u9053<\/h3>\n<h4>1\u3001Redis\u7ba1\u9053\u91ca\u4e49<\/h4>\n<p>Redis\u662f\u4e00\u79cd\u57fa\u4e8e\u5ba2\u6237\u7aef-\u670d\u52a1\u7aef\u6a21\u578b\u4ee5\u53ca\u8bf7\u6c42\u54cd\u5e94\u534f\u8bae\u7684TCP\u670d\u52a1\uff0c\u6bcf\u4e2a\u8bf7\u6c42\u4f1a\u9075\u5faa\u5982\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<p>\uff081\uff09\u5ba2\u6237\u7aef\u5411\u670d\u52a1\u7aef\u53d1\u9001\u547d\u4ee4\uff0c<span style=\"text-decoration:underline\">\u2460 \u53d1\u9001\u547d\u4ee4\uff1b\u2461 \u547d\u4ee4\u6392\u961f\uff1b\u2462 \u547d\u4ee4\u6267\u884c\uff1b\u2463 \u8fd4\u56de\u7ed3\u679c\uff0c\u76d1\u542cSocket\u8fd4\u56de\uff0c\u901a\u5e38\u4ee5\u963b\u585e\u6a21<\/span><\/p>\n<p>\uff082\uff09\u5f0f\u7b49\u5f85\u670d\u52a1\u7aef\u54cd\u5e94\u3002<\/p>\n<p>\u670d\u52a1\u7aef\u5904\u7406\u547d\u4ee4\uff0c\u5e76\u5c06\u7ed3\u679c\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<p>\u4e0a\u9762\u4e24\u6b65\u8d70\uff0c\u79f0\u4e3aRTT\uff0c\u6570\u636e\u5f80\u8fd4\u4e8e\u4e24\u7aef\u7684\u65f6\u95f4\uff0cRound Trip Time\u3002<\/p>\n<p>\u5982\u679c\u9700\u8981\u6267\u884c\u5927\u91cf\u547d\u4ee4\uff0c\u90a3\u4e48\u65b0\u7684\u547d\u4ee4\u8981\u7b49\u5f85\u4e0a\u4e00\u4e2a\u547d\u4ee4\u6267\u884c\u5b8c\u6bd5\u624d\u80fd\u6267\u884c\uff0c\u4f1a\u9891\u7e41\u7684\u8c03\u7528\u7cfb\u7edfIO\uff0c\u9891\u7e41\u53d1\u9001\u7f51\u7edc\u8bf7\u6c42\uff0c\u540c\u65f6\u9700\u8981Redis\u8c03\u7528\u591a\u6b21read()\u548cwrite()\u7cfb\u7edf\u65b9\u6cd5\uff0c\u7cfb\u7edf\u65b9\u6cd5\u4f1a\u5c06\u6570\u636e\u4ece\u7528\u6237\u6001\u8f6c\u79fb\u5230\u5185\u6838\u6001\uff0c\u6027\u80fd\u4e0d\u4f73\u3002<\/p>\n<h4>2\u3001\u6ce8\u610f\u4e8b\u9879<\/h4>\n<p>\uff081\uff09pipeline\u7f13\u5b58\u7684\u6307\u4ee4\u53ea\u4f1a\u4f9d\u6b64\u6267\u884c\uff0c\u4e0d\u4fdd\u8bc1\u539f\u5b50\u6027\uff0c\u5982\u679c\u6267\u884c\u4e2d\u53d1\u751f\u5f02\u5e38\uff0c\u4e5f\u4f1a\u7ee7\u7eed\u6267\u884c\u540e\u9762\u7684\u6307\u4ee4\u3002<\/p>\n<p>\uff082\uff09\u4f7f\u7528pipeline\u7ec4\u88c5\u7684\u547d\u4ee4\u4e2a\u6570\u4e0d\u80fd\u592a\u591a\uff0c\u4e0d\u7136\u53ef\u80fd\u4f1a\u9020\u6210\u963b\u585e\u65f6\u95f4\u8fc7\u957f\u7684\u73b0\u8c61\uff0c\u540c\u65f6\u670d\u52a1\u7aef\u4e5f\u4f1a\u88ab\u8feb\u56de\u590d\u4e00\u4e2a\u961f\u5217\u7b54\u590d\uff0c\u5360\u7528\u8fc7\u591a\u5185\u5b58\u3002<\/p>\n<h4>3\u3001\u4ee3\u7801\u5b9e\u6218<\/h4>\n<p>\u7f16\u5199\u4e00\u4e2a\u547d\u4ee4\u811a\u672c\uff0c\u6dfb\u52a0\u51e0\u4e2a\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002<\/p>\n<p>\u901a\u8fc7&nbsp;cat run.txt | redis-cli -a 111111 &#8211;pipe&nbsp;\u547d\u4ee4\uff0c\u4f53\u9a8cRedis\u7ba1\u9053\u6548\u679c\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230313\/1678670104640e7918caf4b.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p>Redis\u7ba1\u9053<\/p>\n<p>\u672c\u6587\u8f6c\u8f7d\u81ea\u5fae\u4fe1\u516c\u4f17\u53f7\u300c\u54ea\u5412\u7f16\u7a0b\u300d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4e8c\u7ef4\u7801\u5173\u6ce8\u3002\u8f6c\u8f7d\u672c\u6587\u8bf7\u8054\u7cfb\u54ea\u5412\u7f16\u7a0b\u516c\u4f17\u53f7\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230313\/1678670105640e791918703.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u804a\u804aRedis\u7684\u6301\u4e45\u5316\u3001RDB\u5feb&#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-201659","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201659","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=201659"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201659\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}