{"id":238,"date":"2026-09-06T00:43:22","date_gmt":"2026-09-05T16:43:22","guid":{"rendered":"https:\/\/www.ziliaochi.cn\/index.php\/2026\/09\/06\/interview-high-concurrency-design\/"},"modified":"2026-09-06T00:43:22","modified_gmt":"2026-09-05T16:43:22","slug":"interview-high-concurrency-design","status":"publish","type":"post","link":"https:\/\/www.ziliaochi.cn\/index.php\/2026\/09\/06\/interview-high-concurrency-design\/","title":{"rendered":"\u9ad8\u5e76\u53d1\u7cfb\u7edf\u8bbe\u8ba1\u9762\u8bd5 25 \u95ee\uff1a\u9650\u6d41\u3001\u524a\u5cf0\u3001\u7194\u65ad\u4e0e\u4e00\u81f4\u6027\u54c8\u5e0c"},"content":{"rendered":"<div style=\"font-family:-apple-system,BlinkMacSystemFont,\"Segoe UI\",\"PingFang SC\",\"Hiragino Sans GB\",\"Microsoft YaHei\",sans-serif;font-size:16.5px;line-height:1.9;color:#35435c;letter-spacing:.2px\">\n<div style=\"background:linear-gradient(135deg,#f5f9ff,#eef5ff);border:1px solid #dce8f8;border-left:4px solid #d98324;border-radius:12px;padding:16px 20px;margin:0 0 24px;font-size:14.5px;color:#3d5570;line-height:2\"><span style=\"display:inline-block;background:#d98324;color:#fff;font-size:12.5px;font-weight:700;padding:3px 10px;border-radius:6px;margin-right:12px;letter-spacing:1px;vertical-align:1px\">\u5173\u952e\u8bcd<\/span>\u9ad8\u5e76\u53d1\u9762\u8bd5\u3001\u9650\u6d41\u7b97\u6cd5\u3001\u7194\u65ad\u964d\u7ea7\u3001\u7f13\u5b58\u96ea\u5d29\u3001\u4e00\u81f4\u6027\u54c8\u5e0c\u3001\u7cfb\u7edf\u8bbe\u8ba1<\/div>\n<div style=\"background:#fafbfd;border:1px solid #e8edf5;border-radius:12px;padding:18px 22px;margin:0 0 30px\">\n<div style=\"font-size:13.5px;font-weight:700;color:#8a99ae;letter-spacing:2px;margin-bottom:12px\">\u76ee\u5f55<\/div>\n<ol style=\"margin:0;padding-left:20px\">\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-1\" style=\"color:#42546e;text-decoration:none;border:none\">\u4e00\u3001\u5148\u5efa\u7acb\u4e00\u4e2a\u6b63\u786e\u7684\u5206\u5c42\u6a21\u578b<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-2\" style=\"color:#42546e;text-decoration:none;border:none\">\u4e8c\u3001\u9650\u6d41\uff1a\u4e09\u79cd\u7b97\u6cd5\u5fc5\u987b\u4f1a\u753b\u51fa\u6765<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-3\" style=\"color:#42546e;text-decoration:none;border:none\">\u4e09\u3001\u524a\u5cf0\uff1a\u628a\u5c16\u5cf0\u62c9\u6210\u5e73\u8c37<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-4\" style=\"color:#42546e;text-decoration:none;border:none\">\u56db\u3001\u7194\u65ad\u4e0e\u964d\u7ea7\uff1a\u4ec0\u4e48\u65f6\u5019\u8be5\u8ba4\u8f93<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-5\" style=\"color:#42546e;text-decoration:none;border:none\">\u4e94\u3001\u4e00\u81f4\u6027\u76f8\u5173\u7684\u9ad8\u9891\u8ffd\u95ee<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-6\" style=\"color:#42546e;text-decoration:none;border:none\">\u516d\u3001\u600e\u4e48\u628a\u8bbe\u8ba1\u9898\u7b54\u51fa\u5c42\u6b21<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-7\" style=\"color:#42546e;text-decoration:none;border:none\">\u4e03\u3001\u5c0f\u7ed3<\/a><\/li>\n<\/ol>\n<\/div>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\"><span style=\"font-size:17px;color:#1e2f47\">&#8220;\u8bbe\u8ba1\u4e00\u4e2a\u79d2\u6740\u7cfb\u7edf&#8221;&#8221;\u5982\u4f55\u652f\u6491\u767e\u4e07 QPS&#8221;\u8fd9\u7c7b\u9ad8\u5e76\u53d1\u9898\uff0c\u662f\u540e\u7aef\u9762\u8bd5\u91cc<strong style=\"color:#0f1c2e;font-weight:600\">\u6700\u5bb9\u6613\u88ab\u7b54\u6210\u4e00\u5806\u540d\u8bcd\u5806\u780c<\/strong>\u7684\u4e00\u5757\u3002\u9762\u8bd5\u5b98\u542c\u4f60\u5ff5&#8221;\u9650\u6d41\u3001\u964d\u7ea7\u3001\u7f13\u5b58\u3001MQ&#8221;\u7684\u65f6\u5019\uff0c\u5176\u5b9e\u5728\u7b49\u4f60\u56de\u7b54\u53e6\u4e00\u4ef6\u4e8b\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u4f60\u77e5\u9053\u6bcf\u4e00\u5c42\u6321\u4f4f\u7684\u662f\u4ec0\u4e48\uff0c\u4ee5\u53ca\u6321\u4e0d\u4f4f\u7684\u65f6\u5019\u4f1a\u53d1\u751f\u4ec0\u4e48\u3002<\/strong><\/p>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u672c\u6587\u6309<strong style=\"color:#0f1c2e;font-weight:600\">\u6d41\u91cf\u5206\u5c42\u6cbb\u7406<\/strong>\u7684\u601d\u8def\u7ec4\u7ec7\uff1a\u4ece\u5ba2\u6237\u7aef\u5230\u6570\u636e\u5e93\uff0c\u9010\u5c42\u8bb2\u6e05\u6bcf\u4e00\u5c42\u7684\u624b\u6bb5\u3001\u5931\u6548\u8fb9\u754c\u548c\u5e38\u89c1\u8ffd\u95ee\u3002<\/p>\n<figure style=\"margin:30px 0;text-align:center\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"900\" src=\"https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/interview-high-concurrency-design-fig.png\" alt=\"\u6d41\u91cf\u5206\u5c42\u6cbb\u7406\u6a21\u578b\" class=\"wp-image-237\" style=\"max-width:100%;height:auto;border-radius:12px;border:1px solid #e6ecf4;box-shadow:0 8px 24px rgba(15,30,60,.07)\" srcset=\"https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/interview-high-concurrency-design-fig.png 1200w, https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/interview-high-concurrency-design-fig-300x225.png 300w, https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/interview-high-concurrency-design-fig-1024x768.png 1024w, https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/interview-high-concurrency-design-fig-768x576.png 768w, https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/interview-high-concurrency-design-fig-800x600.png 800w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><figcaption style=\"margin-top:12px;font-size:13.5px;color:#7b8aa0;text-align:center;line-height:1.75\">\u9ad8\u5e76\u53d1\u4e94\u5c42\u6cbb\u7406\uff1a\u5ba2\u6237\u7aef \u2192 \u63a5\u5165\u5c42 \u2192 \u5e94\u7528\u5c42 \u2192 \u670d\u52a1\u5c42 \u2192 \u6570\u636e\u5c42<\/figcaption><\/figure>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #d98324;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-1\">\u4e00\u3001\u5148\u5efa\u7acb\u4e00\u4e2a\u6b63\u786e\u7684\u5206\u5c42\u6a21\u578b<\/h2>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u9ad8\u5e76\u53d1\u4e0d\u662f&#8221;\u52a0\u673a\u5668&#8221;\uff0c\u800c\u662f<strong style=\"color:#0f1c2e;font-weight:600\">\u628a\u5c3d\u53ef\u80fd\u591a\u7684\u8bf7\u6c42\u5728\u5c3d\u53ef\u80fd\u9760\u5916\u7684\u5c42\u6321\u6389\u6216\u6d88\u5316\u6389<\/strong>\u3002\u6807\u51c6\u7684\u5206\u5c42\u662f\uff1a<\/p>\n<ol style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u5ba2\u6237\u7aef\u5c42<\/strong>\uff1a\u6309\u94ae\u7f6e\u7070\u3001\u7b54\u9898\u3001\u672c\u5730\u9650\u6d41\u2014\u2014\u6321\u6389\u91cd\u590d\u63d0\u4ea4\u548c\u811a\u672c\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u63a5\u5165\u5c42\uff08CDN \/ \u7f51\u5173\uff09<\/strong>\uff1a\u9759\u6001\u8d44\u6e90\u5378\u8f7d\u3001WAF\u3001\u5168\u5c40\u9650\u6d41\u2014\u2014\u6321\u6389\u5927\u90e8\u5206\u65e0\u6548\u6d41\u91cf\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u5e94\u7528\u5c42<\/strong>\uff1a\u672c\u5730\u7f13\u5b58\u3001Token \u6821\u9a8c\u3001\u5e93\u5b58\u9884\u6263\u2014\u2014\u627f\u63a5\u771f\u6b63\u7684\u4e1a\u52a1\u8bf7\u6c42\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u670d\u52a1\u5c42<\/strong>\uff1a\u5206\u5e03\u5f0f\u7f13\u5b58\u3001\u5f02\u6b65\u5316\u3001\u7194\u65ad\u964d\u7ea7\u2014\u2014\u524a\u5cf0\u586b\u8c37\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u6570\u636e\u5c42<\/strong>\uff1a\u5206\u5e93\u5206\u8868\u3001\u8bfb\u5199\u5206\u79bb\u3001\u4e50\u89c2\u9501\u2014\u2014\u6700\u540e\u4e00\u9053\u9632\u7ebf\u3002<\/li>\n<\/ol>\n<blockquote style=\"margin:24px 0;padding:16px 22px;background:#f7fafd;border-left:4px solid #d98324;border-radius:0 10px 10px 0;color:#4a5b73;font-size:15.6px;line-height:1.88\">\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u9ad8\u5206\u5f00\u573a\u767d\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">&#8220;\u6211\u505a\u9ad8\u5e76\u8bbe\u8ba1\u7684\u7b2c\u4e00\u539f\u5219\u662f\uff1a\u8bf7\u6c42\u8d8a\u65e9\u88ab\u62d2\u7edd\uff0c\u4ee3\u4ef7\u8d8a\u5c0f\u3002&#8221;<\/strong>\u53ea\u8981\u8bf4\u51fa\u8fd9\u53e5\uff0c\u540e\u9762\u6240\u6709\u7684\u624b\u6bb5\u90fd\u6709\u4e86\u4e3b\u7ebf\u3002<\/p>\n<\/blockquote>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #d98324;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-2\">\u4e8c\u3001\u9650\u6d41\uff1a\u4e09\u79cd\u7b97\u6cd5\u5fc5\u987b\u4f1a\u753b\u51fa\u6765<\/h2>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #d9832440\">Q1\uff1a\u8ba1\u6570\u5668\u3001\u6ed1\u52a8\u7a97\u53e3\u3001\u4ee4\u724c\u6876\u3001\u6f0f\u6876\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/h3>\n<table style=\"width:100%;border-collapse:collapse;margin:24px 0;font-size:15px;border:1px solid #e3eaf3;border-radius:10px;overflow:hidden\">\n<thead>\n<tr>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\">\u7b97\u6cd5<\/th>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\">\u6838\u5fc3\u7ed3\u6784<\/th>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\">\u662f\u5426\u5e73\u6ed1<\/th>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\">\u80fd\u5426\u5e94\u5bf9\u7a81\u53d1<\/th>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\">\u5178\u578b\u843d\u5730<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u56fa\u5b9a\u7a97\u53e3\u8ba1\u6570<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u4e00\u4e2a\u8ba1\u6570\u5668 + \u65f6\u95f4\u7a97<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u5426<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u5426<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u7b80\u5355\u63a5\u53e3\u4fdd\u62a4<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u6ed1\u52a8\u7a97\u53e3<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u591a\u4e2a\u5c0f\u683c\u5b50\u7684\u8ba1\u6570<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u8f83\u5e73\u6ed1<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u6709\u9650<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">Sentinel \u9ed8\u8ba4<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u4ee4\u724c\u6876<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u5b9a\u901f\u751f\u6210\u4ee4\u724c + \u6876\u5bb9\u91cf<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u5e73\u6ed1\uff08\u9650\u5e73\u5747\u901f\u7387\uff09<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\"><strong style=\"color:#0f1c2e;font-weight:600\">\u80fd<\/strong>\uff08\u6876\u91cc\u6709\u5b58\u8d27\u5373\u53ef\u7a81\u53d1\uff09<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">Guava RateLimiter<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u6f0f\u6876<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u6052\u5b9a\u901f\u7387\u51fa\u6c34<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\"><strong style=\"color:#0f1c2e;font-weight:600\">\u5b8c\u5168\u5e73\u6ed1<\/strong><\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u4e0d\u80fd<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u6d41\u91cf\u6574\u5f62<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u5fc5\u8003\u8ffd\u95ee\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u56fa\u5b9a\u7a97\u53e3\u7684\u4e34\u754c\u95ee\u9898<\/strong>\u3002\u9650\u6d41 100 QPS\uff0c\u5982\u679c\u5728 0.9s \u65f6\u6765\u4e86 100 \u4e2a\u8bf7\u6c42\u30011.1s \u65f6\u53c8\u6765\u4e86 100 \u4e2a\uff0c\u4e24\u4e2a\u7a97\u53e3\u5404\u81ea\u90fd\u6ca1\u8d85\u9650\uff0c\u4f46<strong style=\"color:#0f1c2e;font-weight:600\">\u8fd9 0.2 \u79d2\u5185\u5b9e\u9645\u8fc7\u4e86 200 \u4e2a<\/strong>\u3002\u6ed1\u52a8\u7a97\u53e3\u5c31\u662f\u4e3a\u4e86\u89e3\u51b3\u5b83\u800c\u51fa\u73b0\u7684\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #d9832440\">Q2\uff1a\u5355\u673a\u9650\u6d41\u548c\u5206\u5e03\u5f0f\u9650\u6d41\u600e\u4e48\u9009\uff1f<\/h3>\n<pre style=\"background:#0f1a2b;color:#dbe6f5;border-radius:12px;padding:18px 20px;overflow-x:auto;font-size:13.6px;line-height:1.78;margin:22px 0;border:1px solid #1e2c42;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace\"><code style=\"background:none;border:none;color:inherit;padding:0;font-size:inherit;font-family:inherit\">\/\/ \u5355\u673a\uff1a\u4ee4\u724c\u6876\uff0c\u6027\u80fd\u597d\u3001\u65e0\u7f51\u7edc\u5f00\u9500\nRateLimiter limiter = RateLimiter.create(1000.0);   \/\/ Guava\nif (!limiter.tryAcquire()) return tooManyRequests();\n\n\/\/ \u5206\u5e03\u5f0f\uff1aRedis + Lua\uff08\u4fdd\u8bc1\u539f\u5b50\u6027\uff09\n\/\/ KEYS[1]=key, ARGV[1]=\u9650\u6d41\u9608\u503c, ARGV[2]=\u7a97\u53e3\u79d2\u6570\nlocal cur = redis.call('INCR', KEYS[1])\nif cur == 1 then redis.call('EXPIRE', KEYS[1], ARGV[2]) end\nreturn cur &gt; tonumber(ARGV[1]) and 0 or 1<\/code><\/pre>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u53d6\u820d\u8981\u70b9\uff1a<\/p>\n<ul style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u5355\u673a\u9650\u6d41<\/strong>\uff1a\u65e0\u7f51\u7edc\u5f00\u9500\u3001\u6027\u80fd\u597d\uff0c\u4f46\u673a\u5668\u6570\u91cf\u53d8\u5316\u65f6\u9700\u8981\u91cd\u65b0\u8ba1\u7b97\u9608\u503c\uff1b\u9002\u5408\u4fdd\u62a4<strong style=\"color:#0f1c2e;font-weight:600\">\u672c\u673a\u8d44\u6e90<\/strong>\uff08CPU\u3001\u8fde\u63a5\u6c60\uff09\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u5206\u5e03\u5f0f\u9650\u6d41<\/strong>\uff1a\u7cbe\u786e\u63a7\u5236\u5168\u5c40\u603b\u91cf\uff0c\u4f46\u6bcf\u6b21\u8bf7\u6c42\u90fd\u8981\u6253\u4e00\u6b21 Redis\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u672c\u8eab\u6210\u4e3a\u70ed\u70b9<\/strong>\uff1b\u9002\u5408\u4fdd\u62a4<strong style=\"color:#0f1c2e;font-weight:600\">\u4e0b\u6e38\u7a00\u7f3a\u8d44\u6e90<\/strong>\uff08\u6570\u636e\u5e93\u3001\u7b2c\u4e09\u65b9\u63a5\u53e3\uff09\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u5b9e\u8df5\u4e0a<strong style=\"color:#0f1c2e;font-weight:600\">\u4e24\u8005\u53e0\u52a0<\/strong>\uff1a\u7f51\u5173\u505a\u7c97\u7c92\u5ea6\u5206\u5e03\u5f0f\u9650\u6d41\uff0c\u5e94\u7528\u5185\u518d\u505a\u4e00\u5c42\u5355\u673a\u9650\u6d41\u515c\u5e95\u3002<\/li>\n<\/ul>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #d98324;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-3\">\u4e09\u3001\u524a\u5cf0\uff1a\u628a\u5c16\u5cf0\u62c9\u6210\u5e73\u8c37<\/h2>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #d9832440\">Q3\uff1a\u79d2\u6740\u573a\u666f\u4e3a\u4ec0\u4e48\u8981\u5f02\u6b65\u5316\uff1f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u540c\u6b65\u94fe\u8def\u7684\u95ee\u9898\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">100 \u4e07\u8bf7\u6c42\u76f4\u63a5\u6253\u5230\u6570\u636e\u5e93\uff0c\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u77ac\u95f4\u88ab\u6253\u6ee1\uff0c\u6b63\u5e38\u4e1a\u52a1\u4e5f\u8ddf\u7740\u6302<\/strong>\u3002\u5f02\u6b65\u5316\u7684\u672c\u8d28\u662f\u7528 MQ \u505a\u7f13\u51b2\u533a\uff0c\u628a&#8221;\u77ac\u65f6 100 \u4e07&#8221;\u53d8\u6210&#8221;\u5300\u901f\u6d88\u8d39 1 \u4e07\/\u79d2&#8221;\u3002<\/p>\n<pre style=\"background:#0f1a2b;color:#dbe6f5;border-radius:12px;padding:18px 20px;overflow-x:auto;font-size:13.6px;line-height:1.78;margin:22px 0;border:1px solid #1e2c42;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace\"><code style=\"background:none;border:none;color:inherit;padding:0;font-size:inherit;font-family:inherit\">\/\/ \u6807\u51c6\u79d2\u6740\u94fe\u8def\n\/\/ 1. Redis \u9884\u6263\u5e93\u5b58\uff08\u539f\u5b50\u64cd\u4f5c\uff0c\u6321\u6389 99% \u7684\u8bf7\u6c42\uff09\nLong remain = redis.eval(DECR_STOCK_LUA, keys, args);\nif (remain &lt; 0) return \"\u5df2\u552e\u7f44\";\n\n\/\/ 2. \u5199\u5165 MQ\uff0c\u7acb\u5373\u8fd4\u56de\"\u6392\u961f\u4e2d\"\nmq.send(new OrderCreatedEvent(userId, skuId));\n\n\/\/ 3. \u6d88\u8d39\u8005\u5300\u901f\u843d\u5e93\uff0c\u524d\u7aef\u8f6e\u8be2\u6216\u63a8\u9001\u7ed3\u679c\n\/\/    \u2192 \u6570\u636e\u5e93\u5b9e\u9645\u627f\u53d7\u7684\u662f\u6d88\u8d39\u901f\u7387\uff0c\u4e0d\u662f\u8bf7\u6c42\u901f\u7387<\/code><\/pre>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u8ffd\u95ee\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">MQ \u79ef\u538b\u4e86\u600e\u4e48\u529e\uff1f<\/strong>\u4e09\u4e2a\u5c42\u6b21\u2014\u2014\u2460 \u4e34\u65f6\u6269\u5bb9\u6d88\u8d39\u8005\uff1b\u2461 \u5982\u679c\u79ef\u538b\u5728\u4e1a\u52a1\u4f4e\u5cf0\u671f\u53ef\u4ee5\u6162\u6162\u6d88\u5316\uff0c\u5c31\u4e0d\u7528\u7ba1\uff1b\u2462 \u771f\u6b63\u5371\u9669\u7684\u662f<strong style=\"color:#0f1c2e;font-weight:600\">\u6d88\u606f\u5806\u79ef\u5bfc\u81f4\u78c1\u76d8\u5199\u6ee1\u6216 TTL \u8fc7\u671f\u4e22\u5931<\/strong>\uff0c\u6240\u4ee5\u8981\u8bbe\u79ef\u538b\u544a\u8b66 + \u6b7b\u4fe1\u961f\u5217\u515c\u5e95\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #d9832440\">Q4\uff1a\u7f13\u5b58\u4e09\u5927\u95ee\u9898\u7684\u6807\u51c6\u89e3\u6cd5<\/h3>\n<table style=\"width:100%;border-collapse:collapse;margin:24px 0;font-size:15px;border:1px solid #e3eaf3;border-radius:10px;overflow:hidden\">\n<thead>\n<tr>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\">\u95ee\u9898<\/th>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\">\u6210\u56e0<\/th>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\">\u89e3\u6cd5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u7f13\u5b58\u7a7f\u900f<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u67e5\u8be2\u6839\u672c\u4e0d\u5b58\u5728\u7684\u6570\u636e<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u7a7a\u503c\u7f13\u5b58\uff08\u77ed TTL\uff09+ \u5e03\u9686\u8fc7\u6ee4\u5668<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u7f13\u5b58\u51fb\u7a7f<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u5355\u4e2a\u70ed\u70b9 key \u8fc7\u671f\u77ac\u95f4\u5927\u91cf\u8bf7\u6c42\u6253\u5230 DB<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u4e92\u65a5\u9501\u91cd\u5efa \/ \u903b\u8f91\u8fc7\u671f\uff08\u6c38\u4e0d\u8fc7\u671f + \u540e\u53f0\u5237\u65b0\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u7f13\u5b58\u96ea\u5d29<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u5927\u6279 key \u540c\u65f6\u8fc7\u671f<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">TTL \u52a0\u968f\u673a\u6296\u52a8 + \u591a\u7ea7\u7f13\u5b58 + \u7194\u65ad<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre style=\"background:#0f1a2b;color:#dbe6f5;border-radius:12px;padding:18px 20px;overflow-x:auto;font-size:13.6px;line-height:1.78;margin:22px 0;border:1px solid #1e2c42;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace\"><code style=\"background:none;border:none;color:inherit;padding:0;font-size:inherit;font-family:inherit\">\/\/ \u903b\u8f91\u8fc7\u671f\u65b9\u6848\uff1avalue \u91cc\u5e26\u4e00\u4e2a\u903b\u8f91\u8fc7\u671f\u65f6\u95f4\uff0c\u7269\u7406\u4e0a\u6c38\u4e0d\u8fc7\u671f\nclass CacheItem {\n    Object data;\n    long   expireAt;   \/\/ \u903b\u8f91\u8fc7\u671f\u65f6\u95f4\n}\n\n\/\/ \u547d\u4e2d\u540e\u53d1\u73b0\u903b\u8f91\u8fc7\u671f\uff1a\u4e0d\u963b\u585e\uff0c\u5148\u8fd4\u56de\u65e7\u503c\uff0c\u53e6\u8d77\u7ebf\u7a0b\u91cd\u5efa\nif (item.expireAt &lt; now) {\n    executor.submit(() -&gt; rebuildWithLock(key));   \/\/ \u53ea\u653e\u4e00\u4e2a\u7ebf\u7a0b\u53bb\u91cd\u5efa\n    return item.data;    \/\/ \u5176\u4ed6\u7ebf\u7a0b\u7ee7\u7eed\u7528\u65e7\u6570\u636e\uff0c\u4e0d\u7b49\u5f85\n}<\/code><\/pre>\n<blockquote style=\"margin:24px 0;padding:16px 22px;background:#f7fafd;border-left:4px solid #d98324;border-radius:0 10px 10px 0;color:#4a5b73;font-size:15.6px;line-height:1.88\">\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u533a\u5206\u8981\u70b9\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u51fb\u7a7f\u662f&#8221;\u4e00\u4e2a key&#8221;\uff0c\u96ea\u5d29\u662f&#8221;\u4e00\u6279 key&#8221;\u3002<\/strong>\u9762\u8bd5\u5b98\u7ecf\u5e38\u6545\u610f\u6df7\u7740\u95ee\uff0c\u4f60\u4e3b\u52a8\u70b9\u51fa\u6765\u4f1a\u52a0\u5206\u3002<\/p>\n<\/blockquote>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #d98324;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-4\">\u56db\u3001\u7194\u65ad\u4e0e\u964d\u7ea7\uff1a\u4ec0\u4e48\u65f6\u5019\u8be5\u8ba4\u8f93<\/h2>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #d9832440\">Q5\uff1a\u7194\u65ad\u5668\u7684\u4e09\u79cd\u72b6\u6001\u600e\u4e48\u8f6c\u6362\uff1f<\/h3>\n<ol style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">Closed\uff08\u5173\u95ed\uff09<\/strong>\uff1a\u6b63\u5e38\u653e\u884c\uff0c\u7edf\u8ba1\u5931\u8d25\u7387\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">Open\uff08\u6253\u5f00\uff09<\/strong>\uff1a\u5931\u8d25\u7387\u8d85\u9608\u503c\u540e\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u76f4\u63a5\u5feb\u901f\u5931\u8d25<\/strong>\uff0c\u4e0d\u518d\u8c03\u7528\u4e0b\u6e38\u3002\u8fd9\u662f\u4e3a\u4e86\u8ba9\u4e0b\u6e38\u6709\u5598\u606f\u65f6\u95f4\u6062\u590d\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">Half-Open\uff08\u534a\u5f00\uff09<\/strong>\uff1a\u7194\u65ad\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u653e\u5c11\u91cf\u63a2\u6d4b\u8bf7\u6c42<\/strong>\uff1b\u6210\u529f\u5219\u56de\u5230 Closed\uff0c\u5931\u8d25\u5219\u56de\u5230 Open\u3002<\/li>\n<\/ol>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u5173\u952e\u8ba4\u77e5\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u7194\u65ad\u4fdd\u62a4\u7684\u662f\u4e0b\u6e38\uff0c\u964d\u7ea7\u4fdd\u62a4\u7684\u662f\u81ea\u5df1\u3002<\/strong>\u7194\u65ad\u662f&#8221;\u8c03\u7528\u65b9\u53d1\u73b0\u4e0b\u6e38\u4e0d\u884c\u4e86\uff0c\u5148\u522b\u6253\u4e86&#8221;\uff1b\u964d\u7ea7\u662f&#8221;\u6211\u81ea\u5df1\u625b\u4e0d\u4f4f\u4e86\uff0c\u628a\u975e\u6838\u5fc3\u529f\u80fd\u5173\u6389\u4fdd\u4f4f\u6838\u5fc3\u94fe\u8def&#8221;\u3002<\/p>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u964d\u7ea7\u5e38\u89c1\u624b\u6bb5\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u8fd4\u56de\u515c\u5e95\u6570\u636e\uff08\u9ed8\u8ba4\u503c\u3001\u7f13\u5b58\u65e7\u503c\uff09\u3001\u5173\u95ed\u975e\u6838\u5fc3\u529f\u80fd\uff08\u63a8\u8350\u3001\u8bc4\u8bba\u3001\u6392\u884c\u699c\uff09\u3001\u5f02\u6b65\u5316\u975e\u5fc5\u8981\u6b65\u9aa4\u3002<\/strong><\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #d9832440\">Q6\uff1a\u7194\u65ad\u548c\u9650\u6d41\u7684\u533a\u522b\uff1f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u4e00\u53e5\u8bdd\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u9650\u6d41\u662f&#8221;\u6211\u505a\u4e0d\u4e86\u8fd9\u4e48\u591a&#8221;\uff0c\u7194\u65ad\u662f&#8221;\u4e0b\u6e38\u4e0d\u884c\u4e86\uff0c\u6211\u522b\u7ed9\u5b83\u6dfb\u4e71&#8221;\u3002<\/strong>\u9650\u6d41\u53d1\u751f\u5728\u5165\u53e3\uff0c\u7194\u65ad\u53d1\u751f\u5728\u51fa\u53e3\uff1b\u9650\u6d41\u662f\u4e3b\u52a8\u7684\u5bb9\u91cf\u7ba1\u7406\uff0c\u7194\u65ad\u662f\u88ab\u52a8\u7684\u6545\u969c\u54cd\u5e94\u3002<\/p>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #d98324;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-5\">\u4e94\u3001\u4e00\u81f4\u6027\u76f8\u5173\u7684\u9ad8\u9891\u8ffd\u95ee<\/h2>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #d9832440\">Q7\uff1a\u4e00\u81f4\u6027\u54c8\u5e0c\u662f\u4ec0\u4e48\uff1f\u89e3\u51b3\u4e86\u4ec0\u4e48\u95ee\u9898\uff1f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u666e\u901a\u54c8\u5e0c\u53d6\u6a21\uff08<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">hash(key) % N<\/code>\uff09\u7684\u95ee\u9898\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u8282\u70b9\u6570 N \u53d8\u5316\u65f6\uff0c\u51e0\u4e4e\u6240\u6709 key \u7684\u6620\u5c04\u90fd\u4f1a\u6539\u53d8<\/strong>\u3002\u96c6\u7fa4\u4ece 3 \u53f0\u6269\u5230 4 \u53f0\uff0c\u7f13\u5b58\u547d\u4e2d\u7387\u4f1a\u76f4\u63a5\u5d29\u6389\uff0c\u5bfc\u81f4\u5927\u91cf\u8bf7\u6c42\u7a7f\u900f\u5230\u6570\u636e\u5e93\u3002<\/p>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u4e00\u81f4\u6027\u54c8\u5e0c\u628a\u8282\u70b9\u548c key \u90fd\u6620\u5c04\u5230\u4e00\u4e2a <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">0 ~ 2^32<\/code> \u7684\u54c8\u5e0c\u73af\u4e0a\uff0ckey \u987a\u65f6\u9488\u627e\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002<strong style=\"color:#0f1c2e;font-weight:600\">\u589e\u5220\u8282\u70b9\u65f6\u53ea\u5f71\u54cd\u73af\u4e0a\u76f8\u90bb\u7684\u4e00\u5c0f\u6bb5 key<\/strong>\uff0c\u5927\u90e8\u5206\u6620\u5c04\u4fdd\u6301\u4e0d\u53d8\u3002<\/p>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u8ffd\u95ee\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u8282\u70b9\u592a\u5c11\u5bfc\u81f4\u6570\u636e\u503e\u659c\u600e\u4e48\u529e\uff1f<\/strong>\u5f15\u5165<strong style=\"color:#0f1c2e;font-weight:600\">\u865a\u62df\u8282\u70b9<\/strong>\u2014\u2014\u4e00\u4e2a\u7269\u7406\u8282\u70b9\u5bf9\u5e94\u73af\u4e0a\u51e0\u767e\u4e2a\u865a\u62df\u8282\u70b9\uff0c\u8ba9\u5206\u5e03\u66f4\u5747\u5300\u3002\u8fd9\u662f\u6807\u51c6\u7b54\u6848\uff0c\u5fc5\u987b\u80fd\u8bf4\u51fa\u6765\u3002<\/p>\n<pre style=\"background:#0f1a2b;color:#dbe6f5;border-radius:12px;padding:18px 20px;overflow-x:auto;font-size:13.6px;line-height:1.78;margin:22px 0;border:1px solid #1e2c42;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace\"><code style=\"background:none;border:none;color:inherit;padding:0;font-size:inherit;font-family:inherit\">\/\/ \u865a\u62df\u8282\u70b9\u793a\u610f\nfor (int i = 0; i &lt; VIRTUAL_NODES; i++) {\n    String vnode = physicalNode + \"#\" + i;\n    ring.put(hash(vnode), physicalNode);   \/\/ TreeMap \u6709\u5e8f\u73af\n}\n\/\/ \u67e5\u627e\uff1atailMap(hash(key)) \u53d6\u7b2c\u4e00\u4e2a\uff0c\u6ca1\u6709\u5219\u56de\u5230\u73af\u9996<\/code><\/pre>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #d9832440\">Q8\uff1a\u5e93\u5b58\u6263\u51cf\u600e\u4e48\u9632\u8d85\u5356\uff1f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u4e09\u79cd\u65b9\u6848\uff0c\u6309\u5f3a\u5ea6\u548c\u4ee3\u4ef7\u9012\u8fdb\uff1a<\/p>\n<ol style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u6570\u636e\u5e93\u4e50\u89c2\u9501<\/strong>\uff1a<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">UPDATE stock SET num = num - 1 WHERE sku_id = ? AND num &gt; 0<\/code>\uff0c\u9760<strong style=\"color:#0f1c2e;font-weight:600\">\u5f71\u54cd\u884c\u6570<\/strong>\u5224\u65ad\u662f\u5426\u6210\u529f\u3002\u7b80\u5355\u53ef\u9760\uff0c\u4f46\u9ad8\u5e76\u53d1\u4e0b\u5927\u91cf\u5931\u8d25\u91cd\u8bd5\uff0c\u6570\u636e\u5e93\u538b\u529b\u5927\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">Redis \u539f\u5b50\u9884\u6263<\/strong>\uff1aLua \u811a\u672c\u4fdd\u8bc1&#8221;\u5224\u65ad + \u6263\u51cf&#8221;\u539f\u5b50\u6027\uff0c\u6321\u6389\u7edd\u5927\u90e8\u5206\u8bf7\u6c42\uff0c\u53ea\u6709\u771f\u6b63\u4e0b\u5355\u7684\u624d\u843d\u5e93\u3002<strong style=\"color:#0f1c2e;font-weight:600\">\u79d2\u6740\u573a\u666f\u7684\u6807\u51c6\u505a\u6cd5\u3002<\/strong><\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u5206\u6bb5\u5e93\u5b58<\/strong>\uff1a\u628a 1000 \u4ef6\u5e93\u5b58\u62c6\u6210 10 \u4e2a\u6bb5\u5404 100 \u4ef6\uff0c\u8bf7\u6c42\u968f\u673a\u843d\u5230\u67d0\u4e00\u6bb5\uff0c\u628a\u70ed\u70b9\u6253\u6563\u3002\u80fd\u663e\u8457\u63d0\u5347\u5e76\u53d1\u4e0a\u9650\uff0c\u4ee3\u4ef7\u662f\u53ef\u80fd\u51fa\u73b0&#8221;\u67d0\u6bb5\u5356\u5b8c\u4e86\u4f46\u603b\u91cf\u8fd8\u6709&#8221;\u7684\u60c5\u51b5\uff0c\u9700\u8981\u989d\u5916\u7684\u5f52\u5e76\u903b\u8f91\u3002<\/li>\n<\/ol>\n<blockquote style=\"margin:24px 0;padding:16px 22px;background:#f7fafd;border-left:4px solid #d98324;border-radius:0 10px 10px 0;color:#4a5b73;font-size:15.6px;line-height:1.88\">\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u5fc5\u8003\u9677\u9631\uff1a&#8221;<strong style=\"color:#0f1c2e;font-weight:600\">\u5148\u67e5\u518d\u6539\u4e3a\u4ec0\u4e48\u4e0d\u884c\uff1f<\/strong>&#8220;\u2014\u2014\u56e0\u4e3a <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">SELECT num<\/code> \u548c <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">UPDATE<\/code> \u662f\u4e24\u6761\u8bed\u53e5\uff0c\u5e76\u53d1\u4e0b\u4e24\u4e2a\u4e8b\u52a1\u53ef\u80fd\u540c\u65f6\u8bfb\u5230 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">num=1<\/code>\uff0c\u7136\u540e\u90fd\u5224\u65ad\u901a\u8fc7\u540e\u6263\u51cf\uff0c\u7ed3\u679c\u53d8\u6210 -1\u3002\u6838\u5fc3\u662f<strong style=\"color:#0f1c2e;font-weight:600\">\u5224\u65ad\u4e0e\u4fee\u6539\u5fc5\u987b\u5728\u540c\u4e00\u4e2a\u539f\u5b50\u64cd\u4f5c\u91cc\u5b8c\u6210<\/strong>\u3002<\/p>\n<\/blockquote>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #d9832440\">Q9\uff1a\u63a5\u53e3\u5e42\u7b49\u600e\u4e48\u4fdd\u8bc1\uff1f<\/h3>\n<ul style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u552f\u4e00\u7d22\u5f15<\/strong>\uff1a\u6700\u7b80\u5355\u53ef\u9760\u3002\u4e1a\u52a1\u4e0a\u7528\u4e00\u4e2a\u552f\u4e00\u952e\uff08\u8ba2\u5355\u53f7 + \u64cd\u4f5c\u7c7b\u578b\uff09\uff0c\u91cd\u590d\u63d2\u5165\u76f4\u63a5\u62a5\u9519\u6355\u83b7\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">Token \u673a\u5236<\/strong>\uff1a\u8fdb\u5165\u9875\u9762\u524d\u5148\u7533\u8bf7\u4e00\u4e2a token\uff0c\u63d0\u4ea4\u65f6\u5e26\u4e0a\uff0c\u670d\u52a1\u7aef\u6821\u9a8c\u540e\u5220\u9664\u3002<strong style=\"color:#0f1c2e;font-weight:600\">\u7528 Redis \u7684 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">DEL<\/code> \u8fd4\u56de\u503c\u5224\u65ad\u662f\u5426\u9996\u6b21<\/strong>\uff08\u539f\u5b50\u6027\uff09\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u72b6\u6001\u673a<\/strong>\uff1a\u66f4\u65b0\u65f6\u5e26\u4e0a\u524d\u7f6e\u72b6\u6001\uff0c<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">WHERE status = 'CREATED'<\/code>\uff0c\u53ea\u6709\u72b6\u6001\u5339\u914d\u624d\u66f4\u65b0\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u5206\u5e03\u5f0f\u9501<\/strong>\uff1a\u515c\u5e95\u624b\u6bb5\uff0c\u4ee3\u4ef7\u6700\u9ad8\uff0c\u614e\u7528\u3002<\/li>\n<\/ul>\n<pre style=\"background:#0f1a2b;color:#dbe6f5;border-radius:12px;padding:18px 20px;overflow-x:auto;font-size:13.6px;line-height:1.78;margin:22px 0;border:1px solid #1e2c42;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace\"><code style=\"background:none;border:none;color:inherit;padding:0;font-size:inherit;font-family:inherit\">\/\/ Token \u5e42\u7b49\uff1aDEL \u662f\u539f\u5b50\u7684\uff0c\u8fd4\u56de 1 \u8868\u793a\u9996\u6b21\u63d0\u4ea4\nLong deleted = redis.del(\"idempotent:\" + token);\nif (deleted == null || deleted == 0) {\n    return \"\u91cd\u590d\u63d0\u4ea4\";     \/\/ \u5df2\u88ab\u6d88\u8d39\u8fc7\n}\n\/\/ \u7ee7\u7eed\u5904\u7406\u4e1a\u52a1...<\/code><\/pre>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #d98324;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-6\">\u516d\u3001\u600e\u4e48\u628a\u8bbe\u8ba1\u9898\u7b54\u51fa\u5c42\u6b21<\/h2>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u7ed9\u4e00\u4e2a\u53ef\u4ee5\u76f4\u63a5\u5957\u7528\u7684\u7b54\u9898\u7ed3\u6784\uff1a<\/p>\n<ol style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u5148\u95ee\u6e05\u91cf\u7ea7<\/strong>\uff1a\u5cf0\u503c QPS \u591a\u5c11\uff1f\u8bfb\u591a\u5199\u5c11\u8fd8\u662f\u76f8\u53cd\uff1f\u4e00\u81f4\u6027\u8981\u6c42\u591a\u9ad8\uff1f<strong style=\"color:#0f1c2e;font-weight:600\">\u5f00\u53e3\u5c31\u4e0a Redis \u96c6\u7fa4\u662f\u51cf\u5206\u9879\u3002<\/strong><\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u7ed9\u51fa\u5206\u5c42\u67b6\u6784<\/strong>\uff1a\u4ece CDN \u5230\u6570\u636e\u5e93\uff0c\u753b\u51fa\u8bf7\u6c42\u6d41\u7ecf\u7684\u6bcf\u4e00\u5c42\uff0c\u6807\u6ce8\u6bcf\u5c42\u6321\u6389\u591a\u5c11\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u6293\u4f4f\u6838\u5fc3\u77db\u76fe<\/strong>\uff1a\u79d2\u6740\u7684\u6838\u5fc3\u662f&#8221;\u5e93\u5b58\u6263\u51cf\u7684\u539f\u5b50\u6027 + \u6d41\u91cf\u524a\u5cf0&#8221;\uff1bFeed \u6d41\u7684\u6838\u5fc3\u662f&#8221;\u8bfb\u5199\u653e\u5927\u4e0e\u6247\u51fa&#8221;\uff1b\u6392\u884c\u699c\u7684\u6838\u5fc3\u662f&#8221;\u5b9e\u65f6\u6027\u4e0e\u5199\u538b\u529b&#8221;\u3002<strong style=\"color:#0f1c2e;font-weight:600\">\u4e0d\u540c\u573a\u666f\u77db\u76fe\u4e0d\u540c\uff0c\u522b\u4e00\u5957\u65b9\u6848\u6253\u5929\u4e0b\u3002<\/strong><\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u4e3b\u52a8\u8bf4\u4ee3\u4ef7<\/strong>\uff1a\u6bcf\u4e2a\u65b9\u6848\u90fd\u6709\u526f\u4f5c\u7528\u2014\u2014\u5f02\u6b65\u5316\u5e26\u6765\u4e00\u81f4\u6027\u5ef6\u8fdf\uff0c\u7f13\u5b58\u5e26\u6765\u6570\u636e\u9648\u65e7\uff0c\u9650\u6d41\u5e26\u6765\u90e8\u5206\u7528\u6237\u5931\u8d25\u3002<strong style=\"color:#0f1c2e;font-weight:600\">\u80fd\u8bf4\u51fa&#8221;\u6211\u63a5\u53d7\u4ec0\u4e48\u4ee3\u4ef7&#8221;\u662f\u8d44\u6df1\u548c\u521d\u7ea7\u7684\u5206\u6c34\u5cad\u3002<\/strong><\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u8865\u4e0a\u53ef\u89c2\u6d4b<\/strong>\uff1a\u76d1\u63a7\u54ea\u4e9b\u6307\u6807\uff08QPS\u3001RT\u3001\u9519\u8bef\u7387\u3001\u7f13\u5b58\u547d\u4e2d\u7387\u3001MQ \u79ef\u538b\uff09\u3001\u544a\u8b66\u9608\u503c\u600e\u4e48\u5b9a\u3002<\/li>\n<\/ol>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #d98324;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-7\">\u4e03\u3001\u5c0f\u7ed3<\/h2>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u9ad8\u5e76\u53d1\u8bbe\u8ba1\u9898\u8003\u5bdf\u7684\u4e0d\u662f\u65b9\u6848\u80cc\u8bf5\uff0c\u800c\u662f<strong style=\"color:#0f1c2e;font-weight:600\">\u5206\u5c42\u6cbb\u7406\u7684\u601d\u7ef4\u65b9\u5f0f + \u5bf9\u6bcf\u4e2a\u624b\u6bb5\u5931\u6548\u8fb9\u754c\u7684\u8ba4\u77e5<\/strong>\u3002\u628a\u4e94\u5c42\u6a21\u578b\u8bb0\u4f4f\uff0c\u628a\u9650\u6d41\u56db\u7b97\u6cd5\u3001\u7f13\u5b58\u4e09\u95ee\u9898\u3001\u7194\u65ad\u4e09\u72b6\u6001\u3001\u5e42\u7b49\u56db\u65b9\u6848\u8bb2\u6e05\u695a\uff0c\u518d\u914d\u4e0a&#8221;\u8bf7\u6c42\u8d8a\u65e9\u88ab\u62d2\u7edd\u4ee3\u4ef7\u8d8a\u5c0f&#8221;\u8fd9\u6761\u4e3b\u7ebf\uff0c\u8fd9\u4e00\u5757\u5c31\u80fd\u7b54\u5f97\u6709\u7ed3\u6784\u3001\u6709\u53d6\u820d\u3002<\/p>\n<hr style=\"border:none;border-top:1px solid #eaeef4;margin:34px 0\">\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\"><em style=\"color:#5a6b85;font-style:normal;background:#d983241f;padding:1px 4px;border-radius:4px\">\u53c2\u8003\uff1a<a href=\"https:\/\/redis.io\/docs\/latest\/develop\/interact\/programmability\/\" target=\"_blank\" rel=\"noopener\" style=\"color:#d98324;text-decoration:none;border-bottom:1px solid #d9832466;transition:opacity .15s\">Redis Lua \u811a\u672c\u6587\u6863<\/a>\u3001<a href=\"https:\/\/sentinelguard.io\/zh-cn\/docs\/introduction\/\" target=\"_blank\" rel=\"noopener\" style=\"color:#d98324;text-decoration:none;border-bottom:1px solid #d9832466;transition:opacity .15s\">Sentinel \u5b98\u65b9\u6587\u6863<\/a>\u3001<a href=\"https:\/\/resilience4j.readme.io\/docs\" target=\"_blank\" rel=\"noopener\" style=\"color:#d98324;text-decoration:none;border-bottom:1px solid #d9832466;transition:opacity .15s\">Resilience4j \u6587\u6863<\/a>\u3002\u5b9e\u73b0\u7ec6\u8282\u8bf7\u4ee5\u6240\u7528\u7ec4\u4ef6\u7684\u6700\u65b0\u5b98\u65b9\u6587\u6863\u4e3a\u51c6\u3002<\/em><\/p>\n<div style=\"margin:42px 0 0;padding:22px 0 0;border-top:1px solid #eaeef4\">\n<div style=\"font-size:13px;color:#93a1b5;letter-spacing:1px;margin-bottom:12px\">\u6807\u7b7e<\/div>\n<p><span style=\"display:inline-block;background:#f3f6fa;border:1px solid #e4eaf2;color:#5b6c85;font-size:13px;padding:5px 12px;border-radius:999px;margin:0 8px 8px 0\">#\u540e\u7aef\u9762\u8bd5\u9898<\/span><span style=\"display:inline-block;background:#f3f6fa;border:1px solid #e4eaf2;color:#5b6c85;font-size:13px;padding:5px 12px;border-radius:999px;margin:0 8px 8px 0\">#\u9ad8\u5e76\u53d1<\/span><span style=\"display:inline-block;background:#f3f6fa;border:1px solid #e4eaf2;color:#5b6c85;font-size:13px;padding:5px 12px;border-radius:999px;margin:0 8px 8px 0\">#\u7cfb\u7edf\u8bbe\u8ba1<\/span><span style=\"display:inline-block;background:#f3f6fa;border:1px solid #e4eaf2;color:#5b6c85;font-size:13px;padding:5px 12px;border-radius:999px;margin:0 8px 8px 0\">#\u9762\u8bd5<\/span><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8bbe\u8ba1\u4e00\u4e2a\u79d2\u6740\u7cfb\u7edf\u8fd9\u7c7b\u9898\uff0c\u6700\u5bb9\u6613\u88ab\u7b54\u6210\u4e00\u5806\u540d\u8bcd\u5806\u780c\u3002\u672c\u6587\u6309\u6d41\u91cf\u5206\u5c42\u6cbb\u7406\u7684\u601d\u8def\u7ec4\u7ec7\uff1a\u4ece\u5ba2\u6237\u7aef\u5230\u6570\u636e\u5e93\uff0c\u9010\u5c42\u8bb2\u6e05\u6bcf\u4e00\u5c42\u7684\u624b\u6bb5\u3001\u5931\u6548\u8fb9\u754c\u548c\u5e38\u89c1\u8ffd\u95ee\uff0c\u5e76\u7ed9\u51fa\u4e00\u5957\u53ef\u4ee5\u76f4\u63a5\u5957\u7528\u7684\u7b54\u9898\u7ed3\u6784\u3002<\/p>\n","protected":false},"author":1,"featured_media":236,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,11],"tags":[69,116,66,115],"class_list":["post-238","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-backend-question-bank","category-question-bank","tag-69","tag-116","tag-66","tag-115"],"_links":{"self":[{"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/posts\/238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/comments?post=238"}],"version-history":[{"count":0,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/posts\/238\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/media\/236"}],"wp:attachment":[{"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/media?parent=238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/categories?post=238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/tags?post=238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}