{"id":1797,"date":"2023-06-19T18:08:09","date_gmt":"2023-06-19T10:08:09","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=1797"},"modified":"2023-06-19T18:08:09","modified_gmt":"2023-06-19T10:08:09","slug":"%e5%b8%b8%e8%a7%81%e7%9a%84%e5%88%86%e5%b8%83%e5%bc%8f%e9%94%81%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/uncategorized\/%e5%b8%b8%e8%a7%81%e7%9a%84%e5%88%86%e5%b8%83%e5%bc%8f%e9%94%81%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88\/","title":{"rendered":"\u5e38\u89c1\u7684\u5206\u5e03\u5f0f\u9501\u89e3\u51b3\u65b9\u6848"},"content":{"rendered":"<div class='wxsyncmain'>\n<blockquote class=\"js_blockquote_wrap\" data-type=\"2\" data-url=\"\" data-author-name=\"\" data-content-utf8-length=\"24\" data-source-title=\"\">\n<section class=\"js_blockquote_digest\">\n<p>\u6587\u4e2d\u7684\u4ee3\u7801\u4e0d\u5b8c\u6574\uff0c\u53ea\u662f\u4e2a\u5927\u6982\uff0c\u505a\u4e2a\u4e86\u89e3\u5c31\u53ef\u4ee5\u4e86\uff01<\/p>\n<\/section>\n<\/blockquote>\n<p>&nbsp; &nbsp;<br  \/><\/p>\n<p>\u5206\u5e03\u5f0f\u9501\u5728\u6211\u4eec\u7684\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u662f\u5341\u5206\u5e38\u89c1\u7684\u6280\u672f\uff0c\u901a\u8fc7\u6765\u8bf4\u6211\u4eec\u4f1a\u91c7\u7528mysql\u3001redis\u3001zk\u7b49\u624b\u6bb5\u53bb\u505a\u5206\u5e03\u5f0f\u9501\uff0c\u672c\u6b21\u4e3b\u8981\u4ecb\u7ecdmysql\u548credis\u5b9e\u73b0\u7684\u65b9\u5f0f\uff0c\u56e0\u4e3azk\u6211\u4e0d\u719f\u3002<\/p>\n<section class=\"mp_common_sticker_iframe_wrp\"><mp-common-sticker class=\"js_uneditable custom_select_card mp_common_sticker_iframe\" data-pluginname=\"emotion\" data-id=\"9f76c2eb756e5833c6933e6f7a3754d3\" data-type=\"0\" data-emoji_url=\"https:\/\/mmbiz.qpic.cn\/mmbiz_gif\/WjPTzsspasoN84Yiae1hsfSIyLuqAlnJtbx4iaia0Q3zGutR7NL68nrK5T08oLgV5qK54VsHeHryObhohicWPQgTSw\/0\" data-md5=\"9f76c2eb756e5833c6933e6f7a3754d3\" data-inserted=\"0\" data-weui-theme=\"light\" data-is_ban=\"0\" data-loading=\"0\"><\/mp-common-sticker><\/section>\n<h2 style=\"box-sizing: border-box;margin-top: 30px;margin-bottom: 15px;color: rgb(0, 0, 0);font-weight: bold;font-size: 22px;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\"><span style=\"box-sizing: border-box;\">mysql<\/span><span style=\"box-sizing: border-box;\"><\/span><\/h2>\n<p style=\"box-sizing: border-box;margin-bottom: 0px;font-size: 16px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;\u4f7f\u7528mysql\u505a\u5206\u5e03\u5f0f\u9501\u6709\u4ee5\u4e0b\u7684\u65b9\u5f0f\uff1a<\/p>\n<ol style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;font-size: 16px;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\" class=\"list-paddingleft-1\">\n<li style=\"box-sizing: border-box;\">\n<section style=\"box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u5efa\u7acb\u4e00\u5f20\u8868\u8bb0\u5f55\u5bf9\u5e94\u7684\u65b9\u6cd5\uff0c\u5e76\u4e14\u4f7f\u7528\u552f\u4e00\u7d22\u5f15<\/section>\n<\/li>\n<\/ol>\n<p style=\"box-sizing: border-box;margin-bottom: 0px;font-size: 16px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;\u5148\u8bd5\u56fe\u63d2\u5165\u8be5\u8868\u4e2d\uff0c\u5982\u679c\u80fd\u591f\u6267\u884c\u6210\u529f\u5219\u4ee3\u8868\u83b7\u53d6\u5230\u9501\uff0c\u6267\u884c\u5931\u8d25\u5219\u81ea\u65cb\u76f4\u81f3\u83b7\u53d6\u9501 \u903b\u8f91\u64cd\u4f5c\u5b8c\u6210\u4e4b\u540e\uff0c\u5220\u9664\u5bf9\u5e94\u7684\u6570\u636e<\/p>\n<ol start=\"2\" style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;font-size: 16px;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\" class=\"list-paddingleft-1\">\n<li style=\"box-sizing: border-box;\">\n<section style=\"box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u4f7f\u7528Mysql\u81ea\u5e26\u7684\u6392\u5b83\u9501 select for update\u8bed\u53e5<\/section>\n<\/li>\n<\/ol>\n<p style=\"box-sizing: border-box;margin-bottom: 0px;font-size: 16px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;\u540c\u6837\u9700\u8981\u4e00\u5f20\u8868\uff0c\u5e76\u4e14\u8868\u4e2d\u521d\u59cb\u5316\u9700\u8981\u9501\u7684\u8d44\u6e90 \u4f7f\u7528select xxx from table where xxx=xxx for update\u67e5\u8be2 \u5e76\u4e14\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4\uff0c\u907f\u514d\u957f\u65f6\u95f4\u6301\u6709\u9501 \u5982\u679c\u83b7\u53d6\u8d44\u6e90\u5219\u4ee3\u8868\u83b7\u53d6\u9501 \u65e0\u8bba\u662f\u5426\u6210\u529f\u83b7\u53d6\u5230\u9501\u90fd\u8981\u91ca\u653e\u6389\u8fde\u63a5<\/p>\n<pre style=\"box-sizing: border-box;font-size: 16px;font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;margin-top: 10px;margin-bottom: 10px;overflow: auto;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;color: rgb(0, 0, 0);text-align: left;background-color: rgb(255, 255, 255);\"><code style=\"box-sizing: border-box;font-size: 12px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);border-radius: 5px;\">&nbsp;<span style=\"box-sizing: border-box;color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\uff08\u8fd9\u91cc\u53ea\u662f\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5bf9\u4e8e\u4e0a\u8ff0\u65b9\u6848\u53ef\u4ee5\u8fdb\u884c\u4f18\u5316\uff0c\u5982\uff1a\u5e94\u7528\u4e3b\u4ece\u6570\u636e\u5e93\uff0c\u6570\u636e\u4e4b\u95f4\u53cc\u5411\u540c\u6b65\uff1b\u4e00\u65e6\u6302\u6389\u5feb\u901f\u5207\u6362\u5230\u5907\u5e93\u4e0a\uff1b\u505a\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\uff0c\u6bcf\u9694\u4e00\u5b9a\u65f6\u95f4\u628a\u6570\u636e\u5e93\u4e2d\u7684\u8d85\u65f6\u6570\u636e\u6e05\u7406\u4e00\u904d\uff1b<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u4f7f\u7528while\u5faa\u73af\uff0c\u76f4\u5230insert\u6210\u529f\u518d\u8fd4\u56de\u6210\u529f\uff1b\u8bb0\u5f55\u5f53\u524d\u83b7\u5f97\u9501\u7684\u673a\u5668\u7684\u4e3b\u673a\u4fe1\u606f\u548c\u7ebf\u7a0b\u4fe1\u606f\uff0c\u4e0b\u6b21\u518d\u83b7\u53d6\u9501\u7684\u65f6\u5019\u5148\u67e5\u8be2\u6570\u636e\u5e93<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u5982\u679c\u5f53\u524d\u673a\u5668\u7684\u4e3b\u673a\u4fe1\u606f\u548c\u7ebf\u7a0b\u4fe1\u606f\u5728\u6570\u636e\u5e93\u53ef\u4ee5\u67e5\u5230\u7684\u8bdd\uff0c\u76f4\u63a5\u628a\u9501\u5206\u914d\u7ed9\u4ed6\u5c31\u53ef\u4ee5\u4e86\uff0c\u5b9e\u73b0\u53ef\u91cd\u5165\u9501\uff09<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">@throws<\/span>&nbsp;InterruptedException<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(97, 174, 238);line-height: 26px;\">@RequestMapping<\/span>(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\/lock\"<\/span>)<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;line-height: 26px;\"><span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"box-sizing: border-box;color: rgb(97, 174, 238);line-height: 26px;\">lock<\/span><span style=\"box-sizing: border-box;line-height: 26px;\">()<\/span>&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;InterruptedException&nbsp;<\/span>{<br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;className&nbsp;=&nbsp;Thread.currentThread().getStackTrace()[<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">1<\/span>].getClassName();<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;methodName&nbsp;=&nbsp;Thread.currentThread().getStackTrace()[<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">1<\/span>].getMethodName();<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TestLock&nbsp;testLock&nbsp;=&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;TestLock();<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;testLock.setController(className);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;testLock.setMethod(methodName);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;testLock.setTime(<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;Date());<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">try<\/span>&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>&nbsp;(testLockMapper.insert(testLock)&nbsp;&gt;&nbsp;<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">0<\/span>)&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">10000<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;testLockMapper.deleteByCondition(className,&nbsp;methodName);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u91ca\u653e\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">else<\/span>&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u4e0d\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">catch<\/span>&nbsp;(Exception&nbsp;e)&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u4e0d\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u52a0\u4e86\u6392\u4ed6\u9501\u4e4b\u540e\uff0c\u52a0\u4e86for&nbsp;update&nbsp;\u7684sql&nbsp;\u5c06\u4f1a\u963b\u585e\uff0c\u62ff\u5230\u9501\u4e4b\u540e\u7ee7\u7eed\u6267\u884c<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u963b\u585e\u65f6\u95f4\u662f\u5426\u6709\u9650\u5236\uff1f&nbsp;\u8fd9\u4e2a\u6ca1\u6709\u4e00\u4e2a&nbsp;\u8d85\u65f6\u65f6\u95f4\uff0c\u8fc7\u4e86\u8d85\u65f6\u65f6\u95f4\u5c31\u81ea\u52a8\u91ca\u653e\u9501<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;preparedStatement.setQueryTimeout(200);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u521d\u6b65\u60f3\u6cd5\u662f\u8bbe\u7f6e\u4e00\u4e2a\u67e5\u8be2\u8d85\u65f6\u65f6\u95f4\uff0c\u4e2d\u65ad\u67e5\u8be2\uff0c\u67e5\u8be2\u4e0d\u5230\u5c31\u62ff\u4e0d\u5230\u9501\u5c31\u53ef\u4ee5\u6267\u884c\u5176\u4ed6\u7684\u903b\u8f91\uff0c\u5c31\u53ef\u4ee5\u4e0d\u7528\u4e00\u76f4\u963b\u585e\u3002<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u4f46\u662f\u4e0d\u751f\u6548\u3002<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">@throws<\/span>&nbsp;SQLException<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">@throws<\/span>&nbsp;InterruptedException<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(97, 174, 238);line-height: 26px;\">@RequestMapping<\/span>(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\/mysqlLock\"<\/span>)<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;line-height: 26px;\"><span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"box-sizing: border-box;color: rgb(97, 174, 238);line-height: 26px;\">mysqlLock<\/span><span style=\"box-sizing: border-box;line-height: 26px;\">()<\/span>&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;SQLException,&nbsp;InterruptedException&nbsp;<\/span>{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Connection&nbsp;connection&nbsp;=&nbsp;BeanUtils.source.getConnection();<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connection.setAutoCommit(<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">false<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">try<\/span>&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;sql&nbsp;=&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"select&nbsp;*&nbsp;from&nbsp;test_lock&nbsp;where&nbsp;controller&nbsp;=&nbsp;'lock'&nbsp;for&nbsp;update;\"<\/span>;<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PreparedStatement&nbsp;preparedStatement&nbsp;=&nbsp;connection.prepareStatement(sql);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;preparedStatement.setQueryTimeout(<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">200<\/span>);<br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u5f00\u59cb\u6267\u884csql\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">long<\/span>&nbsp;l&nbsp;=&nbsp;System.currentTimeMillis();<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ResultSet&nbsp;resultSet&nbsp;=&nbsp;preparedStatement.executeQuery();<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">long<\/span>&nbsp;l1&nbsp;=&nbsp;System.currentTimeMillis();<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(l1&nbsp;-&nbsp;l);<br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"sql\u6267\u884c\u5b8c\u6210\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>&nbsp;(resultSet.next())&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/\u4ee3\u8868\u83b7\u53d6\u5230\u9501<\/span><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">10000<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u5f00\u59cb\u6267\u884c\u4e1a\u52a1\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connection.commit();<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u91ca\u653e\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">return<\/span>;<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">else<\/span>&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u4e0d\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">catch<\/span>&nbsp;(Exception&nbsp;e)&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connection.commit();<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br style=\"box-sizing: border-box;\"  \/><\/code><\/pre>\n<h2 style=\"box-sizing: border-box;margin-top: 30px;margin-bottom: 15px;color: rgb(0, 0, 0);font-weight: bold;font-size: 22px;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\"><span style=\"box-sizing: border-box;\">redis\uff08\u6f14\u53d8\u8fc7\u7a0b\uff09<\/span><span style=\"box-sizing: border-box;\"><\/span><\/h2>\n<h2 style=\"box-sizing: border-box;margin-top: 30px;margin-bottom: 15px;color: rgb(0, 0, 0);font-weight: bold;font-size: 22px;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\"><span style=\"box-sizing: border-box;\">\u5e38\u89c4\u505a\u6cd5<\/span><span style=\"box-sizing: border-box;\"><\/span><\/h2>\n<p style=\"box-sizing: border-box;margin-bottom: 0px;font-size: 16px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;\u6211\u4eec\u901a\u5e38\u4f7f\u7528redis+lua\u6765\u505a\u4e00\u4e2a\u5206\u5e03\u5f0f\u9501\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u91c7\u7528\u8fd9\u79cd\u65b9\u6848\u6211\u4eec\u5e94\u8be5\u4e00\u6b65\u4e00\u6b65\u6765\u63a2\u8ba8\u4e00\u4e0b\u8fd9\u4e2a\u95ee\u9898<\/p>\n<ol style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;font-size: 16px;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\" class=\"list-paddingleft-1\">\n<li style=\"box-sizing: border-box;\">\n<section style=\"box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u901a\u5e38\u903b\u8f91\u6765\u8bf4\u6211\u4eec\u662f\u8fd9\u6837\u5904\u7406\u7684\uff0c\u9996\u5148\u5c06\u9700\u8981\u505a\u4e92\u65a5\u64cd\u4f5c\u7684\u8d44\u6e90\u8fdb\u884csetnx\u64cd\u4f5c\uff0c\u5982\u679c\u5df2\u7ecf\u5b58\u5728\u4e86\u8fd9\u4e2a\u952e\u5219\u4e0d\u8bbe\u7f6e\uff0c\u5c31\u4f1a\u8fd4\u56de0\uff0c\u8868\u793a\u5f53\u524d\u8d44\u6e90\u5df2\u7ecf\u88ab\u5176\u4ed6\u7ebf\u7a0b\u5360\u7528\uff0c\u5982\u679c\u8bbe\u7f6e\u6210\u529f\uff0c\u8fd4\u56de\u7684\u662f1\uff0c\u8868\u793a\u5f53\u524d\u7ebf\u7a0b\u83b7\u53d6\u4e86\u9501\u3002\u7136\u540e\u6267\u884c\u64cd\u4f5c\uff0c\u6267\u884c\u64cd\u4f5c\u5b8c\u6210\u4e4b\u540e\u518d\u5220\u9664key\u3002<\/section>\n<\/li>\n<li style=\"box-sizing: border-box;\">\n<section style=\"box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u5982\u679c\u6309\u7167\u4e0a\u9762\u505a\u6cd5\u7684\u8bdd\uff0c\u518d\u6267\u884c\u903b\u8f91\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\u53d1\u751f\u4e2d\u65ad\uff0ckey\u6ca1\u6709\u7ed9\u5220\u6389\uff0c\u90a3\u4e48\u4ea7\u751f\u6b7b\u9501\uff0c\u6240\u4ee5\u81ea\u7136\u800c\u7136\u6211\u4eec\u5c31\u4f1a\u60f3\u5230\uff0c\u7ed9key\u6dfb\u52a0\u8fc7\u671f\u65f6\u95f4\uff0c\u4e5f\u5c31\u4f1a\u81ea\u7136\u800c\u8a00\u7684\uff0c\u4f46\u662fsetnx\u4e0d\u80fd\u8bbe\u7f6ekey\u7684\u8fc7\u671f\u65f6\u95f4\uff0c\u6240\u4ee5\u6211\u4eec\u5c31\u4f1a\u60f3\u5230\uff0c\u5728setn\u64cd\u4f5c\u5b8c\u6210\u4e4b\u540e \u4f7f\u7528expire\u547d\u4ee4\u7ed9key\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\u3002<\/section>\n<\/li>\n<li style=\"box-sizing: border-box;\">\n<section style=\"box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u7b2c2\u70b9\u7684\u505a\u6cd5\u5982\u679c\u5728expire\u6267\u884c\u4e4b\u524d\u5c31\u4e2d\u65ad\u4e86\u7ebf\u7a0b\uff0c\u4f9d\u7136\u4f1a\u4ea7\u751f\u6b7b\u9501\uff0c\u90a3\u600e\u4e48\u529e\uff1f\u5176\u5b9e\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528set\u547d\u4ee4\uff0c\u5176\u4e2d\u6709\u4e2a\u65b9\u6cd5\u91cd\u8f7dSET key value [expiration EX seconds|PX milliseconds] [NX|XX]\uff0c\u8be5\u65b9\u6cd5\u91cd\u65b0\u65e2\u53ef\u4ee5\u5b9e\u73b0setnx\u7684\u6548\u679c\u4e5f\u53ef\u4ee5\u6dfb\u52a0\u8fc7\u671f\u65f6\u95f4<\/section>\n<\/li>\n<\/ol>\n<blockquote style=\"box-sizing: border-box;margin-top: 20px;margin-bottom: 20px;border-top: none;border-right: none;border-bottom: none;border-left-color: rgba(0, 0, 0, 0.4);font-size: 0.9em;overflow: auto;background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;\">\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;color: black;\" class=\"list-paddingleft-1\">\n<li style=\"box-sizing: border-box;\">\n<section style=\"box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">EX second\uff1a\u8bbe\u7f6e\u952e\u7684\u8fc7\u671f\u65f6\u95f4\u4e3a second \u79d2\u3002SET key value EX second \u6548\u679c\u7b49\u540c\u4e8e SETEX key second value\u3002<\/section>\n<\/li>\n<li style=\"box-sizing: border-box;\">\n<section style=\"box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">PX millisecond\uff1a\u8bbe\u7f6e\u952e\u7684\u8fc7\u671f\u65f6\u95f4\u4e3a\u6beb\u79d2\u3002SET key value PX millisecond \u6548\u679c\u7b49\u540c\u4e8e PSETEX key millisecond value\u3002<\/section>\n<\/li>\n<li style=\"box-sizing: border-box;\">\n<section style=\"box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">NX\uff1a\u53ea\u5728\u952e\u4e0d\u5b58\u5728\u65f6\uff0c\u624d\u5bf9\u952e\u8fdb\u884c\u8bbe\u7f6e\u64cd\u4f5c\u3002SET key value NX \u6548\u679c\u7b49\u540c\u4e8e SETNX key value\u3002<\/section>\n<\/li>\n<li style=\"box-sizing: border-box;\">\n<section style=\"box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">XX\uff1a\u53ea\u5728\u952e\u5df2\u7ecf\u5b58\u5728\u65f6\uff0c\u624d\u5bf9\u952e\u8fdb\u884c\u8bbe\u7f6e\u64cd\u4f5c<\/section>\n<\/li>\n<\/ul>\n<\/blockquote>\n<p style=\"box-sizing: border-box;font-size: 16px;font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;margin-top: 10px;margin-bottom: 10px;overflow: auto;color: rgb(0, 0, 0);text-align: left;background-color: rgb(255, 255, 255);\"><code style=\"box-sizing: border-box;font-size: 12px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;display: -webkit-box;border-radius: 0px;\"><br  \/><\/code><code style=\"box-sizing: border-box;font-size: 12px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;display: -webkit-box;border-radius: 0px;\"><span style=\"white-space:pre-wrap;color: rgb(0, 0, 0);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 15px;text-align: left;background-color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;\u6240\u4ee5\u6211<\/span><span style=\"white-space:pre-wrap;color: rgb(0, 0, 0);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 15px;text-align: left;background-color: rgb(255, 255, 255);\">\u4eec\u4f7f\u7528set key value ex ttl nx \u6765\u8bbe\u7f6e\u503c\u5e76\u4e14\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\uff0c\u5982\u679c\u8bbe\u7f6e\u6210\u529f\u5219\u8868\u793a\u83b7\u53d6\u5230<\/span><span style=\"white-space:pre-wrap;color: rgb(0, 0, 0);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 15px;text-align: left;background-color: rgb(255, 255, 255);\">\u9501\u3002<\/span><\/code><code style=\"box-sizing: border-box;font-size: 12px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;display: -webkit-box;border-radius: 0px;\"><span style=\"white-space:pre-wrap;color: rgb(0, 0, 0);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 15px;text-align: left;background-color: rgb(255, 255, 255);\"><br  \/><\/span><\/code><\/p>\n<ol start=\"4\" style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;font-size: 16px;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\" class=\"list-paddingleft-1\">\n<li style=\"box-sizing: border-box;\">\n<section style=\"box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u5230\u8fd9\u91cc\u662f\u5426\u5c31\u6ca1\u6709\u95ee\u9898\u4e86\u5462\uff1f\u5176\u5b9e\u4e0d\u7136 \uff0c\u867d\u7136\u6211\u4eec\u8bbe\u7f6e\u4e86\u8fc7\u671f\u65f6\u95f4\uff0c\u4f46\u662f\u6211\u4eec\u5ffd\u7565\u7684\u4e1a\u52a1\u903b\u8f91\u6267\u884c\u7684\u65f6\u95f4 \u4e0e \u8fc7\u671f\u65f6\u95f4\u7684 \u4e4b\u95f4\u7684\u5173\u7cfb\u4e0a\u9762\u8bbe\u7f6e\u7684\u9501\u7684\u8fc7\u671f\u65f6\u95f4\u662f 5s, \u5982\u679c\u6211\u4eec\u7ebf\u7a0bA\u4e1a\u52a1\u903b\u8f91\u64cd\u4f5c\u65f6\u95f4\u662f10s\uff0c 5s\u4e4b\u540e\uff0c\u9501\u8fc7\u671f\u4e86\u81ea\u52a8\u91ca\u653e\u5728 5s \u540e \u7ebf\u7a0bB\u5c31\u53ef\u4ee5\u62ff\u5230\u8fd9\u628a\u9501 \uff0c\u7ebf\u7a0bB\u7684\u4e1a\u52a1\u903b\u8f91\u64cd\u4f5c\u65f6\u95f4\u4e5f\u662f10s, \u7b49\u7edd\u5bf9\u65f6\u95f4\u5230\u4e86 10s \u65f6\u5019\uff0c\u7ebf\u7a0bA\u6267\u884cdel\u64cd\u4f5c\u65f6\u91ca\u653e\u9501\uff0c\u8fd9\u65f6\u5019 \u7ebf\u7a0bA \u91ca\u653e\u7684\u662f\u7ebf\u7a0bB\u7684\u9501\u3002<\/section>\n<\/li>\n<li style=\"box-sizing: border-box;\">\n<section style=\"box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u90a3\u4e48\u600e\u4e48\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff1f\u6211\u4eec\u53ef\u4ee5\u5c06\u662fkey\u7684\u503c\u8bbe\u7f6e\u6210\u5f53\u524d\u7ebf\u7a0b\u7684\u4fe1\u606f\uff0c\u6211\u4eec\u5220\u9664key\u4e4b\u524d\u5148\u5224\u65ad\u4e00\u4e0bkey\u7684\u503c\u662f\u4e0d\u662f\u5f53\u524d\u7ebf\u7a0b\uff0c\u4f46\u662f\u8fd9\u91cc\u67e5\u8be2\u548c\u5220\u9664\u4e0d\u662f\u539f\u5b50\u6027\uff0c\u4f9d\u7136\u4f1a\u6709\u95ee\u9898\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981lua\u811a\u672c\u53bb\u89e3\u51b3\u6211\u4eec\u7684\u539f\u5b50\u6027\u95ee\u9898\u3002\u5e76\u4e14\u6211\u4eec\u53ef\u4ee5\u5f00\u4e00\u4e2a\u5b50\u7ebf\u7a0b\u505a\u5b88\u62a4\u7ebf\u7a0b\uff0c\u5b9a\u65f6\u7684\u9694\u4e00\u6bb5\u65f6\u95f4\u53bb\u91cd\u7f6e\u8fc7\u671f\u65f6\u95f4\uff0c\u8fd9\u4e2a\u505a\u6cd5\u53eb\u505a\u9501\u7eed\u79df<\/section>\n<\/li>\n<\/ol>\n<p style=\"box-sizing: border-box;margin-bottom: 0px;font-size: 16px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;\u603b\u7ed3\u4e00\u4e0b\uff0c\u5206\u5e03\u5f0f\u9501\u6211\u4eec\u901a\u5e38\u4f7f\u7528set\u547d\u4ee4\u53bb\u8bbe\u7f6ekey\u548c\u8fc7\u671f\u65f6\u95f4\uff0c\u4f7f\u7528redis+lua\u53bb\u91ca\u653e\u9501\uff0c\u8fd8\u6709\u4e00\u79cd\u5b9e\u73b0\u662f\u57fa\u4e8esetnx,get,getset\u8fd9\u4e09\u4e2a\u547d\u4ee4\u7684\u53bb\u5b9e\u73b0\u7684\uff0c\u611f\u5174\u8da3\u53ef\u4ee5\u81ea\u5df1\u770b\u4e00\u4e0b\uff0c\u6838\u5fc3\u601d\u60f3\u5c31\u662f\u907f\u514d\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\uff0c\u76f4\u63a5\u5c06\u65f6\u95f4\u8bbe\u7f6e\u4e3avalue\u3002<\/p>\n<pre style=\"box-sizing: border-box;font-size: 16px;font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;margin-top: 10px;margin-bottom: 10px;overflow: auto;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;color: rgb(0, 0, 0);text-align: left;background-color: rgb(255, 255, 255);\"><code style=\"box-sizing: border-box;font-size: 12px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);border-radius: 5px;\">&nbsp;<span style=\"box-sizing: border-box;color: rgb(97, 174, 238);line-height: 26px;\">@RequestMapping<\/span>(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"redisLock\"<\/span>)<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;line-height: 26px;\"><span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"box-sizing: border-box;color: rgb(97, 174, 238);line-height: 26px;\">redisLock<\/span><span style=\"box-sizing: border-box;line-height: 26px;\">()<\/span>&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;InterruptedException&nbsp;<\/span>{<br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u65b9\u6cd5\u4e00\u5b58\u5728\u95ee\u9898\uff1a<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* 1\u3002\u5982\u679c\u5728setnx\u4e0e del \u64cd\u4f5c\u4e4b\u95f4&nbsp;\u7a0b\u5e8f\u5f02\u5e38\u6216\u7ec8\u7aef\uff0c\u5c06\u4f1a\u5bfc\u81f4\u8fd9\u628a&nbsp;?&nbsp;\u6c38\u8fdc\u90fd\u65e0\u6cd5\u91ca\u653e\uff0c\u5c06\u4f1a\u4ea7\u751f\u6b7b\u9501\u95ee\u9898\u3002<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/\u65b9\u6cd5\u4e00<\/span><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>&nbsp;(redisOperations.setnx(LOCK_IN_REDIS_PREFIX,&nbsp;VALUE_LOCK_IN_REDIS))&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/\u903b\u8f91\u64cd\u4f5c<\/span><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u5f00\u59cb\u6267\u884c\u4e1a\u52a1\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">5000<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u4e1a\u52a1\u6267\u884c\u7ed3\u675f\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redisOperations.del(LOCK_IN_REDIS_PREFIX);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u91ca\u653e\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">else<\/span>&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u4e0d\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u9488\u5bf9\u65b9\u6cd5\u4e00\u4ea7\u751f\u7684\u6b7b\u9501\u95ee\u9898\uff0c\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u8fc7\u671f\u65f6\u95f4\u6765\u5904\u7406\uff1a<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;1.\u901a\u8fc7expire\u6765\u4e3a\u8fd9\u4e2akey\u589e\u52a0\u8fc7\u671f\u65f6\u95f4<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">boolean<\/span>&nbsp;setnx&nbsp;=&nbsp;redisOperations.setnx(LOCK_IN_REDIS_PREFIX,&nbsp;VALUE_LOCK_IN_REDIS);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>&nbsp;(setnx)&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u5f00\u59cb\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redisOperations.expire(LOCK_IN_REDIS_PREFIX,&nbsp;<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">30000<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u8fc7\u671f\u65f6\u95f4\u8bbe\u7f6e\u5b8c\u6210\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u5f00\u59cb\u6267\u884c\u4e1a\u52a1\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">4000<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u4e1a\u52a1\u6267\u884c\u5b8c\u6210\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redisOperations.del(LOCK_IN_REDIS_PREFIX);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u91ca\u653e\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">else<\/span>&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u4e0d\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u4e0a\u9762\u8fd9\u79cd\u65b9\u6cd5\u8fd8\u662f\u4f1a\u6709\u95ee\u9898\u7684\uff0c\u56e0\u4e3a&nbsp;setnx\u548c&nbsp;expire&nbsp;\u6ca1\u6709\u539f\u5b50\u6027\uff0c\u6709\u53ef\u80fd\u6267\u884c\u4e86&nbsp;setnx\u540e\u9762&nbsp;\u7cfb\u7edf\u5f02\u5e38\u4e86\uff0c\u90a3\u4e48\u4f9d\u65e7\u8fd8\u662f\u4f1a\u4ea7\u751f\u6b7b\u9501\u7684\u73b0\u8c61<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u6240\u4ee5\u8fd9\u4e2a\u65f6\u95f4\u5c31\u8981\u7528\u66f4\u6362\u601d\u8def\uff0c\u8981\u4fdd\u8bc1expire\u548c\u5176\u4ed6\u7684\u64cd\u4f5c\u662f\u539f\u5b50\u6027\u7684<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;2.\u91c7\u7528redis\u7684set\u547d\u4ee4&nbsp;&nbsp;set\u547d\u4ee4\u652f\u6301\u5728\u83b7\u53d6\u9501\u7684\u540c\u65f6\u8bbe\u7f6ekey\u7684\u8fc7\u671f\u65f6\u95f4<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;set&nbsp;=&nbsp;redisOperations.set(LOCK_IN_REDIS_PREFIX,&nbsp;VALUE_LOCK_IN_REDIS,&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"NX\"<\/span>,&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"EX\"<\/span>,&nbsp;<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">5000<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>&nbsp;(!StringUtils.isEmpty(set)){<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u5f00\u59cb\u6267\u884c\u4e1a\u52a1\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">5000<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u4e1a\u52a1\u6267\u884c\u5b8c\u6210\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redisOperations.del(LOCK_IN_REDIS_PREFIX);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u9501\u91ca\u653e\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">else<\/span>&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u4e0d\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u5230\u8fd9\u91cc\u662f\u5426\u5c31\u6ca1\u6709\u95ee\u9898\u4e86\u5462\uff1f&nbsp;\u5176\u5b9e\u4e0d\u7136&nbsp;\uff0c\u5c31\u4e0a\u9762\u8fd9\u6bb5\u7a0b\u5e8f\u800c\u8a00<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u867d\u7136\u6211\u4eec\u8bbe\u7f6e\u4e86\u8fc7\u671f\u65f6\u95f4\uff0c\u4f46\u662f\u6211\u4eec\u5ffd\u7565\u7684\u4e1a\u52a1\u903b\u8f91\u6267\u884c\u7684\u65f6\u95f4&nbsp;\u4e0e&nbsp;\u8fc7\u671f\u65f6\u95f4\u7684&nbsp;\u4e4b\u95f4\u7684\u5173\u7cfb<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u4e0a\u9762\u8bbe\u7f6e\u7684?\u7684\u8fc7\u671f\u65f6\u95f4\u662f&nbsp;5s,&nbsp;&nbsp;\u5982\u679c\u6211\u4eec\u7ebf\u7a0bA\u4e1a\u52a1\u903b\u8f91\u64cd\u4f5c\u65f6\u95f4\u662f10s\uff0c&nbsp;5s\u4e4b\u540e\uff0c\u9501\u8fc7\u671f\u4e86\u81ea\u52a8\u91ca\u653e<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u5728&nbsp;5s&nbsp;\u540e&nbsp;\u7ebf\u7a0bB\u5c31\u53ef\u4ee5\u62ff\u5230\u8fd9\u628a\u9501&nbsp;\uff0c\u7ebf\u7a0bB\u7684\u4e1a\u52a1\u903b\u8f91\u64cd\u4f5c\u65f6\u95f4\u4e5f\u662f10s,&nbsp;&nbsp;\u7b49\u7edd\u5bf9\u65f6\u95f4\u5230\u4e86&nbsp;10s&nbsp;\u65f6\u5019\uff0c<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u7ebf\u7a0bA\u6267\u884cdel\u64cd\u4f5c\u65f6\u91ca\u653e\u9501\uff0c\u8fd9\u65f6\u5019&nbsp;\u7ebf\u7a0bA&nbsp;\u91ca\u653e\u7684\u662f\u7ebf\u7a0bB\u7684\u9501<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u4e0a\u9762\u7684\u95ee\u9898\u53ef\u4ee5\u8fd9\u6837\u6765\u89e3\u51b3\uff1a<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5c06\u5f53\u524d\u7ebf\u7a0b\u7684\u76f8\u5173\u4fe1\u606f\u8bbe\u7f6e\u6210\u503c\uff0c<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5220\u9664\u4e4b\u524d\u5148\u5224\u65ad\u4e00\u4e0bvalue\u91cc\u9762\u7684\u7ebf\u7a0b\u4fe1\u606f\u662f\u5426\u662f\u5f53\u524d\u7ebf\u7a0b\u7684\u503c<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u4f46\u662f\u8fd9\u6837get&nbsp;\u548c&nbsp;del&nbsp;\u4e0d\u5b58\u5728&nbsp;\u539f\u5b50\u6027&nbsp;\u53ef\u4ee5\u901a\u8fc7lua\u811a\u672c\u4fdd\u8bc1\u539f\u5b50\u6027<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;threadMsg&nbsp;=&nbsp;Thread.currentThread().getName();<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;sets&nbsp;=&nbsp;redisOperations.set(LOCK_IN_REDIS_PREFIX,&nbsp;threadMsg,&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"NX\"<\/span>,&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"EX\"<\/span>,&nbsp;<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">5000<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;script&nbsp;=&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"--KEYS[1]&nbsp;string&nbsp;\u9501\u7684keyn\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"--ARGV[1]&nbsp;string&nbsp;\u5f53\u524d\u7ebf\u7a0b\u7684valuen\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"n\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"local&nbsp;valid_thread&nbsp;=&nbsp;ARGV[1]&nbsp;n\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"local&nbsp;current_thread&nbsp;=&nbsp;redis.call(\"get\",KEYS[1])n\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"if&nbsp;n\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"valid_thread&nbsp;==&nbsp;current_threadn\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"thenn\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"redis.call(\"del\",KEYS[1])n\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"end\"<\/span>;<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>&nbsp;(!StringUtils.isEmpty(sets)){<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u5f00\u59cb\u6267\u884c\u4e1a\u52a1\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">5000<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u4e1a\u52a1\u6267\u884c\u5b8c\u6210\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redisOperations.eval(script,&nbsp;Collections.singletonList(LOCK_IN_REDIS_PREFIX),Collections.singletonList(VALUE_LOCK_IN_REDIS));<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u9501\u91ca\u653e\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">else<\/span>&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u4e0d\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u8fd8\u53ef\u4ee5\u901a\u8fc7\u9501\u7eed\u79df\u6765\u89e3\u51b3&nbsp;\u5728\u83b7\u53d6\u5f97\u5230\u9501\u7684\u7ebf\u7a0b\u4e2d\u5f00\u542f\u4e00\u4e2a\u5b88\u62a4\u7ebf\u7a0b\u6ca1\u9694\u51e0\u79d2\u7eed\u79df\u4e00\u6b21<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;localThreadMsg&nbsp;=&nbsp;Thread.currentThread().getName();<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;sets1&nbsp;=&nbsp;redisOperations.set(LOCK_IN_REDIS_PREFIX,&nbsp;threadMsg,&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"NX\"<\/span>,&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"EX\"<\/span>,&nbsp;<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">5000<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;script1&nbsp;=&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"--KEYS[1]&nbsp;string&nbsp;\u9501\u7684keyn\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"--ARGV[1]&nbsp;string&nbsp;\u5f53\u524d\u7ebf\u7a0b\u7684valuen\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"n\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"local&nbsp;valid_thread&nbsp;=&nbsp;ARGV[1]&nbsp;n\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"local&nbsp;current_thread&nbsp;=&nbsp;redis.call(\"get\",KEYS[1])n\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"if&nbsp;n\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"valid_thread&nbsp;==&nbsp;current_threadn\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"thenn\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"redis.call(\"del\",KEYS[1])n\"<\/span>&nbsp;+<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"end\"<\/span>;<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>&nbsp;(!StringUtils.isEmpty(sets)){<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u5f00\u59cb\u6267\u884c\u4e1a\u52a1\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread&nbsp;demon&nbsp;=&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;Thread(()-&gt;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">long<\/span>&nbsp;start&nbsp;=&nbsp;System.currentTimeMillis();<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">while<\/span>&nbsp;(System.currentTimeMillis()-start&nbsp;&gt;=&nbsp;<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">29000L<\/span>){<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redisOperations.expire(LOCK_IN_REDIS_PREFIX,<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">20<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start&nbsp;=&nbsp;System.currentTimeMillis();<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demon.run();<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(<span style=\"box-sizing: border-box;color: rgb(209, 154, 102);line-height: 26px;\">5000<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u4e1a\u52a1\u6267\u884c\u5b8c\u6210\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redisOperations.eval(script,&nbsp;Collections.singletonList(LOCK_IN_REDIS_PREFIX),Collections.singletonList(VALUE_LOCK_IN_REDIS));<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u9501\u91ca\u653e\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<span style=\"box-sizing: border-box;color: rgb(198, 120, 221);line-height: 26px;\">else<\/span>&nbsp;{<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span style=\"box-sizing: border-box;color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u4e0d\u5230\u9501\"<\/span>);<br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br style=\"box-sizing: border-box;\"  \/><br style=\"box-sizing: border-box;\"  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br style=\"box-sizing: border-box;\"  \/><\/code><\/pre>\n<p style=\"box-sizing: border-box;margin-bottom: 0px;font-size: 16px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;\u4e0a\u9762\u7684\u505a\u6cd5\u5f88\u597d\u89e3\u51b3\u7684\u5206\u5e03\u5f0f\u9501\u7684\u95ee\u9898\uff0c\u4f46\u662f\u6211\u4eec\u7684redis\u901a\u5e38\u90fd\u662f\u96c6\u7fa4\u5316\uff0c\u6211\u4eec\u8003\u8651\u4e00\u4e0b\u8fd9\u79cd\u60c5\u51b5 \u6211\u4eec\u77e5\u9053\u5728\u4e3b\u4ece\u67b6\u6784\u4e0bmaster\u8282\u70b9\u53ef\u4ee5\u8bfb\u5199\uff0cslave\u8282\u70b9\u53ea\u80fd\u8bfb\uff0cmaster\u901a\u8fc7\u6267\u884cbgsave()\u547d\u4ee4\u5f00\u542f\u5f02\u6b65\u7ebf\u7a0b\u5c06\u6570\u636e\u540c\u6b65\u7ed9slave\u5982\u679c\u5728\u8fd9\u4e2a\u540c\u6b65\u8fc7\u7a0b\uff0ckey\u8fd8\u6ca1\u6709\u6765\u5f97\u53ca\u540c\u6b65\u7ed9slave\u5c31\u53d1\u751f\u6545\u969c\uff0c\u8fd9\u4e2a\u65f6\u5019\u9501\u5c31\u4f1a\u4e22\u5931\u3002\u90a3\u4e48\u5bf9\u5e94\u8fd9\u79cd\u60c5\u51b5\uff0c\u6709\u4eba\u63d0\u51fa\u4e86RedLock\uff08\u7ea2\u9501\uff09\uff0c\u4ed6\u7684\u4e3b\u8981\u539f\u7406\u662f\u5728\u591a\u4e2aredis\u8282\u70b9\u4e2d\u5171\u4eab\u4e00\u4e2a\u9501\uff0c\u4f7f\u7528\u591a\u4e2a\u9501\u6765\u534f\u8c03\u4fee\u6539\u9501\u7684\u72b6\u6001\uff0c\u5177\u4f53\u7684\u7ec6\u8282\u53ef\u4ee5\u53bb\u767e\u5ea6\u4e00\u4e0b\u3002\u6211\u4eecredisson\u7684\u6846\u67b6\u63d0\u4f9b\u4e86\u5bf9redlock\u7684\u5b9e\u73b0\uff0c\u6211\u4eec\u76f4\u63a5\u5c31\u53ef\u4ee5\u7528redisson\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<h2 style=\"box-sizing: border-box;margin-top: 30px;margin-bottom: 15px;color: rgb(0, 0, 0);font-weight: bold;font-size: 22px;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\"><span style=\"box-sizing: border-box;\">redisson\u6846\u67b6<\/span><span style=\"box-sizing: border-box;\"><\/span><\/h2>\n<blockquote style=\"box-sizing: border-box;margin-top: 20px;margin-bottom: 20px;border-top: none;border-right: none;border-bottom: none;border-left-color: rgba(0, 0, 0, 0.4);font-size: 0.9em;overflow: auto;background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;\">\n<p style=\"box-sizing: border-box;font-size: 16px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;\">Redisson\u662f\u4e00\u4e2a\u67b6\u8bbe\u5728redis\u4e0a\u975e\u5e38\u4f18\u79c0\u7684\u5f00\u6e90\u6846\u67b6\uff0c\u63d0\u4f9b\u4e86\u4e00\u79cd\u57fa\u4e8e\u770b\u95e8\u72d7\u673a\u5236\u7684\u5206\u5e03\u5f0f\u9501\u6846\u67b6\u3002<\/p>\n<\/blockquote>\n<p style=\"box-sizing: border-box;margin-bottom: 0px;font-size: 16px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; redisson\u5728\u83b7\u53d6\u9501\u4e4b\u540e\uff0c\u4f1a\u7ef4\u62a4\u4e00\u4e2a\u770b\u95e8\u72d7\u7ebf\u7a0b\uff0c\u5728\u6bcf\u4e00\u4e2a\u9501\u8bbe\u7f6e\u7684\u8fc7\u671f\u65f6\u95f4\u76841\/3\u5904\uff0c\u5982\u679c\u7ebf\u7a0b\u8fd8\u6ca1\u6267\u884c\u5b8c\u4efb\u52a1\uff0c\u5219\u4e0d\u65ad\u5ef6\u957f\u9501\u7684\u6709\u6548\u671f\u3002\u770b\u95e8\u72d7\u7684\u68c0\u67e5\u9501\u8d85\u65f6\u65f6\u95f4\u9ed8\u8ba4\u662f30\u79d2\uff0c\u53ef\u4ee5\u901a\u8fc7 lockWactchdogTimeout \u53c2\u6570\u6765\u6539\u53d8\u3002<\/p>\n<p style=\"box-sizing: border-box;margin-bottom: 0px;font-size: 16px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;\u52a0\u9501\u7684\u65f6\u95f4\u9ed8\u8ba4\u662f30\u79d2\uff0c\u5982\u679c\u52a0\u9501\u7684\u4e1a\u52a1\u6ca1\u6709\u6267\u884c\u5b8c\uff0c\u90a3\u4e48\u6bcf\u9694 30 \u00f7 3 = 10\u79d2\uff0c\u5c31\u4f1a\u8fdb\u884c\u4e00\u6b21\u7eed\u671f\uff0c\u628a\u9501\u91cd\u7f6e\u621030\u79d2\uff0c\u4fdd\u8bc1\u89e3\u9501\u524d\u9501\u4e0d\u4f1a\u81ea\u52a8\u5931\u6548\u3002<\/p>\n<p style=\"box-sizing: border-box;margin-bottom: 0px;font-size: 16px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;\u7ebf\u7a0b\u53bb\u83b7\u53d6\u9501\uff0c\u83b7\u53d6\u6210\u529f\uff1a\u6267\u884clua\u811a\u672c\uff0c\u4fdd\u5b58\u6570\u636e\u5230redis\u6570\u636e\u5e93\u3002<br  \/><\/p>\n<p style=\"box-sizing: border-box;margin-bottom: 0px;font-size: 16px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;\u7ebf\u7a0b\u53bb\u83b7\u53d6\u9501\uff0c\u83b7\u53d6\u5931\u8d25\uff1a\u4e00\u76f4\u901a\u8fc7while\u5faa\u73af\u5c1d\u8bd5\u83b7\u53d6\u9501\uff0c\u83b7\u53d6\u6210\u529f\u540e\uff0c\u6267\u884clua\u811a\u672c\uff0c\u4fdd\u5b58\u6570\u636e\u5230redis\u6570\u636e\u5e93\u3002<\/p>\n<p style=\"box-sizing: border-box;margin-bottom: 0px;font-size: 16px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\"><span style=\"font-size: 24px;font-weight: bold;letter-spacing: 0.544px;\"><br  \/><\/span><\/p>\n<p style=\"box-sizing: border-box;margin-bottom: 0px;font-size: 16px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);\"><span style=\"font-size: 24px;font-weight: bold;letter-spacing: 0.544px;\">\u6700<\/span><span style=\"font-size: 24px;font-weight: bold;letter-spacing: 0.544px;\">\u540e<\/span><br  \/><\/p>\n<p><span style=\"outline: 0px;max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;\">&nbsp;&nbsp;&nbsp;&nbsp;\u60f3\u8bf4\u7684\u5f88\u591a\uff0c\u665a\u70b9\u518d\u8bf4<br  \/><\/span><\/p>\n<p><br  \/><\/p>\n<p style=\"display: none;\"><mp-style-type data-value=\"3\"><\/mp-style-type><\/p>\n<blockquote>\n<p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7:                 Hephaestuses              <\/p>\n<\/blockquote>\n<\/div>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u6587\u4e2d\u7684\u4ee3\u7801\u4e0d\u5b8c\u6574\uff0c\u53ea\u662f\u4e2a\u5927\u6982\uff0c\u505a\u4e2a\u4e86\u89e3\u5c31\u53ef\u4ee5\u4e86\uff01 &nbsp; &nbsp; \u5206\u5e03\u5f0f\u9501\u5728\u6211\u4eec\u7684\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u662f\u5341\u5206\u5e38\u89c1\u7684\u6280\u672f\uff0c\u901a\u8fc7\u6765\u8bf4 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":1796,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-1797","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528045228324-150x150.jpeg","content_first_image":null,"post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528045228324-300x128.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528045228324.jpeg","post_frist_image":null,"post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528045228324-300x128.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528045228324.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528045228324.jpeg","post_all_images":[],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"\u672a\u5206\u7c7b","post_date":"2023-06-19","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":223,"next_post_id":2045,"next_post_title":"Hadoop \u96c6\u7fa4\u642d\u5efa","previous_post_id":1795,"previous_post_title":"\u5206\u5e03\u5f0f\u4e8b\u52a1\uff0c\u8fd9\u4e00\u7bc7\u5c31\u591f\u4e86","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/1797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1797"}],"version-history":[{"count":0,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/1797\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/1796"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}