{"id":2653,"date":"2023-07-05T11:16:54","date_gmt":"2023-07-05T03:16:54","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=2653"},"modified":"2023-07-05T14:02:27","modified_gmt":"2023-07-05T06:02:27","slug":"%e5%88%86%e5%b8%83%e5%bc%8f%e9%94%81%e5%b7%a5%e5%85%b7-redisson%ef%bc%8c%e5%a4%aa%e4%bc%98%e9%9b%85%ef%bc%81%ef%bc%81","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/redis\/%e5%88%86%e5%b8%83%e5%bc%8f%e9%94%81%e5%b7%a5%e5%85%b7-redisson%ef%bc%8c%e5%a4%aa%e4%bc%98%e9%9b%85%ef%bc%81%ef%bc%81\/","title":{"rendered":"\u5206\u5e03\u5f0f\u9501\u5de5\u5177 Redisson\uff0c\u592a\u4f18\u96c5\uff01\uff01"},"content":{"rendered":"<div class=\"wxsyncmain\">\n<h1 style=\"text-align: left;\" data-id=\"heading-0\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 10px; color: #b2b2b2;\"><span style=\"color: #b2b2b2; font-size: 10px; font-family: arial, helvetica, sans-serif; letter-spacing: 0.578px; text-align: left; text-wrap: wrap;\">\u4f5c\u8005\uff1a\u957f\u6c5f\u6c34\u9762\u5199\u65e5\u8bb0<\/span><br style=\"font-family: arial, helvetica, sans-serif; font-size: 16px; letter-spacing: 0.578px; text-align: left; text-wrap: wrap;\" \/><span style=\"color: #b2b2b2; font-size: 10px; font-family: arial, helvetica, sans-serif; letter-spacing: 0.578px; text-align: left; text-wrap: wrap;\">\u94fe\u63a5\uff1ahttps:\/\/juejin.cn\/post\/6961380552519712798<\/span><\/span><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-0\"><span style=\"font-size: 18px;\"><strong><span style=\"font-family: arial, helvetica, sans-serif; color: #df7766;\">\u4e00\u3001Redisson\u6982\u8ff0<\/span><\/strong><\/span><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-0\"><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-0\"><span style=\"letter-spacing: 0.034em; font-family: arial, helvetica, sans-serif;\">\u4ec0\u4e48\u662fRedisson\uff1f\u2014\u2014 <\/span><span style=\"letter-spacing: 0.034em; font-family: arial, helvetica, sans-serif;\">Redisson Wiki<\/span><\/h1>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">Redisson\u662f\u4e00\u4e2a\u5728Redis\u7684\u57fa\u7840\u4e0a\u5b9e\u73b0\u7684Java\u9a7b\u5185\u5b58\u6570\u636e\u7f51\u683c\uff08In-Memory Data Grid\uff09\u3002\u5b83\u4e0d\u4ec5\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684\u5206\u5e03\u5f0f\u7684Java\u5e38\u7528\u5bf9\u8c61\uff0c\u8fd8\u63d0\u4f9b\u4e86\u8bb8\u591a\u5206\u5e03\u5f0f\u670d\u52a1\u3002\u5176\u4e2d\u5305\u62ec(BitSet, Set, Multimap, SortedSet, Map, List, Queue, BlockingQueue, Deque, BlockingDeque, Semaphore, Lock, AtomicLong, CountDownLatch, Publish \/ Subscribe, Bloom filter, Remote service, Spring cache, Executor service, Live Object service, Scheduler service) Redisson\u63d0\u4f9b\u4e86\u4f7f\u7528Redis\u7684\u6700\u7b80\u5355\u548c\u6700\u4fbf\u6377\u7684\u65b9\u6cd5\u3002Redisson\u7684\u5b97\u65e8\u662f\u4fc3\u8fdb\u4f7f\u7528\u8005\u5bf9Redis\u7684\u5173\u6ce8\u5206\u79bb\uff08Separation of Concern\uff09\uff0c\u4ece\u800c\u8ba9\u4f7f\u7528\u8005\u80fd\u591f\u5c06\u7cbe\u529b\u66f4\u96c6\u4e2d\u5730\u653e\u5728\u5904\u7406\u4e1a\u52a1\u903b\u8f91\u4e0a\u3002<\/span><\/p>\n<\/blockquote>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u4e00\u4e2a\u57fa\u4e8eRedis\u5b9e\u73b0\u7684\u5206\u5e03\u5f0f\u5de5\u5177\uff0c\u6709\u57fa\u672c\u5206\u5e03\u5f0f\u5bf9\u8c61\u548c\u9ad8\u7ea7\u53c8\u62bd\u8c61\u7684\u5206\u5e03\u5f0f\u670d\u52a1\uff0c\u4e3a\u6bcf\u4e2a\u8bd5\u56fe\u518d\u9020\u5206\u5e03\u5f0f\u8f6e\u5b50\u7684\u7a0b\u5e8f\u5458\u5e26\u6765\u4e86\u5927\u90e8\u5206\u5206\u5e03\u5f0f\u95ee\u9898\u7684\u89e3\u51b3\u529e\u6cd5\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">Redisson\u548cJedis\u3001Lettuce\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u5012\u4e5f\u4e0d\u662f\u96f7\u950b\u548c\u96f7\u950b\u5854<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">Redisson\u548c\u5b83\u4fe9\u7684\u533a\u522b\u5c31\u50cf\u4e00\u4e2a\u7528\u9f20\u6807\u64cd\u4f5c\u56fe\u5f62\u5316\u754c\u9762\uff0c\u4e00\u4e2a\u7528\u547d\u4ee4\u884c\u64cd\u4f5c\u6587\u4ef6\u3002Redisson\u662f\u66f4\u9ad8\u5c42\u7684\u62bd\u8c61\uff0cJedis\u548cLettuce\u662fRedis\u547d\u4ee4\u7684\u5c01\u88c5\u3002<\/span><\/p>\n<ul class=\"list-paddingleft-1\">\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">Jedis\u662fRedis\u5b98\u65b9\u63a8\u51fa\u7684\u7528\u4e8e\u901a\u8fc7Java\u8fde\u63a5Redis\u5ba2\u6237\u7aef\u7684\u4e00\u4e2a\u5de5\u5177\u5305\uff0c\u63d0\u4f9b\u4e86Redis\u7684\u5404\u79cd\u547d\u4ee4\u652f\u6301<\/span><\/p>\n<\/li>\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">Lettuce\u662f\u4e00\u79cd\u53ef\u6269\u5c55\u7684\u7ebf\u7a0b\u5b89\u5168\u7684 Redis \u5ba2\u6237\u7aef\uff0c\u901a\u8baf\u6846\u67b6\u57fa\u4e8eNetty\uff0c\u652f\u6301\u9ad8\u7ea7\u7684 Redis \u7279\u6027\uff0c\u6bd4\u5982\u54e8\u5175\uff0c\u96c6\u7fa4\uff0c\u7ba1\u9053\uff0c\u81ea\u52a8\u91cd\u65b0\u8fde\u63a5\u548cRedis\u6570\u636e\u6a21\u578b\u3002Spring Boot 2.x \u5f00\u59cb Lettuce \u5df2\u53d6\u4ee3 Jedis \u6210\u4e3a\u9996\u9009 Redis \u7684\u5ba2\u6237\u7aef\u3002<\/span><\/p>\n<\/li>\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">Redisson\u662f\u67b6\u8bbe\u5728Redis\u57fa\u7840\u4e0a\uff0c\u901a\u8baf\u57fa\u4e8eNetty\u7684\u7efc\u5408\u7684\u3001\u65b0\u578b\u7684\u4e2d\u95f4\u4ef6\uff0c\u4f01\u4e1a\u7ea7\u5f00\u53d1\u4e2d\u4f7f\u7528Redis\u7684\u6700\u4f73\u8303\u672c<\/span><\/p>\n<\/li>\n<\/ul>\n<p style=\"outline: 0px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; white-space: normal; text-align: center; visibility: visible;\"><a style=\"outline: 0px; color: #0052ff; cursor: pointer; letter-spacing: 0.544px; font-size: 20px; visibility: visible; font-family: arial, helvetica, sans-serif;\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=Mzg5MzU1Nzc1Mw==&amp;mid=2247497266&amp;idx=1&amp;sn=0cbc4a257adbf7af3bdde782601e0b49&amp;chksm=c02fb8a4f75831b2484bc6e3f18423229a46caa0d11fea7aefc93dd89ba9418d7ebec649c009&amp;scene=21#wechat_redirect\" target=\"_blank\" rel=\"noopener\" data-itemshowtype=\"0\" data-linktype=\"2\" rel=\"nofollow\" ><span style=\"outline: 0px; visibility: visible;\"><strong style=\"outline: 0px; visibility: visible;\">\u4e13\u5c5e\u798f\u5229<\/strong><\/span><\/a><\/p>\n<p style=\"outline: 0px; letter-spacing: 0.544px; white-space: normal; font-family: system-ui, -apple-system, system-ui, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; text-align: center; line-height: normal; visibility: visible;\"><a class=\"wx_tap_link\" style=\"outline: 0px; color: #ff0000; cursor: pointer; background-color: #00fcff; font-size: 20px; visibility: visible; font-family: arial, helvetica, sans-serif;\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=Mzg5MzU1Nzc1Mw==&amp;mid=2247497266&amp;idx=1&amp;sn=0cbc4a257adbf7af3bdde782601e0b49&amp;chksm=c02fb8a4f75831b2484bc6e3f18423229a46caa0d11fea7aefc93dd89ba9418d7ebec649c009&amp;scene=21#wechat_redirect\" target=\"_blank\" rel=\"noopener\" data-itemshowtype=\"0\" data-linktype=\"2\" rel=\"nofollow\" ><span style=\"outline: 0px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); cursor: pointer; visibility: visible;\"><strong style=\"outline: 0px; visibility: visible;\">?\u70b9\u51fb\u9886\u53d6\uff1a651\u9875Java\u9762\u8bd5\u9898<\/strong><\/span><\/a><\/p>\n<p style=\"outline: 0px; letter-spacing: 0.544px; white-space: normal; font-family: system-ui, -apple-system, system-ui, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; text-align: center; line-height: normal; visibility: visible;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px; letter-spacing: 0.034em;\">Jedis\u628aRedis\u547d\u4ee4\u5c01\u88c5\u597d\uff0cLettuce\u5219\u8fdb\u4e00\u6b65\u6709\u4e86\u66f4\u4e30\u5bcc\u7684Api\uff0c\u4e5f\u652f\u6301\u96c6\u7fa4\u7b49\u6a21\u5f0f\u3002<\/span><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px; letter-spacing: 0.034em;\">\u4f46\u662f\u4e24\u8005\u4e5f\u90fd\u70b9\u5230\u4e3a\u6b62\uff0c\u53ea\u7ed9\u4e86\u4f60\u64cd\u4f5cRedis\u6570\u636e\u5e93\u7684\u811a\u624b\u67b6\uff0c\u800cRedisson\u5219\u662f\u57fa\u4e8eRedis\u3001Lua\u548cNetty\u5efa\u7acb\u8d77\u4e86\u6210\u719f\u7684\u5206\u5e03\u5f0f\u89e3\u51b3\u65b9\u6848\uff0c\u751a\u81f3redis\u5b98\u65b9\u90fd\u63a8\u8350\u7684\u4e00\u79cd\u5de5\u5177\u96c6\u3002<\/span><\/p>\n<h1 style=\"text-align: left;\" data-id=\"heading-1\"><span style=\"font-size: 18px;\"><strong><span style=\"font-size: 18px; font-family: arial, helvetica, sans-serif; color: #df7766;\">\u4e8c\u3001\u5206\u5e03\u5f0f\u9501<\/span><\/strong><\/span><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-1\"><span style=\"font-size: 12pt;\"><strong>\u5206\u5e03\u5f0f\u9501\u600e\u4e48\u5b9e\u73b0\uff1f<\/strong><\/span><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-1\"><span style=\"font-size: 12pt;\">\u5206\u5e03\u5f0f\u9501\u662f\u5e76\u53d1\u4e1a\u52a1\u4e0b\u7684\u521a\u9700\uff0c\u867d\u7136\u5b9e\u73b0\u4e94\u82b1\u516b\u95e8\uff1aZooKeeper\u6709Znode\u987a\u5e8f\u8282<span style=\"font-family: arial, helvetica, sans-serif; letter-spacing: 0.034em;\">\u70b9\uff0c\u6570\u636e\u5e93\u6709\u8868\u7ea7\u9501\u548c\u4e50\/\u60b2\u89c2\u9501\uff0cRedis\u6709setNx\uff0c\u4f46\u662f\u6b8a\u9014\u540c\u5f52\uff0c\u6700\u7ec8\u8fd8\u662f\u8981\u56de\u5230\u4e92\u65a5\u4e0a\u6765\uff0c\u672c\u7bc7\u4ecb\u7ecdRedisson\uff0c\u90a3\u5c31\u4ee5redis\u4e3a\u4f8b\u3002<\/span><\/span><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-1\"><span style=\"font-size: 12pt;\"><strong>\u600e\u4e48\u5199\u4e00\u4e2a\u7b80\u5355\u7684Redis\u5206\u5e03\u5f0f\u9501\uff1f<\/strong><\/span><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-1\"><span style=\"font-size: 12pt;\">\u4ee5Spring Data Redis\u4e3a\u4f8b\uff0c\u7528RedisTemplate\u6765\u64cd\u4f5cRedis\uff08setIfAbsent\u5df2\u7ecf\u662fsetNx + expire\u7684\u5408\u5e76\u547d\u4ee4\uff09\uff0c\u5982\u4e0b<\/span><\/h1>\n<section>\n<pre data-lang=\"cs\">\/\/ \u52a0\u9501public Boolean tryLock(String key, String value, long timeout, TimeUnit unit) { return redisTemplate.opsForValue().setIfAbsent(key, value, timeout, unit);}\/\/ \u89e3\u9501\uff0c\u9632\u6b62\u5220\u9519\u522b\u4eba\u7684\u9501\uff0c\u4ee5uuid\u4e3avalue\u6821\u9a8c\u662f\u5426\u81ea\u5df1\u7684\u9501public void unlock(String lockName, String uuid) { if(uuid.equals(redisTemplate.opsForValue().get(lockName)){ redisTemplate.opsForValue().del(lockName); }} \/\/ \u7ed3\u6784if(tryLock){ \/\/ todo}finally{ unlock;}<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u7b80\u53551.0\u7248\u672c\u5b8c\u6210\uff0c\u806a\u660e\u7684\u5c0f\u5f20\u4e00\u773c\u770b\u51fa\uff0c\u8fd9\u662f\u9501\u6ca1\u9519\uff0c\u4f46get\u548cdel\u64cd\u4f5c\u975e\u539f\u5b50\u6027\uff0c\u5e76\u53d1\u4e00\u65e6\u5927\u4e86\uff0c\u65e0\u6cd5\u4fdd\u8bc1\u8fdb\u7a0b\u5b89\u5168\u3002\u4e8e\u662f\u5c0f\u5f20\u63d0\u8bae\uff0c\u7528Lua\u811a\u672c<\/span><\/p>\n<p style=\"text-align: left;\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">Lua\u811a\u672c\u662f\u4ec0\u4e48\uff1f<\/span><\/strong><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">Lua\u811a\u672c\u662fredis\u5df2\u7ecf\u5185\u7f6e\u7684\u4e00\u79cd\u8f7b\u91cf\u5c0f\u5de7\u8bed\u8a00\uff0c\u5176\u6267\u884c\u662f\u901a\u8fc7redis\u7684eval\/evalsha\u547d\u4ee4\u6765\u8fd0\u884c\uff0c\u628a\u64cd\u4f5c\u5c01\u88c5\u6210\u4e00\u4e2aLua\u811a\u672c\uff0c\u5982\u8bba\u5982\u4f55\u90fd\u662f\u4e00\u6b21\u6267\u884c\u7684\u539f\u5b50\u64cd\u4f5c\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u4e8e\u662f2.0\u7248\u672c\u901a\u8fc7Lua\u811a\u672c\u5220\u9664<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">lockDel.lua\u5982\u4e0b<\/span><\/p>\n<section>\n<pre data-lang=\"ruby\">if redis.call('get', KEYS[1]) == ARGV[1] \n    then \n  -- \u6267\u884c\u5220\u9664\u64cd\u4f5c\n        return redis.call('del', KEYS[1]) \n    else \n  -- \u4e0d\u6210\u529f\uff0c\u8fd4\u56de0\n        return 0 \nend<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">delete\u64cd\u4f5c\u65f6\u6267\u884cLua\u547d\u4ee4<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"javascript\">\/\/ \u89e3\u9501\u811a\u672c\nDefaultRedisScript&lt;Object&gt; unlockScript = new DefaultRedisScript();\nunlockScript.setScriptSource(new ResourceScriptSource(new ClassPathResource(\"lockDel.lua\")));\n\/\/ \u6267\u884clua\u811a\u672c\u89e3\u9501\nredisTemplate.execute(unlockScript,\u00a0Collections.singletonList(keyName),\u00a0value);<\/pre>\n<\/section>\n<pre style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">2.0\u4f3c\u4e4e\u66f4\u50cf\u4e00\u628a\u9501\uff0c\u4f46\u597d\u50cf\u53c8\u7f3a\u5c11\u4e86\u4ec0\u4e48\uff0c\u5c0f\u5f20\u4e00\u62cd\u8111\u888b\uff0csynchronized\u548cReentrantLock\u90fd\u5f88\u4e1d\u6ed1\uff0c\u56e0\u4e3a\u4ed6\u4eec\u90fd\u662f\u53ef\u91cd\u5165\u9501\uff0c\u4e00\u4e2a\u7ebf\u7a0b\u591a\u6b21\u62ff\u9501\u4e5f\u4e0d\u4f1a\u6b7b\u9501\uff0c\u6211\u4eec\u9700\u8981\u53ef\u91cd\u5165\u3002<\/span><\/pre>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u600e\u4e48\u4fdd\u8bc1\u53ef\u91cd\u5165\uff1f<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u91cd\u5165\u5c31\u662f\uff0c\u540c\u4e00\u4e2a\u7ebf\u7a0b\u591a\u6b21\u83b7\u53d6\u540c\u4e00\u628a\u9501\u662f\u5141\u8bb8\u7684\uff0c\u4e0d\u4f1a\u9020\u6210\u6b7b\u9501\uff0c\u8fd9\u4e00\u70b9synchronized\u504f\u5411\u9501\u63d0\u4f9b\u4e86\u5f88\u597d\u7684\u601d\u8def\uff0csynchronized\u7684\u5b9e\u73b0\u91cd\u5165\u662f\u5728JVM\u5c42\u9762\uff0cJAVA\u5bf9\u8c61\u5934MARK WORD\u4e2d\u4fbf\u85cf\u6709\u7ebf\u7a0bID\u548c\u8ba1\u6570\u5668\u6765\u5bf9\u5f53\u524d\u7ebf\u7a0b\u505a\u91cd\u5165\u5224\u65ad\uff0c\u907f\u514d\u6bcf\u6b21CAS\u3002<\/span><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u5f53\u4e00\u4e2a\u7ebf\u7a0b\u8bbf\u95ee\u540c\u6b65\u5757\u5e76\u83b7\u53d6\u9501\u65f6\uff0c\u4f1a\u5728\u5bf9\u8c61\u5934\u548c\u6808\u5e27\u4e2d\u7684\u9501\u8bb0\u5f55\u91cc\u5b58\u50a8\u504f\u5411\u7684\u7ebf\u7a0bID\uff0c\u4ee5\u540e\u8be5\u7ebf\u7a0b\u5728\u8fdb\u5165\u548c\u9000\u51fa\u540c\u6b65\u5757\u65f6\u4e0d\u9700\u8981\u8fdb\u884cCAS\u64cd\u4f5c\u6765\u52a0\u9501\u548c\u89e3\u9501\uff0c\u53ea\u9700\u7b80\u5355\u6d4b\u8bd5\u4e00\u4e0b\u5bf9\u8c61\u5934\u7684Mark Word\u91cc\u662f\u5426\u5b58\u50a8\u7740\u6307\u5411\u5f53\u524d\u7ebf\u7a0b\u7684\u504f\u5411\u9501\u3002\u5982\u679c\u6d4b\u8bd5\u6210\u529f\uff0c\u8868\u793a\u7ebf\u7a0b\u5df2\u7ecf\u83b7\u5f97\u4e86\u9501\u3002\u5982\u679c\u6d4b\u8bd5\u5931\u8d25\uff0c\u5219\u9700\u8981\u518d\u6d4b\u8bd5\u4e00\u4e0bMark Word\u4e2d\u504f\u5411\u9501\u6807\u5fd7\u662f\u5426\u8bbe\u7f6e\u62101\uff1a\u6ca1\u6709\u5219CAS\u7ade\u4e89\uff1b\u8bbe\u7f6e\u4e86\uff0c\u5219CAS\u5c06\u5bf9\u8c61\u5934\u504f\u5411\u9501\u6307\u5411\u5f53\u524d\u7ebf\u7a0b\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u518d\u7ef4\u62a4\u4e00\u4e2a\u8ba1\u6570\u5668\uff0c\u540c\u4e2a\u7ebf\u7a0b\u8fdb\u5165\u5219\u81ea\u589e1\uff0c\u79bb\u5f00\u518d\u51cf1\uff0c\u76f4\u5230\u4e3a0\u624d\u80fd\u91ca\u653e<\/span><\/p>\n<\/blockquote>\n<h3 style=\"text-align: left;\" data-id=\"heading-2\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u53ef\u91cd\u5165\u9501<\/span><\/strong><\/h3>\n<h3 style=\"text-align: left;\" data-id=\"heading-2\">\u4eff\u9020\u8be5\u65b9\u6848\uff0c\u6211\u4eec\u9700\u6539\u9020Lua\u811a\u672c\uff1a<\/h3>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">1.\u9700\u8981\u5b58\u50a8 \u9501\u540d\u79f0lockName\u3001\u83b7\u5f97\u8be5\u9501\u7684\u7ebf\u7a0bid\u548c\u5bf9\u5e94\u7ebf\u7a0b\u7684\u8fdb\u5165\u6b21\u6570count<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">2.\u52a0\u9501<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u6bcf\u6b21\u7ebf\u7a0b\u83b7\u53d6\u9501\u65f6\uff0c\u5224\u65ad\u662f\u5426\u5df2\u5b58\u5728\u8be5\u9501<\/span><\/p>\n<ul class=\"list-paddingleft-1\">\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u4e0d\u5b58\u5728<\/span><\/p>\n<\/li>\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u8bbe\u7f6ehash\u7684key\u4e3a\u7ebf\u7a0bid\uff0cvalue\u521d\u59cb\u5316\u4e3a1<\/span><\/p>\n<\/li>\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4<\/span><\/p>\n<\/li>\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u8fd4\u56de\u83b7\u53d6\u9501\u6210\u529ftrue<\/span><\/p>\n<\/li>\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u5b58\u5728<\/span><\/p>\n<\/li>\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u7ee7\u7eed\u5224\u65ad\u662f\u5426\u5b58\u5728\u5f53\u524d\u7ebf\u7a0bid\u7684hash key<\/span><\/p>\n<\/li>\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u5b58\u5728\uff0c\u7ebf\u7a0bkey\u7684value + 1\uff0c\u91cd\u5165\u6b21\u6570\u589e\u52a01\uff0c\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4<\/span><\/p>\n<\/li>\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de\u52a0\u9501\u5931\u8d25<\/span><\/p>\n<\/li>\n<\/ul>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">3.\u89e3\u9501<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u6bcf\u6b21\u7ebf\u7a0b\u6765\u89e3\u9501\u65f6\uff0c\u5224\u65ad\u662f\u5426\u5df2\u5b58\u5728\u8be5\u9501<\/span><\/p>\n<ul class=\"list-paddingleft-1\">\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u5b58\u5728<\/span><\/p>\n<\/li>\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u662f\u5426\u6709\u8be5\u7ebf\u7a0b\u7684id\u7684hash key\uff0c\u6709\u5219\u51cf1\uff0c\u65e0\u5219\u8fd4\u56de\u89e3\u9501\u5931\u8d25<\/span><\/p>\n<\/li>\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u51cf1\u540e\uff0c\u5224\u65ad\u5269\u4f59count\u662f\u5426\u4e3a0\uff0c\u4e3a0\u5219\u8bf4\u660e\u4e0d\u518d\u9700\u8981\u8fd9\u628a\u9501\uff0c\u6267\u884cdel\u547d\u4ee4\u5220\u9664<\/span><\/p>\n<\/li>\n<\/ul>\n<\/blockquote>\n<h4 style=\"text-align: left;\" data-id=\"heading-3\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">1.\u5b58\u50a8\u7ed3\u6784<\/span><\/strong><\/h4>\n<h4 style=\"text-align: left;\" data-id=\"heading-3\"><span style=\"font-family: arial, helvetica, sans-serif; letter-spacing: 0.034em;\">\u4e3a\u4e86\u65b9\u4fbf\u7ef4\u62a4\u8fd9\u4e2a\u5bf9\u8c61\uff0c\u6211\u4eec\u7528Hash\u7ed3\u6784\u6765\u5b58\u50a8\u8fd9\u4e9b\u5b57\u6bb5\u3002Redis\u7684Hash\u7c7b\u4f3cJava\u7684HashM<\/span><span style=\"font-family: arial, helvetica, sans-serif; letter-spacing: 0.034em;\">ap\uff0c\u9002\u5408\u5b58\u50a8\u5bf9\u8c61\u3002<\/span><\/h4>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">hset lockname1 threadId 1<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u8bbe\u7f6e\u4e00\u4e2a\u540d\u5b57\u4e3alockname1\u7684hash\u7ed3\u6784\uff0c\u8be5hash\u7ed3\u6784key\u4e3athreadId\uff0c\u503cvalue\u4e3a1<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">hget lockname1 threadId<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u83b7\u53d6lockname1\u7684threadId\u7684\u503c<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u5b58\u50a8\u7ed3\u6784\u4e3a<\/span><\/p>\n<section>\n<pre data-lang=\"nginx\">lockname \u9501\u540d\u79f0\nkey1\uff1athreadId   \u552f\u4e00\u952e\uff0c\u7ebf\u7a0bid\nvalue1\uff1acount     \u8ba1\u6570\u5668\uff0c\u8bb0\u5f55\u8be5\u7ebf\u7a0b\u83b7\u53d6\u9501\u7684\u6b21\u6570<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">redis\u4e2d\u7684\u7ed3\u6784<\/span><\/p>\n<h4 style=\"text-align: left;\" data-id=\"heading-4\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">2.\u8ba1\u6570\u5668\u7684\u52a0\u51cf<\/span><\/strong><\/h4>\n<h4 style=\"text-align: left;\" data-id=\"heading-4\">\u5f53\u540c\u4e00\u4e2a\u7ebf\u7a0b\u83b7\u53d6\u540c\u4e00\u628a\u9501\u65f6\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u5bf9\u5e94\u7ebf\u7a0b\u7684\u8ba1\u6570\u5668count\u505a\u52a0\u51cf<\/h4>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u5224\u65ad\u4e00\u4e2aredis key\u662f\u5426\u5b58\u5728\uff0c\u53ef\u4ee5\u7528exists\uff0c\u800c\u5224\u65ad\u4e00\u4e2ahash\u7684key\u662f\u5426\u5b58\u5728\uff0c\u53ef\u4ee5\u7528hexists<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u800credis\u4e5f\u6709hash\u81ea\u589e\u7684\u547d\u4ee4hincrby<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u6bcf\u6b21\u81ea\u589e1\u65f6 hincrby lockname1 threadId 1\uff0c\u81ea\u51cf1\u65f6 hincrby lockname1<\/span><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px; letter-spacing: 0.034em;\">threadId -1<\/span><\/p>\n<h4 style=\"text-align: left;\" data-id=\"heading-5\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">3.\u89e3\u9501\u7684\u5224\u65ad<\/span><\/strong><\/h4>\n<h4 style=\"text-align: left;\" data-id=\"heading-5\">\u5f53\u4e00\u628a\u9501\u4e0d\u518d\u88ab\u9700\u8981\u4e86\uff0c\u6bcf\u6b21\u89e3\u9501\u4e00\u6b21\uff0ccount\u51cf1\uff0c\u76f4\u5230\u4e3a0\u65f6\uff0c\u6267\u884c\u5220\u9664<\/h4>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u7efc\u5408\u4e0a\u8ff0\u7684\u5b58\u50a8\u7ed3\u6784\u548c\u5224\u65ad\u6d41\u7a0b\uff0c\u52a0\u9501\u548c\u89e3\u9501Lua\u5982\u4e0b<\/span><\/p>\n<p style=\"text-align: left;\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u52a0\u9501 lock.lua<\/span><\/strong><\/p>\n<section>\n<pre data-lang=\"bash\">local key = KEYS[1];\nlocal threadId = ARGV[1];\nlocal releaseTime = ARGV[2];\n-- lockname\u4e0d\u5b58\u5728\nif(redis.call('exists', key) == 0) then\n    redis.call('hset', key, threadId, '1');\n    redis.call('expire', key, releaseTime);\n    return 1;\nend;\n-- \u5f53\u524d\u7ebf\u7a0b\u5df2id\u5b58\u5728\nif(redis.call('hexists', key, threadId) == 1) then\n    redis.call('hincrby', key, threadId, '1');\n    redis.call('expire', key, releaseTime);\n    return 1;\nend;\nreturn 0;<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u89e3\u9501 unlock.lua<\/span><\/strong><\/p>\n<section>\n<pre data-lang=\"ruby\">local key = KEYS[1];\nlocal threadId = ARGV[1];\n-- lockname\u3001threadId\u4e0d\u5b58\u5728\nif (redis.call('hexists', key, threadId) == 0) then\n    return nil;\nend;\n-- \u8ba1\u6570\u5668-1\nlocal count = redis.call('hincrby', key, threadId, -1);\n-- \u5220\u9664lock\nif (count == 0) then\n    redis.call('del', key);\n    return nil;\nend;<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u4ee3\u7801<\/span><\/p>\n<section>\n<pre data-lang=\"typescript\">\/**\n * @description \u539f\u751fredis\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501\n * @date 2021\/2\/6 10:51 \u4e0b\u5348\n **\/\n@Getter\n@Setter\npublic class RedisLock {\n    private RedisTemplate redisTemplate;\n    private DefaultRedisScript&lt;Long&gt; lockScript;\n    private DefaultRedisScript&lt;Object&gt; unlockScript;\n    public RedisLock(RedisTemplate redisTemplate) {\n        this.redisTemplate = redisTemplate;\n        \/\/ \u52a0\u8f7d\u52a0\u9501\u7684\u811a\u672c\n        lockScript = new DefaultRedisScript&lt;&gt;();\n        this.lockScript.setScriptSource(new ResourceScriptSource(new ClassPathResource(\"lock.lua\")));\n        this.lockScript.setResultType(Long.class);\n        \/\/ \u52a0\u8f7d\u91ca\u653e\u9501\u7684\u811a\u672c\n        unlockScript = new DefaultRedisScript&lt;&gt;();\n        this.unlockScript.setScriptSource(new ResourceScriptSource(new ClassPathResource(\"unlock.lua\")));\n    }\n    \/**\n     * \u83b7\u53d6\u9501\n     *\/\n    public String tryLock(String lockName, long releaseTime) {\n        \/\/ \u5b58\u5165\u7684\u7ebf\u7a0b\u4fe1\u606f\u7684\u524d\u7f00\n        String key = UUID.randomUUID().toString();\n        \/\/ \u6267\u884c\u811a\u672c\n        Long result = (Long) redisTemplate.execute(\n                lockScript,\n                Collections.singletonList(lockName),\n                key + Thread.currentThread().getId(),\n                releaseTime);\n        if (result != null &amp;&amp; result.intValue() == 1) {\n            return key;\n        } else {\n            return null;\n        }\n    }\n    \/**\n     * \u89e3\u9501\n     * @param lockName\n     * @param key\n     *\/\n    public void unlock(String lockName, String key) {\n        redisTemplate.execute(unlockScript,\n                Collections.singletonList(lockName),\n                key + Thread.currentThread().getId()\n                );\n    }\n}<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u81f3\u6b64\u5df2\u7ecf\u5b8c\u6210\u4e86\u4e00\u628a\u5206\u5e03\u5f0f\u9501\uff0c\u7b26\u5408\u4e92\u65a5\u3001\u53ef\u91cd\u5165\u3001\u9632\u6b7b\u9501\u7684\u57fa\u672c\u7279\u70b9\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u4e25\u8c28\u7684\u5c0f\u5f20\u89c9\u5f97\u867d\u7136\u5f53\u4e2a\u666e\u901a\u4e92\u65a5\u9501\uff0c\u5df2\u7ecf\u7a33\u7a33\u591f\u7528\uff0c\u53ef\u662f\u4e1a\u52a1\u91cc\u603b\u662f\u53c8\u5f88\u591a\u7279\u6b8a\u60c5\u51b5\u7684\uff0c\u6bd4\u5982A\u8fdb\u7a0b\u5728\u83b7\u53d6\u5230\u9501\u7684\u65f6\u5019\uff0c\u56e0\u4e1a\u52a1\u64cd\u4f5c\u65f6\u95f4\u592a\u957f\uff0c\u9501\u91ca\u653e\u4e86\u4f46\u662f\u4e1a\u52a1\u8fd8\u5728\u6267\u884c\uff0c\u800c\u6b64\u523bB\u8fdb\u7a0b\u53c8\u53ef\u4ee5\u6b63\u5e38\u62ff\u5230\u9501\u505a\u4e1a\u52a1\u64cd\u4f5c\uff0c\u4e24\u4e2a\u8fdb\u7a0b\u64cd\u4f5c\u5c31\u4f1a\u5b58\u5728\u4f9d\u65e7\u6709\u5171\u4eab\u8d44\u6e90\u7684\u95ee\u9898\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u800c\u4e14\u5982\u679c\u8d1f\u8d23\u50a8\u5b58\u8fd9\u4e2a\u5206\u5e03\u5f0f\u9501\u7684Redis\u8282\u70b9\u5b95\u673a\u4ee5\u540e\uff0c\u800c\u4e14\u8fd9\u4e2a\u9501\u6b63\u597d\u5904\u4e8e\u9501\u4f4f\u7684\u72b6\u6001\u65f6\uff0c\u8fd9\u4e2a\u9501\u4f1a\u51fa\u73b0\u9501\u6b7b\u7684\u72b6\u6001\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u5c0f\u5f20\u4e0d\u662f\u6760\u7cbe\uff0c\u56e0\u4e3a\u5e93\u5b58\u64cd\u4f5c\u603b\u6709\u8fd9\u6837\u90a3\u6837\u7684\u7279\u6b8a\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u6240\u4ee5\u6211\u4eec\u5e0c\u671b\u5728\u8fd9\u79cd\u60c5\u51b5\u65f6\uff0c\u53ef\u4ee5\u5ef6\u957f\u9501\u7684releaseTime\u5ef6\u8fdf\u91ca\u653e\u9501\u6765\u76f4\u5230\u5b8c\u6210\u4e1a\u52a1\u671f\u671b\u7ed3\u679c\uff0c\u8fd9\u79cd\u4e0d\u65ad\u5ef6\u957f\u9501\u8fc7\u671f\u65f6\u95f4\u6765\u4fdd\u8bc1\u4e1a\u52a1\u6267\u884c\u5b8c\u6210\u7684\u64cd\u4f5c\u5c31\u662f\u9501\u7eed\u7ea6\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u8bfb\u5199\u5206\u79bb\u4e5f\u662f\u5e38\u89c1\uff0c\u4e00\u4e2a\u8bfb\u591a\u5199\u5c11\u7684\u4e1a\u52a1\u4e3a\u4e86\u6027\u80fd\uff0c\u5e38\u5e38\u662f\u6709\u8bfb\u9501\u548c\u5199\u9501\u7684\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u800c\u6b64\u523b\u7684\u6269\u5c55\u5df2\u7ecf\u8d85\u51fa\u4e86\u4e00\u628a\u7b80\u5355\u8f6e\u5b50\u7684\u590d\u6742\u7a0b\u5ea6\uff0c\u5149\u662f\u5904\u7406\u7eed\u7ea6\uff0c\u5c31\u591f\u5c0f\u5f20\u559d\u4e00\u58f6\uff0c\u4f55\u51b5\u5728\u6027\u80fd\uff08\u9501\u7684\u6700\u5927\u7b49\u5f85\u65f6\u95f4\uff09\u3001\u4f18\u96c5\uff08\u65e0\u6548\u9501\u7533\u8bf7\uff09\u3001\u91cd\u8bd5\uff08\u5931\u8d25\u91cd\u8bd5\u673a\u5236\uff09\u7b49\u65b9\u9762\u8fd8\u8981\u4e0b\u529f\u592b\u7814\u7a76\u3002\u5728\u5c0f\u5f20\u82e6\u601d\u51a5\u60f3\u65f6\uff0c\u65c1\u8fb9\u7684\u5c0f\u767d\u51d1\u8fc7\u6765\u770b\u4e86\u770b\u5c0f\u5f20\uff0c\u5f88\u597d\u5947\uff0c\u90fd2021\u5e74\u4e86\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u76f4\u63a5\u7528redisson\u5462\uff1f<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">Redisson\u5c31\u6709\u8fd9\u628a\u4f60\u8981\u7684\u9501\u3002<\/span><\/p>\n<h1 style=\"text-align: left;\" data-id=\"heading-6\"><span style=\"font-size: 18px;\"><strong><span style=\"font-family: arial, helvetica, sans-serif; color: #df7766;\">\u4e09\u3001Redisson\u5206\u5e03\u5f0f\u9501<\/span><\/strong><\/span><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-6\">\u53f7\u79f0\u7b80\u5355\u7684Redisson\u5206\u5e03\u5f0f\u9501\u7684\u4f7f\u7528\u59ff\u52bf\u662f\u4ec0\u4e48\uff1f<\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-6\"><strong>1.\u4f9d\u8d56<\/strong><\/h1>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"xml\">&lt;!-- \u539f\u751f\uff0c\u672c\u7ae0\u4f7f\u7528--&gt;\n&lt;dependency&gt;\n    &lt;groupId&gt;org.redisson&lt;\/groupId&gt;\n    &lt;artifactId&gt;redisson&lt;\/artifactId&gt;\n    &lt;version&gt;3.13.6&lt;\/version&gt;\n&lt;\/dependency&gt;\n&lt;!-- \u53e6\u4e00\u79cdSpring\u96c6\u6210starter\uff0c\u672c\u7ae0\u672a\u4f7f\u7528 --&gt;\n&lt;dependency&gt;\n    &lt;groupId&gt;org.redisson&lt;\/groupId&gt;\n    &lt;artifactId&gt;redisson-spring-boot-starter&lt;\/artifactId&gt;\n    &lt;version&gt;3.13.6&lt;\/version&gt;\n&lt;\/dependency&gt;<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">2.\u914d\u7f6e<\/span><\/strong><\/p>\n<section>\n<pre data-lang=\"kotlin\">@Configuration\npublic class RedissionConfig {\n    @Value(\"${spring.redis.host}\")\n    private String redisHost;\n    @Value(\"${spring.redis.password}\")\n    private String password;\n    private int port = 6379;\n    @Bean\n    public RedissonClient getRedisson() {\n        Config config = new Config();\n        config.useSingleServer().\n                setAddress(\"redis:\/\/\" + redisHost + \":\" + port).\n                setPassword(password);\n        config.setCodec(new JsonJacksonCodec());\n        return Redisson.create(config);\n    }\n}<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">3.\u542f\u7528\u5206\u5e03\u5f0f\u9501<\/span><\/strong><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"typescript\">@Resource\nprivate RedissonClient redissonClient;\nRLock rLock = redissonClient.getLock(lockName);\ntry {\n    boolean isLocked = rLock.tryLock(expireTime, TimeUnit.MILLISECONDS);\n    if (isLocked) {\n        \/\/ TODO\n                }\n    } catch (Exception e) {\n            rLock.unlock();\n    }<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u7b80\u6d01\u660e\u4e86\uff0c\u53ea\u9700\u8981\u4e00\u4e2aRLock\uff0c\u65e2\u7136\u63a8\u8350Redisson\uff0c\u5c31\u5f80\u91cc\u9762\u770b\u770b\u4ed6\u662f\u600e\u4e48\u5b9e\u73b0\u7684\u3002<\/span><\/p>\n<h1 style=\"text-align: left;\" data-id=\"heading-7\"><span style=\"font-size: 18px; color: #df7766;\"><strong><span style=\"font-size: 18px; font-family: arial, helvetica, sans-serif;\">\u56db\u3001RLock<\/span><\/strong><\/span><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-7\">RLock\u662fRedisson\u5206\u5e03\u5f0f\u9501\u7684\u6700\u6838\u5fc3\u63a5\u53e3\uff0c\u7ee7\u627f\u4e86concurrent\u5305\u7684Lock\u63a5\u53e3\u548c\u81ea\u5df1\u7684RLockAsync\u63a5<span style=\"font-family: arial, helvetica, sans-serif; letter-spacing: 0.034em;\">\u53e3\uff0cRLockAsync\u7684\u8fd4\u56de\u503c\u90fd\u662fRFuture\uff0c\u662fRedisson\u6267\u884c\u5f02\u6b65\u5b9e\u73b0\u7684\u6838\u5fc3\u903b\u8f91\uff0c\u4e5f\u662fNetty\u53d1\u6325\u7684\u4e3b\u8981\u9635\u5730\u3002<\/span><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-7\"><strong>RLock\u5982\u4f55\u52a0\u9501\uff1f<\/strong><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-7\">\u4eceRLock\u8fdb\u5165\uff0c\u627e\u5230RedissonLock\u7c7b\uff0c\u627e\u5230tryLock\u65b9\u6cd5\u518d\u9012\u8fdb\u5230\u5e72\u4e8b\u7684tryAcquireOnceAsync\u65b9\u6cd5\uff0c\u8fd9\u662f\u52a0\u9501\u7684\u4e3b\u8981\u4ee3\u7801\uff08\u7248\u672c\u4e0d\u4e00\u6b64\u5904\u5b9e\u73b0\u6709\u5dee\u522b\uff0c\u548c\u6700\u65b03.15.x\u6709\u4e00\u5b9a\u51fa\u5165\uff0c\u4f46\u662f\u6838\u5fc3\u903b\u8f91\u4f9d\u7136\u672a\u53d8\u3002<span style=\"font-family: arial, helvetica, sans-serif; letter-spacing: 0.034em;\">\u6b64\u5904\u4ee53.13.6\u4e3a\u4f8b\uff09<\/span><\/h1>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"kotlin\">private RFuture&lt;Boolean&gt; tryAcquireOnceAsync(long waitTime, long leaseTime, TimeUnit unit, long threadId) {\n        if (leaseTime != -1L) {\n            return this.tryLockInnerAsync(waitTime, leaseTime, unit, threadId, RedisCommands.EVAL_NULL_BOOLEAN);\n        } else {\n            RFuture&lt;Boolean&gt; ttlRemainingFuture = this.tryLockInnerAsync(waitTime, this.commandExecutor.getConnectionManager().getCfg().getLockWatchdogTimeout(), TimeUnit.MILLISECONDS, threadId, RedisCommands.EVAL_NULL_BOOLEAN);\n            ttlRemainingFuture.onComplete((ttlRemaining, e) -&gt; {\n                if (e == null) {\n                    if (ttlRemaining) {\n                        this.scheduleExpirationRenewal(threadId);\n                    }\n                }\n            });\n            return ttlRemainingFuture;\n        }\n    }<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u6b64\u5904\u51fa\u73b0leaseTime\u65f6\u95f4\u5224\u65ad\u76842\u4e2a\u5206\u652f\uff0c\u5b9e\u9645\u4e0a\u5c31\u662f\u52a0\u9501\u65f6\u662f\u5426\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\uff0c\u672a\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\uff08-1\uff09\u65f6\u5219\u4f1a\u6709watchDog\u7684\u9501\u7eed\u7ea6\uff08\u4e0b\u6587\uff09\uff0c\u4e00\u4e2a\u6ce8\u518c\u4e86\u52a0\u9501\u4e8b\u4ef6\u7684\u7eed\u7ea6\u4efb\u52a1\u3002\u6211\u4eec\u5148\u6765\u770b\u6709\u8fc7\u671f\u65f6\u95f4tryLockInnerAsync\u90e8\u5206\uff0c<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">evalWriteAsync\u662feval\u547d\u4ee4\u6267\u884clua\u7684\u5165\u53e3<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"kotlin\">&lt;T&gt; RFuture&lt;T&gt; tryLockInnerAsync(long leaseTime, TimeUnit unit, long threadId, RedisStrictCommand&lt;T&gt; command) {\n        this.internalLockLeaseTime = unit.toMillis(leaseTime);\n        return this.commandExecutor.evalWriteAsync(this.getName(), LongCodec.INSTANCE, command, \"if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);\", Collections.singletonList(this.getName()), new Object[]{this.internalLockLeaseTime, this.getLockName(threadId)});\n    }<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u8fd9\u91cc\u63ed\u5f00\u771f\u9762\u76ee\uff0ceval\u547d\u4ee4\u6267\u884cLua\u811a\u672c\u7684\u5730\u65b9\uff0c\u6b64\u5904\u7684Lua\u811a\u672c\u5c55\u5f00<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"ruby\">-- \u4e0d\u5b58\u5728\u8be5key\u65f6\nif (redis.call('exists', KEYS[1]) == 0) then \n  -- \u65b0\u589e\u8be5\u9501\u5e76\u4e14hash\u4e2d\u8be5\u7ebf\u7a0bid\u5bf9\u5e94\u7684count\u7f6e1\n  redis.call('hincrby', KEYS[1], ARGV[2], 1); \n  -- \u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\n  redis.call('pexpire', KEYS[1], ARGV[1]); \n  return nil; \nend; \n-- \u5b58\u5728\u8be5key \u5e76\u4e14 hash\u4e2d\u7ebf\u7a0bid\u7684key\u4e5f\u5b58\u5728\nif (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then \n  -- \u7ebf\u7a0b\u91cd\u5165\u6b21\u6570++\n  redis.call('hincrby', KEYS[1], ARGV[2], 1); \n  redis.call('pexpire', KEYS[1], ARGV[1]); \n  return nil; \nend; \nreturn redis.call('pttl', KEYS[1]);<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u548c\u524d\u9762\u6211\u4eec\u5199\u81ea\u5b9a\u4e49\u7684\u5206\u5e03\u5f0f\u9501\u7684\u811a\u672c\u51e0\u4e4e\u4e00\u81f4\uff0c\u770b\u6765redisson\u4e5f\u662f\u4e00\u6837\u7684\u5b9e\u73b0\uff0c\u5177\u4f53\u53c2\u6570\u5206\u6790\uff1a<\/span><\/p>\n<section>\n<pre data-lang=\"kotlin\">\/\/ keyName\nKEYS[1] = Collections.singletonList(this.getName())\n\/\/ leaseTime\nARGV[1] = this.internalLockLeaseTime\n\/\/ uuid+threadId\u7ec4\u5408\u7684\u552f\u4e00\u503c\nARGV[2] = this.getLockName(threadId)<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u603b\u51713\u4e2a\u53c2\u6570\u5b8c\u6210\u4e86\u4e00\u6bb5\u903b\u8f91\uff1a<\/span><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u5224\u65ad\u8be5\u9501\u662f\u5426\u5df2\u7ecf\u6709\u5bf9\u5e94hash\u8868\u5b58\u5728\uff0c<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u2022 \u6ca1\u6709\u5bf9\u5e94\u7684hash\u8868\uff1a\u5219set\u8be5hash\u8868\u4e2d\u4e00\u4e2aentry\u7684key\u4e3a\u9501\u540d\u79f0\uff0cvalue\u4e3a1\uff0c\u4e4b\u540e\u8bbe\u7f6e\u8be5hash\u8868\u5931\u6548\u65f6\u95f4\u4e3aleaseTime<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u2022 \u5b58\u5728\u5bf9\u5e94\u7684hash\u8868\uff1a\u5219\u5c06\u8be5lockName\u7684value\u6267\u884c+1\u64cd\u4f5c\uff0c\u4e5f\u5c31\u662f\u8ba1\u7b97\u8fdb\u5165\u6b21\u6570\uff0c\u518d\u8bbe\u7f6e\u5931\u6548\u65f6\u95f4leaseTime<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u2022 \u6700\u540e\u8fd4\u56de\u8fd9\u628a\u9501\u7684ttl\u5269\u4f59\u65f6\u95f4<\/span><\/p>\n<\/blockquote>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u4e5f\u548c\u4e0a\u8ff0\u81ea\u5b9a\u4e49\u9501\u6ca1\u6709\u533a\u522b<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u65e2\u7136\u5982\u6b64\uff0c\u90a3\u89e3\u9501\u7684\u6b65\u9aa4\u4e5f\u80af\u5b9a\u6709\u5bf9\u5e94\u7684-1\u64cd\u4f5c\uff0c\u518d\u770bunlock\u65b9\u6cd5\uff0c\u540c\u6837\u67e5\u627e\u65b9\u6cd5\u540d\uff0c\u4e00\u8def\u5230<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"kotlin\">protected RFuture&lt;Boolean&gt; unlockInnerAsync(long threadId) {\n        return this.commandExecutor.evalWriteAsync(this.getName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, \"if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end; local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter &gt; 0) then redis.call('pexpire', KEYS[1], ARGV[2]); return 0; else redis.call('del', KEYS[1]); redis.call('publish', KEYS[2], ARGV[1]); return 1; end; return nil;\", Arrays.asList(this.getName(), this.getChannelName()), new Object[]{LockPubSub.unlockMessage, this.internalLockLeaseTime, this.getLockName(threadId)});\n    }<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u638f\u51faLua\u90e8\u5206<\/span><\/strong><\/p>\n<section>\n<pre data-lang=\"ruby\">-- \u4e0d\u5b58\u5728key\nif (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then \n  return nil;\nend;\n-- \u8ba1\u6570\u5668 -1\nlocal counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); \nif (counter &gt; 0) then \n  -- \u8fc7\u671f\u65f6\u95f4\u91cd\u8bbe\n  redis.call('pexpire', KEYS[1], ARGV[2]); \n  return 0; \nelse\n  -- \u5220\u9664\u5e76\u53d1\u5e03\u89e3\u9501\u6d88\u606f\n  redis.call('del', KEYS[1]); \n  redis.call('publish', KEYS[2], ARGV[1]); \n  return 1;\nend; \nreturn nil;<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u8be5Lua KEYS\u67092\u4e2aArrays.asList(getName(), getChannelName())<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"css\"><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__selector-tag\">name<\/span> \u9501\u540d\u79f0<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__selector-tag\">channelName<\/span>\uff0c\u7528\u4e8e<span class=\"code-snippet__selector-tag\">pubSub<\/span>\u53d1\u5e03\u6d88\u606f\u7684<span class=\"code-snippet__selector-tag\">channel<\/span>\u540d\u79f0<\/span><\/code><\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">ARGV\u53d8\u91cf\u6709\u4e09\u4e2aLockPubSub.UNLOCK_MESSAGE, internalLockLeaseTime, getLockName(threadId)<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"css\"><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__selector-tag\">LockPubSub<\/span><span class=\"code-snippet__selector-class\">.UNLOCK_MESSAGE<\/span>\uff0c<span class=\"code-snippet__selector-tag\">channel<\/span>\u53d1\u9001\u6d88\u606f\u7684\u7c7b\u522b\uff0c\u6b64\u5904\u89e3\u9501\u4e3a0<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__selector-tag\">\ninternalLockLeaseTime<\/span>\uff0c<span class=\"code-snippet__selector-tag\">watchDog<\/span>\u914d\u7f6e\u7684\u8d85\u65f6\u65f6\u95f4\uff0c\u9ed8\u8ba4\u4e3a30<span class=\"code-snippet__selector-tag\">s<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__selector-tag\">\nlockName<\/span> \u8fd9\u91cc\u7684<span class=\"code-snippet__selector-tag\">lockName<\/span>\u6307\u7684\u662f<span class=\"code-snippet__selector-tag\">uuid<\/span>\u548c<span class=\"code-snippet__selector-tag\">threadId<\/span>\u7ec4\u5408\u7684\u552f\u4e00\u503c<\/span><\/code><\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u6b65\u9aa4\u5982\u4e0b\uff1a<\/span><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">1.\u5982\u679c\u8be5\u9501\u4e0d\u5b58\u5728\u5219\u8fd4\u56denil\uff1b<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">2.\u5982\u679c\u8be5\u9501\u5b58\u5728\u5219\u5c06\u5176\u7ebf\u7a0b\u7684hash key\u8ba1\u6570\u5668-1\uff0c<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">3.\u8ba1\u6570\u5668counter&gt;0\uff0c\u91cd\u7f6e\u4e0b\u5931\u6548\u65f6\u95f4\uff0c\u8fd4\u56de0\uff1b\u5426\u5219\uff0c\u5220\u9664\u8be5\u9501\uff0c\u53d1\u5e03\u89e3\u9501\u6d88\u606funlockMessage\uff0c\u8fd4\u56de1\uff1b<\/span><\/p>\n<\/blockquote>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u5176\u4e2dunLock\u7684\u65f6\u5019\u4f7f\u7528\u5230\u4e86Redis\u53d1\u5e03\u8ba2\u9605PubSub\u5b8c\u6210\u6d88\u606f\u901a\u77e5\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u800c\u8ba2\u9605\u7684\u6b65\u9aa4\u5c31\u5728RedissonLock\u7684\u52a0\u9501\u5165\u53e3\u7684lock\u65b9\u6cd5\u91cc<\/span><\/p>\n<section>\n<pre data-lang=\"kotlin\">long threadId = Thread.currentThread().getId();\n        Long ttl = this.tryAcquire(-1L, leaseTime, unit, threadId);\n        if (ttl != null) {\n            \/\/ \u8ba2\u9605\n            RFuture&lt;RedissonLockEntry&gt; future = this.subscribe(threadId);\n            if (interruptibly) {\n                this.commandExecutor.syncSubscriptionInterrupted(future);\n            } else {\n                this.commandExecutor.syncSubscription(future);\n            }\n            \/\/ \u7701\u7565<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u5f53\u9501\u88ab\u5176\u4ed6\u7ebf\u7a0b\u5360\u7528\u65f6\uff0c\u901a\u8fc7\u76d1\u542c\u9501\u7684\u91ca\u653e\u901a\u77e5\uff08\u5728\u5176\u4ed6\u7ebf\u7a0b\u901a\u8fc7RedissonLock\u91ca\u653e\u9501\u65f6\uff0c\u4f1a\u901a\u8fc7\u53d1\u5e03\u8ba2\u9605pub\/sub\u529f\u80fd\u53d1\u8d77\u901a\u77e5\uff09\uff0c\u7b49\u5f85\u9501\u88ab\u5176\u4ed6\u7ebf\u7a0b\u91ca\u653e\uff0c\u4e5f\u662f\u4e3a\u4e86\u907f\u514d\u81ea\u65cb\u7684\u4e00\u79cd\u5e38\u7528\u6548\u7387\u624b\u6bb5\u3002<\/span><\/p>\n<h3 style=\"text-align: left;\" data-id=\"heading-8\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">1.\u89e3\u9501\u6d88\u606f<\/span><\/strong><\/h3>\n<h3 style=\"text-align: left;\" data-id=\"heading-8\">\u4e3a\u4e86\u4e00\u63a2\u7a76\u7adf\u901a\u77e5\u4e86\u4ec0\u4e48\uff0c\u901a\u77e5\u540e\u53c8\u505a\u4e86\u4ec0\u4e48\uff0c\u8fdb\u5165LockPubSub\u3002<\/h3>\n<h3 style=\"text-align: left;\" data-id=\"heading-8\">\u8fd9\u91cc\u53ea\u6709\u4e00\u4e2a\u660e\u663e\u7684<span style=\"font-family: arial, helvetica, sans-serif; letter-spacing: 0.034em;\">\u76d1\u542c\u65b9\u6cd5onMessage\uff0c\u5176\u8ba2\u9605\u548c\u4fe1\u53f7\u91cf\u7684\u91ca\u653e\u90fd\u5728\u7236\u7c7bPublishSubscribe\uff0c\u6211\u4eec\u53ea\u5173\u6ce8\u76d1\u542c\u4e8b\u4ef6\u7684\u5b9e\u9645\u64cd\u4f5c<\/span><\/h3>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"cs\">protected void onMessage(RedissonLockEntry value, Long message) {\n        Runnable runnableToExecute;\n        if (message.equals(unlockMessage)) {\n            \/\/ \u4ece\u76d1\u542c\u5668\u961f\u5217\u53d6\u76d1\u542c\u7ebf\u7a0b\u6267\u884c\u76d1\u542c\u56de\u8c03\n            runnableToExecute = (Runnable)value.getListeners().poll();\n            if (runnableToExecute != null) {\n                runnableToExecute.run();\n            }\n            \/\/ getLatch()\u8fd4\u56de\u7684\u662fSemaphore\uff0c\u4fe1\u53f7\u91cf\uff0c\u6b64\u5904\u662f\u91ca\u653e\u4fe1\u53f7\u91cf\n            \/\/ \u91ca\u653e\u4fe1\u53f7\u91cf\u540e\u4f1a\u5524\u9192\u7b49\u5f85\u7684entry.getLatch().tryAcquire\u53bb\u518d\u6b21\u5c1d\u8bd5\u7533\u8bf7\u9501\n            value.getLatch().release();\n        } else if (message.equals(readUnlockMessage)) {\n            while(true) {\n                runnableToExecute = (Runnable)value.getListeners().poll();\n                if (runnableToExecute == null) {\n                    value.getLatch().release(value.getLatch().getQueueLength());\n                    break;\n                }\n                runnableToExecute.run();\n            }\n        }\n    }<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u53d1\u73b0\u4e00\u4e2a\u662f\u9ed8\u8ba4\u89e3\u9501\u6d88\u606f\uff0c\u4e00\u4e2a\u662f**\u8bfb\u9501\u89e3\u9501\u6d88\u606f****\uff0c**\u56e0\u4e3aredisson\u662f\u6709\u63d0\u4f9b\u8bfb\u5199\u9501\u7684\uff0c\u800c\u8bfb\u5199\u9501\u8bfb\u8bfb\u60c5\u51b5\u548c\u8bfb\u5199\u3001\u5199\u5199\u60c5\u51b5\u4e92\u65a5\u60c5\u51b5\u4e0d\u540c\uff0c\u6211\u4eec\u53ea\u770b\u4e0a\u9762\u7684\u9ed8\u8ba4\u89e3\u9501\u6d88\u606funlockMessage\u5206\u652f<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">LockPubSub\u76d1\u542c\u6700\u7ec8\u6267\u884c\u4e862\u4ef6\u4e8b<\/span><\/p>\n<ol class=\"list-paddingleft-1\">\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">runnableToExecute.run() \u6267\u884c\u76d1\u542c\u56de\u8c03<\/span><\/p>\n<\/li>\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">value.getLatch().release(); \u91ca\u653e\u4fe1\u53f7\u91cf<\/span><\/p>\n<\/li>\n<\/ol>\n<p style=\"text-align: left;\"><span style=\"letter-spacing: 0.034em;\">Redisson\u901a\u8fc7LockPubSub\u76d1\u542c\u89e3\u9501\u6d88\u606f\uff0c\u6267\u884c\u76d1\u542c\u56de\u8c03\u548c\u91ca\u653e\u4fe1\u53f7\u91cf\u901a\u77e5\u7b49\u5f85\u7ebf\u7a0b\u53ef\u4ee5\u91cd\u65b0\u62a2\u9501\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u8fd9\u65f6\u518d\u56de\u6765\u770btryAcquireOnceAsync\u53e6\u4e00\u5206\u652f<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"kotlin\">private RFuture&lt;Boolean&gt; tryAcquireOnceAsync(long waitTime, long leaseTime, TimeUnit unit, long threadId) {\n        if (leaseTime != -1L) {\n            return this.tryLockInnerAsync(waitTime, leaseTime, unit, threadId, RedisCommands.EVAL_NULL_BOOLEAN);\n        } else {\n            RFuture&lt;Boolean&gt; ttlRemainingFuture = this.tryLockInnerAsync(waitTime, this.commandExecutor.getConnectionManager().getCfg().getLockWatchdogTimeout(), TimeUnit.MILLISECONDS, threadId, RedisCommands.EVAL_NULL_BOOLEAN);\n            ttlRemainingFuture.onComplete((ttlRemaining, e) -&gt; {\n                if (e == null) {\n                    if (ttlRemaining) {\n                        this.scheduleExpirationRenewal(threadId);\n                    }\n                }\n            });\n            return ttlRemainingFuture;\n        }\n    }<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u53ef\u4ee5\u770b\u5230\uff0c\u65e0\u8d85\u65f6\u65f6\u95f4\u65f6\uff0c\u5728\u6267\u884c\u52a0\u9501\u64cd\u4f5c\u540e\uff0c\u8fd8\u6267\u884c\u4e86\u4e00\u6bb5\u8d39\u89e3\u7684\u903b\u8f91<\/span><\/p>\n<section>\n<pre data-lang=\"kotlin\">ttlRemainingFuture.onComplete((ttlRemaining, e) -&gt; {\n                if (e == null) {\n                    if (ttlRemaining) {\n                        this.scheduleExpirationRenewal(threadId);\n                    }\n                }\n            })<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u6b64\u5904\u6d89\u53ca\u5230Netty\u7684Future\/Promise-Listener\u6a21\u578b\uff08\u53c2\u8003<\/span><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">Netty\u4e2d\u7684\u5f02\u6b65\u7f16\u7a0b<\/span><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\uff09\uff0cRedisson\u4e2d\u51e0\u4e4e\u5168\u90e8\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u901a\u4fe1\uff08\u6240\u4ee5\u8bf4Redisson\u662f\u57fa\u4e8eNetty\u901a\u4fe1\u673a\u5236\u5b9e\u73b0\u7684\uff09\uff0c\u7406\u89e3\u8fd9\u6bb5\u903b\u8f91\u53ef\u4ee5\u8bd5\u7740\u5148\u7406\u89e3<\/span><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u5728 Java \u7684 Future \u4e2d\uff0c\u4e1a\u52a1\u903b\u8f91\u4e3a\u4e00\u4e2a Callable \u6216 Runnable \u5b9e\u73b0\u7c7b\uff0c\u8be5\u7c7b\u7684 call()\u6216 run()\u6267\u884c\u5b8c\u6bd5\u610f\u5473\u7740\u4e1a\u52a1\u903b\u8f91\u7684\u5b8c\u7ed3\uff0c\u5728 Promise \u673a\u5236\u4e2d\uff0c\u53ef\u4ee5\u5728\u4e1a\u52a1\u903b\u8f91\u4e2d\u4eba\u5de5\u8bbe\u7f6e\u4e1a\u52a1\u903b\u8f91\u7684\u6210\u529f\u4e0e\u5931\u8d25\uff0c\u8fd9\u6837\u66f4\u52a0\u65b9\u4fbf\u7684\u76d1\u63a7\u81ea\u5df1\u7684\u4e1a\u52a1\u903b\u8f91\u3002<\/span><\/p>\n<\/blockquote>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u8fd9\u5757\u4ee3\u7801\u7684\u8868\u9762\u610f\u4e49\u5c31\u662f\uff0c\u5728\u6267\u884c\u5f02\u6b65\u52a0\u9501\u7684\u64cd\u4f5c\u540e\uff0c\u52a0\u9501\u6210\u529f\u5219\u6839\u636e\u52a0\u9501\u5b8c\u6210\u8fd4\u56de\u7684ttl\u662f\u5426\u8fc7\u671f\u6765\u786e\u8ba4\u662f\u5426\u6267\u884c\u4e00\u6bb5\u5b9a\u65f6\u4efb\u52a1\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u8fd9\u6bb5\u5b9a\u65f6\u4efb\u52a1\u7684\u5c31\u662fwatchDog\u7684\u6838\u5fc3\u3002<\/span><\/p>\n<h3 style=\"text-align: left;\" data-id=\"heading-9\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">2.\u9501\u7eed\u7ea6<\/span><\/strong><\/h3>\n<h3 style=\"text-align: left;\" data-id=\"heading-9\">\u67e5\u770bRedissonLo<span style=\"font-family: arial, helvetica, sans-serif; letter-spacing: 0.034em;\">ck.this.scheduleExpirationRenewal(threadId)<\/span><\/h3>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"kotlin\">private void scheduleExpirationRenewal(long threadId) {\n        RedissonLock.ExpirationEntry entry = new RedissonLock.ExpirationEntry();\n        RedissonLock.ExpirationEntry oldEntry = (RedissonLock.ExpirationEntry)EXPIRATION_RENEWAL_MAP.putIfAbsent(this.getEntryName(), entry);\n        if (oldEntry != null) {\n            oldEntry.addThreadId(threadId);\n        } else {\n            entry.addThreadId(threadId);\n            this.renewExpiration();\n        }\n    }\nprivate void renewExpiration() {\n        RedissonLock.ExpirationEntry ee = (RedissonLock.ExpirationEntry)EXPIRATION_RENEWAL_MAP.get(this.getEntryName());\n        if (ee != null) {\n            Timeout task = this.commandExecutor.getConnectionManager().newTimeout(new TimerTask() {\n                public void run(Timeout timeout) throws Exception {\n                    RedissonLock.ExpirationEntry ent = (RedissonLock.ExpirationEntry)RedissonLock.EXPIRATION_RENEWAL_MAP.get(RedissonLock.this.getEntryName());\n                    if (ent != null) {\n                        Long threadId = ent.getFirstThreadId();\n                        if (threadId != null) {\n                            RFuture&lt;Boolean&gt; future = RedissonLock.this.renewExpirationAsync(threadId);\n                            future.onComplete((res, e) -&gt; {\n                                if (e != null) {\n                                    RedissonLock.log.error(\"Can't update lock \" + RedissonLock.this.getName() + \" expiration\", e);\n                                } else {\n                                    if (res) {\n                                        RedissonLock.this.renewExpiration();\n                                    }\n                                }\n                            });\n                        }\n                    }\n                }\n            }, this.internalLockLeaseTime \/ 3L, TimeUnit.MILLISECONDS);\n            ee.setTimeout(task);\n        }\n    }<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u62c6\u5206\u6765\u770b\uff0c\u8fd9\u6bb5\u8fde\u7eed\u5d4c\u5957\u4e14\u5197\u957f\u7684\u4ee3\u7801\u5b9e\u9645\u4e0a\u505a\u4e86\u51e0\u6b65<\/span><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u2022 \u6dfb\u52a0\u4e00\u4e2anetty\u7684Timeout\u56de\u8c03\u4efb\u52a1\uff0c\u6bcf\uff08internalLockLeaseTime \/ 3\uff09\u6beb\u79d2\u6267\u884c\u4e00\u6b21\uff0c\u6267\u884c\u7684\u65b9\u6cd5\u662frenewExpirationAsync<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u2022 renewExpirationAsync\u91cd\u7f6e\u4e86\u9501\u8d85\u65f6\u65f6\u95f4\uff0c\u53c8\u6ce8\u518c\u4e00\u4e2a\u76d1\u542c\u5668\uff0c\u76d1\u542c\u56de\u8c03\u53c8\u6267\u884c\u4e86renewExpiration<\/span><\/p>\n<\/blockquote>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">renewExpirationAsync \u7684Lua\u5982\u4e0b<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"kotlin\">protected RFuture&lt;Boolean&gt; renewExpirationAsync(long threadId) {\n        return this.commandExecutor.evalWriteAsync(this.getName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, \"if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('pexpire', KEYS[1], ARGV[1]); return 1; end; return 0;\", Collections.singletonList(this.getName()), new Object[]{this.internalLockLeaseTime, this.getLockName(threadId)});\n    }\nif (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then \n  redis.call('pexpire', KEYS[1], ARGV[1]); \n  return 1; \nend; \nreturn 0;<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u91cd\u65b0\u8bbe\u7f6e\u4e86\u8d85\u65f6\u65f6\u95f4\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">Redisson\u52a0\u8fd9\u6bb5\u903b\u8f91\u7684\u76ee\u7684\u662f\u4ec0\u4e48\uff1f<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u76ee\u7684\u662f\u4e3a\u4e86\u67d0\u79cd\u573a\u666f\u4e0b\u4fdd\u8bc1\u4e1a\u52a1\u4e0d\u5f71\u54cd\uff0c\u5982\u4efb\u52a1\u6267\u884c\u8d85\u65f6\u4f46\u672a\u7ed3\u675f\uff0c\u9501\u5df2\u7ecf\u91ca\u653e\u7684\u95ee\u9898\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u5f53\u4e00\u4e2a\u7ebf\u7a0b\u6301\u6709\u4e86\u4e00\u628a\u9501\uff0c\u7531\u4e8e\u5e76\u672a\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4leaseTime\uff0cRedisson\u9ed8\u8ba4\u914d\u7f6e\u4e8630S\uff0c\u5f00\u542fwatchDog\uff0c\u6bcf10S\u5bf9\u8be5\u9501\u8fdb\u884c\u4e00\u6b21\u7eed\u7ea6\uff0c\u7ef4\u630130S\u7684\u8d85\u65f6\u65f6\u95f4\uff0c\u76f4\u5230\u4efb\u52a1\u5b8c\u6210\u518d\u5220\u9664\u9501\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u8fd9\u5c31\u662fRedisson\u7684\u9501\u7eed\u7ea6\uff0c\u4e5f\u5c31\u662fWatchDog\u5b9e\u73b0\u7684\u57fa\u672c\u601d\u8def\u3002<\/span><\/p>\n<h3 style=\"text-align: left;\" data-id=\"heading-10\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">3.\u6d41\u7a0b\u6982\u62ec<\/span><\/strong><\/h3>\n<h3 style=\"text-align: left;\" data-id=\"heading-10\"><\/h3>\n<h3 style=\"text-align: left;\" data-id=\"heading-10\">\u901a<span style=\"font-family: arial, helvetica, sans-serif; letter-spacing: 0.034em;\">\u8fc7\u6574\u4f53\u7684\u4ecb\u7ecd\uff0c\u6d41\u7a0b\u7b80\u5355\u6982\u62ec\uff1a<\/span><\/h3>\n<blockquote>\n<ol class=\"list-paddingleft-1\">\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">A\u3001B\u7ebf\u7a0b\u4e89\u62a2\u4e00\u628a\u9501\uff0cA\u83b7\u53d6\u5230\u540e\uff0cB\u963b\u585e<\/span><\/p>\n<\/li>\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">B\u7ebf\u7a0b\u963b\u585e\u65f6\u5e76\u975e\u4e3b\u52a8CAS\uff0c\u800c\u662fPubSub\u65b9\u5f0f\u8ba2\u9605\u8be5\u9501\u7684\u5e7f\u64ad\u6d88\u606f<\/span><\/p>\n<\/li>\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">A\u64cd\u4f5c\u5b8c\u6210\u91ca\u653e\u4e86\u9501\uff0cB\u7ebf\u7a0b\u6536\u5230\u8ba2\u9605\u6d88\u606f\u901a\u77e5<\/span><\/p>\n<\/li>\n<li style=\"font-size: 15px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">B\u88ab\u5524\u9192\u5f00\u59cb\u7ee7\u7eed\u62a2\u9501\uff0c\u62ff\u5230\u9501<\/span><\/p>\n<\/li>\n<\/ol>\n<\/blockquote>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u8be6\u7ec6\u52a0\u9501\u89e3\u9501\u6d41\u7a0b\u603b\u7ed3\u5982\u4e0b\u56fe\uff1a<\/span><img class=\"rich_pages wxw-img lazyload\" data-ratio=\"1.1055555555555556\" data-type=\"other\" data-w=\"1080\" \/><noscript><img class=\"rich_pages wxw-img\" data-ratio=\"1.1055555555555556\" data-type=\"other\" data-w=\"1080\" \/><\/noscript><\/p>\n<h1 style=\"text-align: left;\" data-id=\"heading-11\"><span style=\"font-size: 18px; color: #df7766;\"><strong><span style=\"color: #df7766; font-size: 18px; font-family: arial, helvetica, sans-serif;\">\u4e94\u3001\u516c\u5e73\u9501<\/span><\/strong><\/span><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-11\">\u4ee5\u4e0a\u4ecb\u7ecd\u7684\u53ef\u91cd\u5165\u9501\u662f\u975e\u516c\u5e73\u9501\uff0cRedisson\u8fd8\u57fa\u4e8eRedis\u7684\u961f\u5217\uff08List\uff09\u548cZSet\u5b9e\u73b0\u4e86\u516c\u5e73\u9501<\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-11\"><strong>\u516c\u5e73\u7684\u5b9a\u4e49\u662f\u4ec0\u4e48\uff1f<\/strong><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-11\">\u516c\u5e73\u5c31\u662f\u6309\u7167\u5ba2<span style=\"font-family: arial, helvetica, sans-serif; letter-spacing: 0.034em;\">\u6237\u7aef\u7684\u8bf7\u6c42\u5148\u6765\u540e\u5230\u6392\u961f\u6765\u83b7\u53d6\u9501\uff0c\u5148\u5230\u5148\u5f97\uff0c\u4e5f\u5c31\u662fFIFO\uff0c\u6240\u4ee5\u961f\u5217\u548c\u5bb9\u5668\u987a\u5e8f\u7f16\u6392\u5fc5\u4e0d\u53ef\u5c11<\/span><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-11\"><strong>FairSync<\/strong><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-11\">\u56de\u987eJUC\u7684ReentrantLock\u516c\u5e73\u9501\u7684\u5b9e\u73b0<\/h1>\n<section>\n<pre data-lang=\"java\">\/**\n     * Sync object for fair locks\n     *\/\n    static final class FairSync extends Sync {\n        private static final long serialVersionUID = -3000897897090466540L;\n        final void lock() {\n            acquire(1);\n        }\n        \/**\n         * Fair version of tryAcquire.  Don't grant access unless\n         * recursive call or no waiters or is first.\n         *\/\n        protected final boolean tryAcquire(int acquires) {\n            final Thread current = Thread.currentThread();\n            int c = getState();\n            if (c == 0) {\n                if (!hasQueuedPredecessors() &amp;&amp;\n                    compareAndSetState(0, acquires)) {\n                    setExclusiveOwnerThread(current);\n                    return true;\n                }\n            }\n            else if (current == getExclusiveOwnerThread()) {\n                int nextc = c + acquires;\n                if (nextc &lt; 0)\n                    throw new Error(\"Maximum lock count exceeded\");\n                setState(nextc);\n                return true;\n            }\n            return false;\n        }\n    }<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">AQS\u5df2\u7ecf\u63d0\u4f9b\u4e86\u6574\u4e2a\u5b9e\u73b0\uff0c\u662f\u5426\u516c\u5e73\u53d6\u51b3\u4e8e\u5b9e\u73b0\u7c7b\u53d6\u51fa\u8282\u70b9\u903b\u8f91\u662f\u5426\u987a\u5e8f\u53d6<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">AbstractQueuedSynchronizer\u662f\u7528\u6765\u6784\u5efa\u9501\u6216\u8005\u5176\u4ed6\u540c\u6b65\u7ec4\u4ef6\u7684\u57fa\u7840\u6846\u67b6\uff0c\u901a\u8fc7\u5185\u7f6eFIFO\u961f\u5217\u6765\u5b8c\u6210\u8d44\u6e90\u83b7\u53d6\u7ebf\u7a0b\u7684\u6392\u961f\u5de5\u4f5c\uff0c\u4ed6\u81ea\u8eab\u6ca1\u6709\u5b9e\u73b0\u540c\u6b65\u63a5\u53e3\uff0c\u4ec5\u4ec5\u5b9a\u4e49\u4e86\u82e5\u5e72\u540c\u6b65\u72b6\u6001\u83b7\u53d6\u548c\u91ca\u653e\u7684\u65b9\u6cd5\u6765\u4f9b\u81ea\u5b9a\u4e49\u540c\u6b65\u7ec4\u4ef6\u4f7f\u7528\uff08\u4e0a\u56fe\uff09\uff0c\u652f\u6301\u72ec\u5360\u548c\u5171\u4eab\u83b7\u53d6\uff0c\u8fd9\u662f\u57fa\u4e8e\u6a21\u7248\u65b9\u6cd5\u6a21\u5f0f\u7684\u4e00\u79cd\u8bbe\u8ba1\uff0c\u7ed9\u516c\u5e73\/\u975e\u516c\u5e73\u63d0\u4f9b\u4e86\u571f\u58e4\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u6211\u4eec\u75282\u5f20\u56fe\u6765\u7b80\u5355\u89e3\u91caAQS\u7684\u7b49\u5f85\u6d41\u7a0b\uff08\u51fa\u81ea\u300aJAVA\u5e76\u53d1\u7f16\u7a0b\u7684\u827a\u672f\u300b\uff09<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u4e00\u5f20\u662f\u540c\u6b65\u961f\u5217\uff08FIFO\u53cc\u5411\u961f\u5217\uff09\u7ba1\u7406 \u83b7\u53d6\u540c\u6b65\u72b6\u6001\u5931\u8d25\uff08\u62a2\u9501\u5931\u8d25\uff09\u7684\u7ebf\u7a0b\u5f15\u7528\u3001\u7b49\u5f85\u72b6\u6001\u548c\u524d\u9a71\u540e\u7ee7\u8282\u70b9\u7684\u6d41\u7a0b\u56fe<\/span><img class=\"lazyload\"data-ratio=\"0.28445006321112515\" data-type=\"other\" data-w=\"791\" \/><noscript><img data-ratio=\"0.28445006321112515\" data-type=\"other\" data-w=\"791\" \/><\/noscript><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u4e00\u5f20\u662f\u72ec\u5360\u5f0f\u83b7\u53d6\u540c\u6b65\u72b6\u6001\u7684\u603b\u6d41\u7a0b\uff0c\u6838\u5fc3acquire(int arg)\u65b9\u6cd5\u8c03\u7528\u6d41\u7a0b<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u53ef\u4ee5\u770b\u51fa\u9501\u7684\u83b7\u53d6\u6d41\u7a0b<\/span><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">AQS\u7ef4\u62a4\u4e00\u4e2a\u540c\u6b65\u961f\u5217\uff0c\u83b7\u53d6\u72b6\u6001\u5931\u8d25\u7684\u7ebf\u7a0b\u90fd\u4f1a\u52a0\u5165\u5230\u961f\u5217\u4e2d\u8fdb\u884c\u81ea\u65cb\uff0c\u79fb\u51fa\u961f\u5217\u6216\u505c\u6b62\u81ea\u65cb\u7684\u6761\u4ef6\u662f\u524d\u9a71\u8282\u70b9\u4e3a\u5934\u8282\u70b9\u5207\u6210\u529f\u83b7\u53d6\u4e86\u540c\u6b65\u72b6\u6001\u3002<\/span><\/p>\n<\/blockquote>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u800c\u6bd4\u8f83\u53e6\u4e00\u6bb5\u975e\u516c\u5e73\u9501\u7c7bNonfairSync\u53ef\u4ee5\u53d1\u73b0\uff0c\u63a7\u5236\u516c\u5e73\u548c\u975e\u516c\u5e73\u7684\u5173\u952e\u4ee3\u7801\uff0c\u5728\u4e8ehasQueuedPredecessors\u65b9\u6cd5\u3002<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"java\">static final class NonfairSync extends Sync{\n        private static final long serialVersionUID = 7316153563782823691L;\n        \/**\n         * Performs lock.  Try immediate barge, backing up to normal\n         * acquire on failure.\n         *\/\n        final void lock() {\n            if (compareAndSetState(0, 1))\n                setExclusiveOwnerThread(Thread.currentThread());\n            else\n                acquire(1);\n        }\n        protected final boolean tryAcquire(int acquires) {\n            return nonfairTryAcquire(acquires);\n        }\n    }<\/pre>\n<\/section>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">NonfairSync\u51cf\u5c11\u4e86\u4e86hasQueuedPredecessors\u5224\u65ad\u6761\u4ef6\uff0c\u8be5\u65b9\u6cd5\u7684\u4f5c\u7528\u5c31\u662f<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u67e5\u770b\u540c\u6b65\u961f\u5217\u4e2d\u5f53\u524d\u8282\u70b9\u662f\u5426\u6709\u524d\u9a71\u8282\u70b9\uff0c\u5982\u679c\u6709\u6bd4\u5f53\u524d\u7ebf\u7a0b\u66f4\u65e9\u8bf7\u6c42\u83b7\u53d6\u9501\u5219\u8fd4\u56detrue\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u4fdd\u8bc1\u6bcf\u6b21\u90fd\u53d6\u961f\u5217\u7684\u7b2c\u4e00\u4e2a\u8282\u70b9\uff08\u7ebf\u7a0b\uff09\u6765\u83b7\u53d6\u9501\uff0c\u8fd9\u5c31\u662f\u516c\u5e73\u89c4\u5219<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u4e3a\u4ec0\u4e48JUC\u4ee5\u9ed8\u8ba4\u975e\u516c\u5e73\u9501\u5462\uff1f<\/span><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u56e0\u4e3a\u5f53\u4e00\u4e2a\u7ebf\u7a0b\u8bf7\u6c42\u9501\u65f6\uff0c\u53ea\u8981\u83b7\u53d6\u6765\u540c\u6b65\u72b6\u6001\u5373\u6210\u529f\u83b7\u53d6\u3002\u5728\u6b64\u524d\u63d0\u4e0b\uff0c\u521a\u91ca\u653e\u7684\u7ebf\u7a0b\u518d\u6b21\u83b7\u53d6\u540c\u6b65\u72b6\u6001\u7684\u51e0\u7387\u4f1a\u975e\u5e38\u5927\uff0c\u4f7f\u5f97\u5176\u4ed6\u7ebf\u7a0b\u53ea\u80fd\u5728\u540c\u6b65\u961f\u5217\u4e2d\u7b49\u5f85\u3002\u4f46\u8fd9\u6837\u5e26\u6765\u7684\u597d\u5904\u662f\uff0c\u975e\u516c\u5e73\u9501\u5927\u5927\u51cf\u5c11\u4e86\u7cfb\u7edf\u7ebf\u7a0b\u4e0a\u4e0b\u6587\u7684\u5207\u6362\u5f00\u9500\u3002<\/span><\/p>\n<\/blockquote>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u53ef\u89c1\u516c\u5e73\u7684\u4ee3\u4ef7\u662f\u6027\u80fd\u4e0e\u541e\u5410\u91cf\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">Redis\u91cc\u6ca1\u6709AQS\uff0c\u4f46\u662f\u6709List\u548czSet\uff0c\u770b\u770bRedisson\u662f\u600e\u4e48\u5b9e\u73b0\u516c\u5e73\u7684\u3002<\/span><\/p>\n<h3 style=\"text-align: left;\" data-id=\"heading-13\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">RedissonFairLock<\/span><\/strong><\/h3>\n<h3 style=\"text-align: left;\" data-id=\"heading-13\">RedissonFairLock \u7528\u6cd5\u4f9d\u7136\u5f88\u7b80\u5355<\/h3>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">RLock fairLock = redissonClient.getFairLock(lockName);<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">fairLock.lock();<\/span><\/p>\n<\/blockquote>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">RedissonFairLock\u7ee7\u627f\u81eaRedissonLock\uff0c\u540c\u6837\u4e00\u8def\u5411\u4e0b\u627e\u5230\u52a0\u9501\u5b9e\u73b0\u65b9\u6cd5tryLockInnerAsync\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u8fd9\u91cc\u67092\u6bb5\u5197\u957f\u7684Lua\uff0c\u4f46\u662fDebug\u53d1\u73b0\uff0c\u516c\u5e73\u9501\u7684\u5165\u53e3\u5728 command == RedisCommands.EVAL_LONG \u4e4b\u540e\uff0c\u6b64\u6bb5Lua\u8f83\u957f\uff0c\u53c2\u6570\u4e5f\u591a\uff0c\u6211\u4eec\u7740\u91cd\u5206\u6790Lua\u7684\u5b9e\u73b0\u89c4\u5219<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u53c2\u6570<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"makefile\">-- lua\u4e2d\u7684\u51e0\u4e2a\u53c2\u6570\nKEYS = Arrays.&lt;Object&gt;asList(getName(), threadsQueueName, timeoutSetName)\nKEYS[1]: lock_name, \u9501\u540d\u79f0                   \nKEYS[2]: \"redisson_lock_queue:{xxx}\"  \u7ebf\u7a0b\u961f\u5217\nKEYS[3]: \"redisson_lock_timeout:{xxx}\"  \u7ebf\u7a0bid\u5bf9\u5e94\u7684\u8d85\u65f6\u96c6\u5408\nARGV =  internalLockLeaseTime, getLockName(threadId), currentTime + threadWaitTime, currentTime\nARGV[1]: \"{leaseTime}\" \u8fc7\u671f\u65f6\u95f4\nARGV[2]: \"{Redisson.UUID}:{threadId}\"   \nARGV[3] = \u5f53\u524d\u65f6\u95f4 + \u7ebf\u7a0b\u7b49\u5f85\u65f6\u95f4:\uff0810:00:00\uff09 + 5000\u6beb\u79d2 = 10:00:05\nARGV[4] = \u5f53\u524d\u65f6\u95f4\uff0810:00:00\uff09  \u90e8\u7f72\u670d\u52a1\u5668\u65f6\u95f4\uff0c\u975eredis-server\u670d\u52a1\u5668\u65f6\u95f4<\/pre>\n<\/section>\n<pre style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u516c\u5e73\u9501\u5b9e\u73b0\u7684Lua\u811a\u672c<\/span><\/pre>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"ruby\">-- 1.\u6b7b\u5faa\u73af\u6e05\u9664\u8fc7\u671fkey\nwhile true do \n  -- \u83b7\u53d6\u5934\u8282\u70b9\n    local firstThreadId2 = redis.call('lindex', KEYS[2], 0);\n    -- \u9996\u6b21\u83b7\u53d6\u5fc5\u7a7a\u8df3\u51fa\u5faa\u73af\n  if firstThreadId2 == false then \n    break;\n  end;\n  -- \u6e05\u9664\u8fc7\u671fkey\n  local timeout = tonumber(redis.call('zscore', KEYS[3], firstThreadId2));\n  if timeout &lt;= tonumber(ARGV[4]) then\n    redis.call('zrem', KEYS[3], firstThreadId2);\n    redis.call('lpop', KEYS[2]);\n  else\n    break;\n  end;\nend;\n-- 2.\u4e0d\u5b58\u5728\u8be5\u9501 &amp;&amp; \uff08\u4e0d\u5b58\u5728\u7ebf\u7a0b\u7b49\u5f85\u961f\u5217 || \u5b58\u5728\u7ebf\u7a0b\u7b49\u5f85\u961f\u5217\u800c\u4e14\u7b2c\u4e00\u4e2a\u8282\u70b9\u5c31\u662f\u6b64\u7ebf\u7a0bID)\uff0c\u52a0\u9501\u90e8\u5206\u4e3b\u8981\u903b\u8f91\nif (redis.call('exists', KEYS[1]) == 0) and \n  ((redis.call('exists', KEYS[2]) == 0)  or (redis.call('lindex', KEYS[2], 0) == ARGV[2])) then\n  -- \u5f39\u51fa\u961f\u5217\u4e2d\u7ebf\u7a0bid\u5143\u7d20\uff0c\u5220\u9664Zset\u4e2d\u8be5\u7ebf\u7a0bid\u5bf9\u5e94\u7684\u5143\u7d20\n  redis.call('lpop', KEYS[2]);\n  redis.call('zrem', KEYS[3], ARGV[2]);\n  local keys = redis.call('zrange', KEYS[3], 0, -1);\n  -- \u904d\u5386zSet\u6240\u6709key\uff0c\u5c06key\u7684\u8d85\u65f6\u65f6\u95f4(score) - \u5f53\u524d\u65f6\u95f4ms\n  for i = 1, #keys, 1 do \n    redis.call('zincrby', KEYS[3], -tonumber(ARGV[3]), keys[i]);\n  end;\n    -- \u52a0\u9501\u8bbe\u7f6e\u9501\u8fc7\u671f\u65f6\u95f4\n  redis.call('hset', KEYS[1], ARGV[2], 1);\n  redis.call('pexpire', KEYS[1], ARGV[1]);\n  return nil;\nend;\n-- 3.\u7ebf\u7a0b\u5b58\u5728\uff0c\u91cd\u5165\u5224\u65ad\nif redis.call('hexists', KEYS[1], ARGV[2]) == 1 then\n  redis.call('hincrby', KEYS[1], ARGV[2],1);\n  redis.call('pexpire', KEYS[1], ARGV[1]);\n  return nil;\nend;\n-- 4.\u8fd4\u56de\u5f53\u524d\u7ebf\u7a0b\u5269\u4f59\u5b58\u6d3b\u65f6\u95f4\nlocal timeout = redis.call('zscore', KEYS[3], ARGV[2]);\n    if timeout ~= false then\n  -- \u8fc7\u671f\u65f6\u95f4timeout\u7684\u503c\u5728\u4e0b\u65b9\u8bbe\u7f6e\uff0c\u6b64\u5904\u7684\u51cf\u6cd5\u7b97\u51fa\u7684\u4f9d\u65e7\u662f\u5f53\u524d\u7ebf\u7a0b\u7684ttl\n  return timeout - tonumber(ARGV[3]) - tonumber(ARGV[4]);\nend;\n-- 5.\u5c3e\u8282\u70b9\u5269\u4f59\u5b58\u6d3b\u65f6\u95f4\nlocal lastThreadId = redis.call('lindex', KEYS[2], -1);\nlocal ttl;\n-- \u5c3e\u8282\u70b9\u4e0d\u7a7a &amp;&amp; \u5c3e\u8282\u70b9\u975e\u5f53\u524d\u7ebf\u7a0b\nif lastThreadId ~= false and lastThreadId ~= ARGV[2] then\n  -- \u8ba1\u7b97\u961f\u5c3e\u8282\u70b9\u5269\u4f59\u5b58\u6d3b\u65f6\u95f4\n  ttl = tonumber(redis.call('zscore', KEYS[3], lastThreadId)) - tonumber(ARGV[4]);\nelse\n  -- \u83b7\u53d6lock_name\u5269\u4f59\u5b58\u6d3b\u65f6\u95f4\n  ttl = redis.call('pttl', KEYS[1]);\nend;\n-- 6.\u672b\u5c3e\u6392\u961f\n-- zSet \u8d85\u65f6\u65f6\u95f4\uff08score\uff09\uff0c\u5c3e\u8282\u70b9ttl + \u5f53\u524d\u65f6\u95f4 + 5000ms + \u5f53\u524d\u65f6\u95f4\uff0c\u65e0\u5219\u65b0\u589e\uff0c\u6709\u5219\u66f4\u65b0\n-- \u7ebf\u7a0bid\u653e\u5165\u961f\u5217\u5c3e\u90e8\u6392\u961f\uff0c\u65e0\u5219\u63d2\u5165\uff0c\u6709\u5219\u4e0d\u518d\u63d2\u5165\nlocal timeout = ttl + tonumber(ARGV[3]) + tonumber(ARGV[4]);\nif redis.call('zadd', KEYS[3], timeout, ARGV[2]) == 1 then\n  redis.call('rpush', KEYS[2], ARGV[2]);\nend;\nreturn ttl;<\/pre>\n<\/section>\n<h4 style=\"text-align: left;\" data-id=\"heading-14\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">1.\u516c\u5e73\u9501\u52a0\u9501\u6b65\u9aa4<\/span><\/strong><\/h4>\n<h4 style=\"text-align: left;\" data-id=\"heading-14\"><span style=\"font-family: arial, helvetica, sans-serif; letter-spacing: 0.034em;\">\u901a\u8fc7\u4ee5\u4e0aLua\uff0c\u53ef\u4ee5\u53d1\u73b0\uff0clua\u64cd\u4f5c\u7684\u5173\u952e\u7ed3\u6784\u662f\u5217\u8868\uff08list\uff09\u548c\u6709\u5e8f\u96c6\u5408\uff08zSet\uff09\u3002<\/span><\/h4>\n<h4 style=\"text-align: left;\" data-id=\"heading-14\">\u5176\u4e2dlist\u7ef4\u62a4\u4e86\u4e00\u4e2a\u7b49\u5f85\u7684\u7ebf\u7a0b\u961f\u5217redisson_lock_queue:{xxx}\uff0czSet\u7ef4\u62a4\u4e86\u4e00\u4e2a\u7ebf\u7a0b\u8d85\u65f6\u60c5\u51b5\u7684\u6709\u5e8f\u96c6\u5408redisson_lock_timeout:{xxx}\uff0c\u5c3d\u7ba1lua\u8f83\u957f\uff0c\u4f46\u662f\u53ef\u4ee5\u62c6\u5206\u4e3a6\u4e2a\u6b65\u9aa4<\/h4>\n<ol class=\"list-paddingleft-1\">\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u961f\u5217\u6e05\u7406<\/span><\/p>\n<\/li>\n<\/ol>\n<ul class=\"list-paddingleft-1\">\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u4fdd\u8bc1\u961f\u5217\u4e2d\u53ea\u6709\u672a\u8fc7\u671f\u7684\u7b49\u5f85\u7ebf\u7a0b<\/span><\/p>\n<\/li>\n<\/ul>\n<ol class=\"list-paddingleft-1\" start=\"3\">\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u9996\u6b21\u52a0\u9501<\/span><\/p>\n<\/li>\n<\/ol>\n<ul class=\"list-paddingleft-1\">\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">hset\u52a0\u9501\uff0cpexpire\u8fc7\u671f\u65f6\u95f4<\/span><\/p>\n<\/li>\n<\/ul>\n<ol class=\"list-paddingleft-1\" start=\"5\">\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u91cd\u5165\u5224\u65ad<\/span><\/p>\n<\/li>\n<\/ol>\n<ul class=\"list-paddingleft-1\">\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u6b64\u5904\u540c\u53ef\u91cd\u5165\u9501lua<\/span><\/p>\n<\/li>\n<\/ul>\n<ol class=\"list-paddingleft-1\" start=\"7\">\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u8fd4\u56dettl<\/span><\/p>\n<\/li>\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u8ba1\u7b97\u5c3e\u8282\u70b9ttl<\/span><\/p>\n<\/li>\n<\/ol>\n<ul class=\"list-paddingleft-1\">\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u521d\u59cb\u503c\u4e3a\u9501\u7684\u5269\u4f59\u8fc7\u671f\u65f6\u95f4<\/span><\/p>\n<\/li>\n<\/ul>\n<ol class=\"list-paddingleft-1\" start=\"10\">\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u672b\u5c3e\u6392\u961f<\/span><\/p>\n<\/li>\n<\/ol>\n<ul class=\"list-paddingleft-1\">\n<li style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">ttl + 2 * currentTime + waitTime\u662fscore\u7684\u9ed8\u8ba4\u503c\u8ba1\u7b97\u516c\u5f0f<\/span><\/p>\n<\/li>\n<\/ul>\n<h4 style=\"text-align: left;\" data-id=\"heading-15\"><strong><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">2.\u6a21\u62df<\/span><\/strong><\/h4>\n<h4 style=\"text-align: left;\" data-id=\"heading-15\"><\/h4>\n<h4 style=\"text-align: left;\" data-id=\"heading-15\">\u5982\u679c\u6a21\u62df\u4ee5\u4e0b\u987a\u5e8f\uff0c\u5c31\u4f1a\u660e\u4e86redisson\u516c\u5e73\u9501\u6574\u4e2a\u52a0\u9501\u6d41\u7a0b<\/h4>\n<h4 style=\"text-align: left;\" data-id=\"heading-15\"><\/h4>\n<h4 style=\"text-align: left;\" data-id=\"heading-15\">\u5047\u8bbe t1 10:00:00 &lt; t2 10:00:10 &lt; t3 10:00:20<\/h4>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">t1\uff1a\u5f53\u7ebf\u7a0b1\u521d\u6b21\u83b7\u53d6\u9501<\/span><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">1.\u7b49\u5f85\u961f\u5217\u65e0\u5934\u8282\u70b9\uff0c\u8df3\u51fa\u6b7b\u5faa\u73af-&gt;2<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">2.\u4e0d\u5b58\u5728\u8be5\u9501 &amp;&amp; \u4e0d\u5b58\u5728\u7ebf\u7a0b\u7b49\u5f85\u961f\u5217 \u6210\u7acb<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">2.1 lpop\u548czerm\u3001zincrby\u90fd\u662f\u65e0\u6548\u64cd\u4f5c\uff0c\u53ea\u6709\u52a0\u9501\u751f\u6548\uff0c\u8bf4\u660e\u662f\u9996\u6b21\u52a0\u9501\uff0c\u52a0\u9501\u540e\u8fd4\u56denil<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u52a0\u9501\u6210\u529f\uff0c\u7ebf\u7a0b1\u83b7\u53d6\u5230\u9501\uff0c\u7ed3\u675f<\/span><\/p>\n<\/blockquote>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">t2\uff1a\u7ebf\u7a0b2\u5c1d\u8bd5\u83b7\u53d6\u9501\uff08\u7ebf\u7a0b1\u672a\u91ca\u653e\u9501\uff09<\/span><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">1.\u7b49\u5f85\u961f\u5217\u65e0\u5934\u8282\u70b9\uff0c\u8df3\u51fa\u6b7b\u5faa\u73af-&gt;2<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">2.\u4e0d\u5b58\u5728\u8be5\u9501 \u4e0d\u6210\u7acb-&gt;3<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">3.\u975e\u91cd\u5165\u7ebf\u7a0b -&gt;4<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">4.score\u65e0\u503c -&gt;5<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">5.\u5c3e\u8282\u70b9\u4e3a\u7a7a\uff0c\u8bbe\u7f6ettl\u521d\u59cb\u503c\u4e3alock_name\u7684ttl -&gt; 6<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">6.\u6309\u7167ttl + waitTime + currentTime + currentTime \u6765\u8bbe\u7f6ezSet\u8d85\u65f6\u65f6\u95f4score\uff0c\u5e76\u4e14\u52a0\u5165\u7b49\u5f85\u961f\u5217\uff0c\u7ebf\u7a0b2\u4e3a\u5934\u8282\u70b9<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">score = 20S + 5000ms + 10:00:10 + 10:00:10 = 10:00:35 + 10:00:10<\/span><\/p>\n<\/blockquote>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">t3\uff1a\u7ebf\u7a0b3\u5c1d\u8bd5\u83b7\u53d6\u9501\uff08\u7ebf\u7a0b1\u672a\u91ca\u653e\u9501\uff09<\/span><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">1.\u7b49\u5f85\u961f\u5217\u6709\u5934\u8282\u70b9<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">1.1\u672a\u8fc7\u671f-&gt;2<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">2.\u4e0d\u5b58\u5728\u8be5\u9501\u4e0d\u6210\u7acb-&gt;3<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">3.\u975e\u91cd\u5165\u7ebf\u7a0b-&gt;4<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">4.score\u65e0\u503c -&gt;5<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">5.\u5c3e\u8282\u70b9\u4e0d\u4e3a\u7a7a &amp;&amp; \u5c3e\u8282\u70b9\u7ebf\u7a0b\u4e3a2\uff0c\u975e\u5f53\u524d\u7ebf\u7a0b<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">5.1\u53d6\u51fa\u4e4b\u524d\u8bbe\u7f6e\u7684score\uff0c\u51cf\u53bb\u5f53\u524d\u65f6\u95f4\uff1attl = score - currentTime -&gt;6<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">6.\u6309\u7167ttl + waitTime + currentTime + currentTime \u6765\u8bbe\u7f6ezSet\u8d85\u65f6\u65f6\u95f4score\uff0c\u5e76\u4e14\u52a0\u5165\u7b49\u5f85\u961f\u5217<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">score = 10S + 5000ms + 10:00:20 + 10:00:20 = 10:00:35 + 10:00:20<\/span><\/p>\n<\/blockquote>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u5982\u6b64\u4e00\u6765\uff0c\u4e09\u4e2a\u9700\u8981\u62a2\u593a\u4e00\u628a\u9501\u7684\u7ebf\u7a0b\uff0c\u5b8c\u6210\u4e86\u4e00\u6b21\u6392\u961f\uff0c\u5728list\u4e2d\u6392\u5217\u4ed6\u4eec\u7b49\u5f85\u7ebf\u7a0bid\uff0c\u5728zSet\u4e2d\u5b58\u653e\u8fc7\u671f\u65f6\u95f4\uff08\u4fbf\u4e8e\u6392\u5217\u4f18\u5148\u7ea7\uff09\u3002\u5176\u4e2d\u8fd4\u56dettl\u7684\u7ebf\u7a0b2\u5ba2\u6237\u7aef\u3001\u7ebf\u7a0b3\u5ba2\u6237\u7aef\u5c06\u4f1a\u4e00\u76f4\u6309\u4e00\u5b9a\u95f4\u9694\u81ea\u65cb\u91cd\u590d\u6267\u884c\u8be5\u6bb5Lua\uff0c\u5c1d\u8bd5\u52a0\u9501\uff0c\u5982\u6b64\u4e00\u6765\u4fbf\u548cAQS\u6709\u4e86\u5f02\u66f2\u540c\u5de5\u4e4b\u5904\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u800c\u5f53\u7ebf\u7a0b1\u91ca\u653e\u9501\u4e4b\u540e\uff08\u8fd9\u91cc\u4f9d\u65e7\u6709\u901a\u8fc7Pub\/Sub\u53d1\u5e03\u89e3\u9501\u6d88\u606f\uff0c\u901a\u77e5\u5176\u4ed6\u7ebf\u7a0b\u83b7\u53d6\uff09<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">10:00:30 \u7ebf\u7a0b2\u5c1d\u8bd5\u83b7\u53d6\u9501\uff08\u7ebf\u7a0b1\u5df2\u91ca\u653e\u9501\uff09<\/span><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">1.\u7b49\u5f85\u961f\u5217\u6709\u5934\u8282\u70b9\uff0c\u672a\u8fc7\u671f-&gt;2<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">2.\u4e0d\u5b58\u5728\u8be5\u9501 &amp; \u7b49\u5f85\u961f\u5217\u5934\u8282\u70b9\u662f\u5f53\u524d\u7ebf\u7a0b \u6210\u7acb<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">2.1\u5220\u9664\u5f53\u524d\u7ebf\u7a0b\u7684\u961f\u5217\u4fe1\u606f\u548czSet\u4fe1\u606f\uff0c\u8d85\u65f6\u65f6\u95f4\u4e3a\uff1a<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u7ebf\u7a0b2 10:00:35 + 10:00:10 - 10:00:30 = 10:00:15<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u7ebf\u7a0b3 10:00:35 + 10:00:20 - 10:00:30 = 10:00:25<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">2.2\u7ebf\u7a0b2\u83b7\u53d6\u5230\u9501\uff0c\u91cd\u65b0\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 15px;\">\u52a0\u9501\u6210\u529f\uff0c\u7ebf\u7a0b2\u83b7\u53d6\u5230\u9501\uff0c\u7ed3\u675f<\/span><\/p>\n<\/blockquote>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u6392\u961f\u7ed3\u6784\u5982\u56fe<\/span><\/p>\n<p style=\"text-align: left;\"><img class=\"rich_pages wxw-img lazyload\" data-ratio=\"0.387037037037037\" data-type=\"other\" data-w=\"1080\" \/><noscript><img class=\"rich_pages wxw-img\" data-ratio=\"0.387037037037037\" data-type=\"other\" data-w=\"1080\" \/><\/noscript><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u516c\u5e73\u9501\u7684\u91ca\u653e\u811a\u672c\u548c\u91cd\u5165\u9501\u7c7b\u4f3c\uff0c\u591a\u4e86\u4e00\u6b65\u52a0\u9501\u5f00\u5934\u7684\u6e05\u7406\u8fc7\u671fkey\u7684while true\u903b\u8f91\uff0c\u5728\u6b64\u4e0d\u518d\u5c55\u5f00\u7bc7\u5e45\u63cf\u8ff0\u3002<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u7531\u4e0a\u53ef\u4ee5\u770b\u51fa\uff0cRedisson\u516c\u5e73\u9501\u7684\u73a9\u6cd5\u7c7b\u4f3c\u4e8e\u5ef6\u8fdf\u961f\u5217\u7684\u73a9\u6cd5\uff0c\u6838\u5fc3\u90fd\u5728Redis\u7684List\u548czSet\u7ed3\u6784\u7684\u642d\u914d\uff0c\u4f46\u53c8\u501f\u9274\u4e86AQS\u5b9e\u73b0\uff0c\u5728\u5b9a\u65f6\u5224\u65ad\u5934\u8282\u70b9\u4e0a\u5982\u51fa\u4e00\u8f99\uff08watchDog\uff09\uff0c\u4fdd\u8bc1\u4e86\u9501\u7684\u7ade\u4e89\u516c\u5e73\u548c\u4e92\u65a5\u3002\u5e76\u53d1\u573a\u666f\u4e0b\uff0clua\u811a\u672c\u91cc\uff0czSet\u7684score\u5f88\u597d\u5730\u89e3\u51b3\u4e86\u987a\u5e8f\u63d2\u5165\u7684\u95ee\u9898\uff0c\u6392\u5217\u597d\u4f18\u5148\u7ea7\u3002\u5e76\u4e14\u4e3a\u4e86\u9632\u6b62\u56e0\u5f02\u5e38\u800c\u9000\u51fa\u7684\u7ebf\u7a0b\u65e0\u6cd5\u6e05\u7406\uff0c\u6bcf\u6b21\u8bf7\u6c42\u90fd\u4f1a\u5224\u65ad\u5934\u8282\u70b9\u7684\u8fc7\u671f\u60c5\u51b5\u7ed9\u4e88\u6e05\u7406\uff0c\u6700\u540e\u91ca\u653e\u65f6\u901a\u8fc7CHANNEL\u901a\u77e5\u8ba2\u9605\u7ebf\u7a0b\u53ef\u4ee5\u6765\u83b7\u53d6\u9501\uff0c\u91cd\u590d\u4e00\u5f00\u59cb\u7684\u6b65\u9aa4\uff0c\u987a\u5229\u4ea4\u63a5\u5230\u4e0b\u4e00\u4e2a\u987a\u5e8f\u7ebf\u7a0b\u3002<\/span><\/p>\n<h1 style=\"text-align: left;\" data-id=\"heading-16\"><span style=\"font-size: 18px;\"><strong><span style=\"font-family: arial, helvetica, sans-serif; color: #df7766;\">\u516d\u3001\u603b\u7ed3<\/span><\/strong><\/span><\/h1>\n<h1 style=\"text-align: left;\" data-id=\"heading-16\">Redisson\u6574\u4f53\u5b9e\u73b0\u5206\u5e03\u5f0f\u52a0\u89e3\u9501\u6d41\u7a0b\u7684\u5b9e\u73b0\u7a0d\u663e\u590d\u6742\uff0c\u4f5c\u8005Rui Gu\u5bf9Netty\u548cJUC\u3001Redis\u7814\u7a76\u6df1\u5165\uff0c\u5229\u7528\u4e86\u5f88\u591a\u9ad8\u7ea7\u7279\u6027\u548c\u8bed\u4e49\uff0c\u503c\u5f97\u6df1\u5165\u5b66\u4e60\uff0c\u672c\u6b21\u4ecb\u7ecd\u4e5f\u53ea\u662f\u5355\u673aRedis\u4e0b\u9501\u5b9e\u73b0\uff0cRedisson\u4e5f\u63d0\u4f9b\u4e86\u591a\u673a\u60c5\u51b5\u4e0b\u7684\u8054\u9501\uff08<span style=\"letter-spacing: 0.034em; font-family: arial, helvetica, sans-serif;\">MultiLock<\/span><span style=\"letter-spacing: 0.034em; font-family: arial, helvetica, sans-serif;\">)\u548c\u5b98\u65b9\u63a8\u8350\u7684\u7ea2\u9501\uff08<\/span><span style=\"letter-spacing: 0.034em; font-family: arial, helvetica, sans-serif;\">RedLock<\/span><span style=\"letter-spacing: 0.034em; font-family: arial, helvetica, sans-serif;\">\uff09\uff0c\u4e0b\u4e00\u7ae0\u518d\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/span><\/h1>\n<p style=\"text-align: left;\"><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">\u6240\u4ee5\uff0c\u5f53\u4f60\u771f\u7684\u9700\u8981\u5206\u5e03\u5f0f\u9501\u65f6\uff0c\u4e0d\u59a8\u5148\u6765Redisson\u91cc\u627e\u627e\u3002<\/span><\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113252188.jpeg\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-galleryid=\"\" data-ratio=\"0.44642857142857145\" data-s=\"300,640\" data-type=\"jpeg\" data-w=\"560\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113252188.jpeg\" data-galleryid=\"\" data-ratio=\"0.44642857142857145\" data-s=\"300,640\" data-type=\"jpeg\" data-w=\"560\" \/><\/noscript><\/p>\n<section style=\"margin-right: 8px; margin-bottom: 16px; margin-left: 8px; outline: 0px; letter-spacing: 0.544px; text-wrap: wrap; background-color: #ffffff; font-size: 15px; widows: 1; word-spacing: 2px; color: #222222; font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-weight: bold; orphans: 4; text-align: left; caret-color: #333333; line-height: 1.75em;\"><span style=\"outline: 0px; font-family: arial, helvetica, sans-serif;\"><strong style=\"outline: 0px; color: #3f3f3f; font-size: 16px; letter-spacing: 0.544px;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" style=\"outline: 0px; vertical-align: text-bottom; display: inline-block; visibility: visible !important; width: 20px !important;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113254360.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" width=\"20px\" data-ratio=\"1\" data-type=\"png\" data-w=\"64\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"outline: 0px; vertical-align: text-bottom; display: inline-block; visibility: visible !important; width: 20px !important;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113254360.png\" width=\"20px\" data-ratio=\"1\" data-type=\"png\" data-w=\"64\" \/><\/noscript>\u70ed\u95e8\u63a8\u8350<\/strong><\/span><\/section>\n<ul class=\"list-paddingleft-1\" style=\"outline: 0px; letter-spacing: 0.544px; text-wrap: wrap; width: 577.412px; background-color: #ffffff; font-size: 15px; widows: 1; word-spacing: 2px; color: #222222; font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-weight: bold; orphans: 4; text-align: left; caret-color: #333333;\">\n<li style=\"outline: 0px; font-family: arial, helvetica, sans-serif; color: #0052ff; font-size: 14px;\">\n<section style=\"outline: 0px; line-height: 2em;\">\n<p style=\"outline: 0px; line-height: 2em;\"><a style=\"color: #0052ff;\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=Mzg5MzU1Nzc1Mw==&amp;mid=2247502306&amp;idx=1&amp;sn=b659fd5a19209387469f3455870f5580&amp;chksm=c02f8774f7580e623c199b367af5fd823f72db3c25564f44420f71e0652de4c9e278e73e8fa9&amp;scene=21#wechat_redirect\" target=\"_blank\" rel=\"noopener\" data-itemshowtype=\"0\" data-linktype=\"2\" rel=\"nofollow\" ><span style=\"color: #0052ff;\">\u4e3a\u4ec0\u4e48\u4f01\u4e1a\u559c\u6b22\u7528cenOS\u800c\u4e0d\u662fubuntu\uff1f<\/span><\/a><\/p>\n<\/section>\n<\/li>\n<li style=\"outline: 0px; font-family: arial, helvetica, sans-serif; color: #0052ff; font-size: 14px;\">\n<section style=\"outline: 0px; line-height: 2em;\">\n<p style=\"outline: 0px; line-height: 2em;\"><a style=\"color: #0052ff;\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=Mzg5MzU1Nzc1Mw==&amp;mid=2247502292&amp;idx=1&amp;sn=7bd901f04dce5ef4a4ff224103fbe3bb&amp;chksm=c02f8742f7580e54bac3bbc2677e5be7bba45d8ea1fd5258a6c2f17a1206fbf8ae9a27fe9b28&amp;scene=21#wechat_redirect\" target=\"_blank\" rel=\"noopener\" data-itemshowtype=\"0\" data-linktype=\"2\" rel=\"nofollow\" ><span style=\"color: #0052ff;\">SpringBoot \u5b9e\u73b0\u5ba1\u6838\u529f\u80fd~<\/span><\/a><\/p>\n<\/section>\n<\/li>\n<li style=\"outline: 0px; font-family: arial, helvetica, sans-serif; color: #0052ff; font-size: 14px;\">\n<section style=\"outline: 0px; line-height: 2em;\">\n<p style=\"outline: 0px; line-height: 2em;\"><a style=\"color: #0052ff;\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=Mzg5MzU1Nzc1Mw==&amp;mid=2247502267&amp;idx=1&amp;sn=c16e22eed012e8189547d78b6826c038&amp;chksm=c02f872df7580e3b3cfa3d2c7085e7278157a02b4b2371497461f1d63c28fe1b03ed4aa1a8fe&amp;scene=21#wechat_redirect\" target=\"_blank\" rel=\"noopener\" data-itemshowtype=\"0\" data-linktype=\"2\" rel=\"nofollow\" ><span style=\"color: #0052ff;\">\u95f7\u58f0\u5e72\u5927\u4e8b\uff01\u817e\u8baf\u6350\u4e86\u4e2aJDK\uff01<\/span><\/a><\/p>\n<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin-bottom: 0px; outline: 0px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-wrap: wrap; background-color: #ffffff; color: #3f3f3f; font-size: 15px; widows: 1; word-spacing: 2px; caret-color: #ff0000; line-height: 2em; text-align: left;\"><img decoding=\"async\" class=\"rich_pages wxw-img __bg_gif lazyload\" style=\"outline: 0px; visibility: visible !important; width: 578px !important;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113255527.gif\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-ratio=\"0.2777777777777778\" data-w=\"1080\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img __bg_gif\" style=\"outline: 0px; visibility: visible !important; width: 578px !important;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113255527.gif\" data-ratio=\"0.2777777777777778\" data-w=\"1080\" \/><\/noscript><\/p>\n<p style=\"display: none;\">\n<blockquote><p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7: \u7a0b\u5e8f\u5a9b\u5c71\u6942<\/p><\/blockquote>\n<\/div>\n<p>[the_ad_placement id=\"content-placement-after-3rd-paragraph\"]<\/p>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff1a\u957f\u6c5f\u6c34\u9762\u5199\u65e5\u8bb0\u94fe\u63a5\uff1ahttps:\/\/juejin.cn\/post\/6961380552519712798 \u4e00\u3001Redisso &#8230;<\/p>\n","protected":false},"author":1,"featured_media":2649,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-2653","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-redis"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113246775-150x150.jpeg","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113252188.jpeg","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113246775-300x128.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113246775-1024x435.jpeg","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113252188.jpeg","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113246775-300x128.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113246775-1024x435.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113246775.jpeg","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113252188.jpeg","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113252188.jpeg","id":"image1"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113254360.png","id":"image2"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113254360.png","id":"image3"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113255527.gif","id":"image4"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/07\/20230705113255527.gif","id":"image5"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Redis","post_date":"2023-07-05","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":813,"next_post_id":3054,"next_post_title":"\u4e00\u4e2a\u6ce8\u89e3\u4f18\u96c5\u7684\u5b9e\u73b0Redisson\u5206\u5e03\u5f0f\u9501","previous_post_id":1744,"previous_post_title":"\u6df1\u5165\u5206\u6790Redis\u7684\u4e94\u79cd\u6570\u636e\u7ed3\u6784\u53ca\u5b9e\u73b0\u539f\u7406\u3002","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/2653","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=2653"}],"version-history":[{"count":0,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/2653\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/2649"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}