{"id":201661,"date":"2025-05-10T08:26:20","date_gmt":"2025-05-10T00:26:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201661\/"},"modified":"2025-05-10T08:26:20","modified_gmt":"2025-05-10T00:26:20","slug":"%e8%af%a6%e8%a7%a3-redis-%e5%88%86%e5%b8%83%e5%bc%8f%e9%94%81%e7%9a%84%e4%ba%94%e7%a7%8d%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201661\/","title":{"rendered":"\u8be6\u89e3 Redis \u5206\u5e03\u5f0f\u9501\u7684\u4e94\u79cd\u65b9\u6848"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u8be6\u89e3 Redis \u5206\u5e03\u5f0f\u9501\u7684\u4e94\u79cd\u65b9\u6848<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;font-family:\">\u300a\u8be6\u89e3 Redis \u5206\u5e03\u5f0f\u9501\u7684\u4e94\u79cd\u65b9\u6848\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;font-family:\"><span style=\"color: #FF6600;font-family:\">\u5206\u5e03\u5f0f\u3001Redis\u3001\u9501<\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;font-family:\">\u6570\u636e\u5e93<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p>\u672c\u5730\u52a0\u9501\u200b\u7684\u65b9\u5f0f\u5728\u5206\u5e03\u5f0f\u7684\u573a\u666f\u4e0b\u4e0d\u9002\u7528\uff0c\u6240\u4ee5\u672c\u6587\u6211\u4eec\u6765\u63a2\u8ba8\u4e0b\u5982\u4f55\u5f15\u5165\u5206\u5e03\u5f0f\u9501\u89e3\u51b3\u672c\u5730\u9501\u7684\u95ee\u9898\u3002\u672c\u7bc7\u6240\u6709\u4ee3\u7801\u548c\u4e1a\u52a1\u57fa\u4e8e\u6211\u7684\u5f00\u6e90\u9879\u76ee PassJava\u3002<\/p>\n<p>\u672c\u7bc7\u4e3b\u8981\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230410\/16811107236433b6c31e38d.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<h2>\u4e00\u3001\u672c\u5730\u9501\u7684\u95ee\u9898<\/h2>\n<p>\u9996\u5148\u6211\u4eec\u6765\u56de\u987e\u4e0b\u672c\u5730\u9501\u7684\u95ee\u9898\uff1a<\/p>\n<p>\u76ee\u524d\u9898\u76ee\u5fae\u670d\u52a1\u88ab\u62c6\u5206\u6210\u4e86\u56db\u4e2a\u5fae\u670d\u52a1\u3002\u524d\u7aef\u8bf7\u6c42\u8fdb\u6765\u65f6\uff0c\u4f1a\u88ab\u8f6c\u53d1\u5230\u4e0d\u540c\u7684\u5fae\u670d\u52a1\u3002\u5047\u5982\u524d\u7aef\u63a5\u6536\u4e86 10 W \u4e2a\u8bf7\u6c42\uff0c\u6bcf\u4e2a\u5fae\u670d\u52a1\u63a5\u6536 2.5 W \u4e2a\u8bf7\u6c42\uff0c\u5047\u5982\u7f13\u5b58\u5931\u6548\u4e86\uff0c\u6bcf\u4e2a\u5fae\u670d\u52a1\u5728\u8bbf\u95ee\u6570\u636e\u5e93\u65f6\u52a0\u9501\uff0c\u901a\u8fc7\u9501\uff08synchronzied\u200b&nbsp;\u6216&nbsp;lock\u200b\uff09\u6765\u9501\u4f4f\u81ea\u5df1\u7684\u7ebf\u7a0b\u8d44\u6e90\uff0c\u4ece\u800c\u9632\u6b62\u7f13\u5b58\u51fb\u7a7f\u3002<\/p>\n<p>\u8fd9\u662f\u4e00\u79cd\u672c\u5730\u52a0\u9501\u200b\u7684\u65b9\u5f0f\uff0c\u5728\u5206\u5e03\u5f0f\u60c5\u51b5\u4e0b\u4f1a\u5e26\u6765\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\uff1a\u6bd4\u5982\u670d\u52a1 A \u83b7\u53d6\u6570\u636e\u540e\uff0c\u66f4\u65b0\u7f13\u5b58 key =100\uff0c\u670d\u52a1 B \u4e0d\u53d7\u670d\u52a1 A \u7684\u9501\u9650\u5236\uff0c\u5e76\u53d1\u53bb\u66f4\u65b0\u7f13\u5b58 key = 99\uff0c\u6700\u540e\u7684\u7ed3\u679c\u53ef\u80fd\u662f 99 \u6216 100\uff0c\u4f46\u8fd9\u662f\u4e00\u79cd\u672a\u77e5\u7684\u72b6\u6001\uff0c\u4e0e\u671f\u671b\u7ed3\u679c\u4e0d\u4e00\u81f4\u3002\u6d41\u7a0b\u56fe\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230410\/16811107236433b6c3815b3.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<h2>\u4e8c\u3001\u4ec0\u4e48\u662f\u5206\u5e03\u5f0f\u9501<\/h2>\n<p>\u57fa\u4e8e\u4e0a\u9762\u672c\u5730\u9501\u7684\u95ee\u9898\uff0c\u6211\u4eec\u9700\u8981\u4e00\u79cd\u652f\u6301\u5206\u5e03\u5f0f\u96c6\u7fa4\u73af\u5883\u4e0b\u7684\u9501\uff1a\u67e5\u8be2 DB \u65f6\uff0c\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u8bbf\u95ee\uff0c\u5176\u4ed6\u7ebf\u7a0b\u90fd\u9700\u8981\u7b49\u5f85\u7b2c\u4e00\u4e2a\u7ebf\u7a0b\u91ca\u653e\u9501\u8d44\u6e90\u540e\uff0c\u624d\u80fd\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n<p>\u751f\u6d3b\u4e2d\u7684\u6848\u4f8b\uff1a\u53ef\u4ee5\u628a\u9501\u770b\u6210\u623f\u95e8\u5916\u7684\u4e00\u628a\u9501\u200b\uff0c\u6240\u6709\u5e76\u53d1\u7ebf\u7a0b\u6bd4\u4f5c\u4eba\uff0c\u4ed6\u4eec\u90fd\u60f3\u8fdb\u5165\u623f\u95f4\uff0c\u623f\u95f4\u5185\u53ea\u80fd\u6709\u4e00\u4e2a\u4eba\u8fdb\u5165\u3002\u5f53\u6709\u4eba\u8fdb\u5165\u540e\uff0c\u5c06\u95e8\u53cd\u9501\uff0c\u5176\u4ed6\u4eba\u5fc5\u987b\u7b49\u5f85\uff0c\u76f4\u5230\u8fdb\u53bb\u7684\u4eba\u51fa\u6765\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230410\/16811107236433b6c3da71a.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p>\u6211\u4eec\u6765\u770b\u4e0b\u5206\u5e03\u5f0f\u9501\u7684\u57fa\u672c\u539f\u7406\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230410\/16811107246433b6c44b787.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p>\u6211\u4eec\u6765\u5206\u6790\u4e0b\u4e0a\u56fe\u7684\u5206\u5e03\u5f0f\u9501\uff1a<\/p>\n<p>1.\u524d\u7aef\u5c06 10W \u7684\u9ad8\u5e76\u53d1\u8bf7\u6c42\u8f6c\u53d1\u7ed9\u56db\u4e2a\u9898\u76ee\u5fae\u670d\u52a1\u3002<\/p>\n<p>2.\u6bcf\u4e2a\u5fae\u670d\u52a1\u5904\u7406 2.5 W \u4e2a\u8bf7\u6c42\u3002<\/p>\n<p>3.\u6bcf\u4e2a\u5904\u7406\u8bf7\u6c42\u7684\u7ebf\u7a0b\u5728\u6267\u884c\u4e1a\u52a1\u4e4b\u524d\uff0c\u9700\u8981\u5148\u62a2\u5360\u9501\u3002\u53ef\u4ee5\u7406\u89e3\u4e3a\u201c\u5360\u5751\u201d\u3002<\/p>\n<p>4.\u83b7\u53d6\u5230\u9501\u7684\u7ebf\u7a0b\u5728\u6267\u884c\u5b8c\u4e1a\u52a1\u540e\uff0c\u91ca\u653e\u9501\u3002\u53ef\u4ee5\u7406\u89e3\u4e3a\u201c\u91ca\u653e\u5751\u4f4d\u201d\u3002<\/p>\n<p>5.\u672a\u83b7\u53d6\u5230\u7684\u7ebf\u7a0b\u9700\u8981\u7b49\u5f85\u9501\u91ca\u653e\u3002<\/p>\n<p>6.\u91ca\u653e\u9501\u540e\uff0c\u5176\u4ed6\u7ebf\u7a0b\u62a2\u5360\u9501\u3002<\/p>\n<p>7.\u91cd\u590d\u6267\u884c\u6b65\u9aa4 4\u30015\u30016\u3002<\/p>\n<p>\u5927\u767d\u8bdd\u89e3\u91ca\uff1a\u6240\u6709\u8bf7\u6c42\u7684\u7ebf\u7a0b\u90fd\u53bb\u540c\u4e00\u4e2a\u5730\u65b9\u201c\u5360\u5751\u201d\u200b\uff0c\u5982\u679c\u6709\u5751\u4f4d\uff0c\u5c31\u6267\u884c\u4e1a\u52a1\u903b\u8f91\uff0c\u6ca1\u6709\u5751\u4f4d\uff0c\u5c31\u9700\u8981\u5176\u4ed6\u7ebf\u7a0b\u91ca\u653e\u201c\u5751\u4f4d\u201d\u3002\u8fd9\u4e2a\u5751\u4f4d\u662f\u6240\u6709\u7ebf\u7a0b\u53ef\u89c1\u7684\uff0c\u53ef\u4ee5\u628a\u8fd9\u4e2a\u5751\u4f4d\u653e\u5230 Redis \u7f13\u5b58\u6216\u8005\u6570\u636e\u5e93\uff0c\u8fd9\u7bc7\u8bb2\u7684\u5c31\u662f\u5982\u4f55\u7528 Redis \u505a\u201c\u5206\u5e03\u5f0f\u5751\u4f4d\u201d\u3002<\/p>\n<h2>\u4e09\u3001Redis \u7684 SETNX<\/h2>\n<p>Redis \u4f5c\u4e3a\u4e00\u4e2a\u516c\u5171\u53ef\u8bbf\u95ee\u7684\u5730\u65b9\uff0c\u6b63\u597d\u53ef\u4ee5\u4f5c\u4e3a\u201c\u5360\u5751\u201d\u7684\u5730\u65b9\u3002<\/p>\n<p>\u7528 Redis \u5b9e\u73b0\u5206\u5e03\u5f0f\u9501\u7684\u51e0\u79cd\u65b9\u6848\uff0c\u6211\u4eec\u90fd\u662f\u7528 SETNX \u547d\u4ee4\uff08\u8bbe\u7f6e key \u7b49\u4e8e\u67d0 value\uff09\u3002\u53ea\u662f\u9ad8\u9636\u65b9\u6848\u4f20\u7684\u53c2\u6570\u4e2a\u6570\u4e0d\u4e00\u6837\uff0c\u4ee5\u53ca\u8003\u8651\u4e86\u5f02\u5e38\u60c5\u51b5\u3002<\/p>\n<p>\u6211\u4eec\u6765\u770b\u4e0b\u8fd9\u4e2a\u547d\u4ee4\uff0cSETNX\u662fset If not exist\u7684\u7b80\u5199\u3002\u610f\u601d\u5c31\u662f\u5f53 key \u4e0d\u5b58\u5728\u65f6\uff0c\u8bbe\u7f6e key \u7684\u503c\uff0c\u5b58\u5728\u65f6\uff0c\u4ec0\u4e48\u90fd\u4e0d\u505a\u3002<\/p>\n<p>\u5728 Redis \u547d\u4ee4\u884c\u4e2d\u662f\u8fd9\u6837\u6267\u884c\u7684\uff1a<\/p>\n<p><span style=\"color: #d73a49\">set<\/span> <span style=\"color: #d73a49\">key<span style=\"color: #d73a49\">&gt;<\/span> <span style=\"color: #d73a49\">value<span style=\"color: #d73a49\">&gt;<\/span> NX<\/span><\/span><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u8fdb\u5230 redis \u5bb9\u5668\u4e2d\u6765\u8bd5\u4e0b&nbsp;SETNX&nbsp;\u547d\u4ee4\u3002<\/p>\n<p>\u5148\u8fdb\u5165\u5bb9\u5668\uff1a<\/p>\n<p>docker exec <span style=\"color: #d73a49\">&#8211;<\/span>it <span style=\"color: #d73a49\">\u5bb9\u5668 id<span style=\"color: #d73a49\">&gt;<\/span> redid<span style=\"color: #d73a49\">&#8211;<\/span>cli<\/span><\/p>\n<p>\u7136\u540e\u6267\u884c SETNX \u547d\u4ee4\uff1a\u5c06&nbsp;wukong\u200b&nbsp;\u8fd9\u4e2a key \u5bf9\u5e94\u7684 value \u8bbe\u7f6e\u6210&nbsp;1111\u3002<\/p>\n<p><span style=\"color: #d73a49\">set<\/span> wukong <span style=\"color: #005cc5\">1111<\/span> NX<\/p>\n<p>\u8fd4\u56de&nbsp;OK\u200b\uff0c\u8868\u793a\u8bbe\u7f6e\u6210\u529f\u3002\u91cd\u590d\u6267\u884c\u8be5\u547d\u4ee4\uff0c\u8fd4\u56de&nbsp;nil\u8868\u793a\u8bbe\u7f6e\u5931\u8d25\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230410\/16811107246433b6c4a3d2b.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<h2>\u56db\u3001\u9752\u94dc\u65b9\u6848<\/h2>\n<p>\u6211\u4eec\u5148\u7528 Redis \u7684 SETNX \u547d\u4ee4\u6765\u5b9e\u73b0\u6700\u7b80\u5355\u7684\u5206\u5e03\u5f0f\u9501\u3002<\/p>\n<h3>3.1 \u9752\u94dc\u539f\u7406<\/h3>\n<p>\u6211\u4eec\u6765\u770b\u4e0b\u6d41\u7a0b\u56fe\uff1a<\/p>\n<ul>\n<li>\u591a\u4e2a\u5e76\u53d1\u7ebf\u7a0b\u90fd\u53bb Redis \u4e2d\u7533\u8bf7\u9501\uff0c\u4e5f\u5c31\u662f\u6267\u884c setnx \u547d\u4ee4\uff0c\u5047\u8bbe\u7ebf\u7a0b A \u6267\u884c\u6210\u529f\uff0c\u8bf4\u660e\u5f53\u524d\u7ebf\u7a0b A \u83b7\u5f97\u4e86\u3002<\/li>\n<li>\u5176\u4ed6\u7ebf\u7a0b\u6267\u884c setnx \u547d\u4ee4\u90fd\u4f1a\u662f\u5931\u8d25\u7684\uff0c\u6240\u4ee5\u9700\u8981\u7b49\u5f85\u7ebf\u7a0b A \u91ca\u653e\u9501\u3002<\/li>\n<li>\u7ebf\u7a0b A \u6267\u884c\u5b8c\u81ea\u5df1\u7684\u4e1a\u52a1\u540e\uff0c\u5220\u9664\u9501\u3002<\/li>\n<li>\u5176\u4ed6\u7ebf\u7a0b\u7ee7\u7eed\u62a2\u5360\u9501\uff0c\u4e5f\u5c31\u662f\u6267\u884c setnx \u547d\u4ee4\u3002\u56e0\u4e3a\u7ebf\u7a0b A \u5df2\u7ecf\u5220\u9664\u4e86\u9501\uff0c\u6240\u4ee5\u53c8\u6709\u5176\u4ed6\u7ebf\u7a0b\u53ef\u4ee5\u62a2\u5360\u5230\u9501\u4e86\u3002<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u793a\u4f8b\u5982\u4e0b\uff0cJava \u4e2d setnx \u547d\u4ee4\u5bf9\u5e94\u7684\u4ee3\u7801\u4e3a&nbsp;setIfAbsent\u3002<\/p>\n<p>setIfAbsent \u65b9\u6cd5\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u4ee3\u8868 key\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4ee3\u8868\u503c\u3002<\/p>\n<p><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">1<\/span>.\u5148\u62a2\u5360\u9501<br \/><span style=\"color: #22863a\">Boolean<\/span> lock <span style=\"color: #d73a49\">=<\/span> redisTemplate<span style=\"color: #005cc5\">.opsForValue<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #005cc5\">.setIfAbsent<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;lock&#8221;<\/span><span>,<\/span> <span style=\"color: #690\">&#8220;123&#8221;<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/>if<span style=\"color: #997\">(<\/span>lock<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">2<\/span>.\u62a2\u5360\u6210\u529f\uff0c\u6267\u884c\u4e1a\u52a1<br \/> List<span style=\"color: #d73a49\">TypeEntity<span style=\"color: #d73a49\">&gt;<\/span> typeEntityListFromDb <span style=\"color: #d73a49\">=<\/span> getDataFromDB<span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">3<\/span>.\u89e3\u9501<br \/> redisTemplate<span style=\"color: #005cc5\">.delete<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;lock&#8221;<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/> return typeEntityListFromDb<span>;<\/span><br \/><span style=\"color: #997\">}<\/span> else <span style=\"color: #997\">{<\/span><br \/><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">4<\/span>.\u4f11\u7720\u4e00\u6bb5\u65f6\u95f4<br \/> sleep<span style=\"color: #997\">(<\/span><span style=\"color: #005cc5\">100<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">5<\/span>.\u62a2\u5360\u5931\u8d25\uff0c\u7b49\u5f85\u9501\u91ca\u653e<br \/> return getTypeEntityListByRedisDistributedLock<span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #997\">}<\/span><\/span><\/p>\n<p>\u4e00\u4e2a\u5c0f\u95ee\u9898\uff1a\u90a3\u4e3a\u4ec0\u4e48\u9700\u8981\u4f11\u7720\u4e00\u6bb5\u65f6\u95f4\uff1f<\/p>\n<p>\u56e0\u4e3a\u8be5\u7a0b\u5e8f\u5b58\u5728\u9012\u5f52\u8c03\u7528\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6808\u7a7a\u95f4\u6ea2\u51fa\u3002<\/p>\n<h3>3.2 \u9752\u94dc\u65b9\u6848\u7684\u7f3a\u9677<\/h3>\n<p>\u9752\u94dc\u4e4b\u6240\u4ee5\u53eb\u9752\u94dc\uff0c\u662f\u56e0\u4e3a\u5b83\u662f\u6700\u521d\u7ea7\u7684\uff0c\u80af\u5b9a\u4f1a\u5e26\u6765\u5f88\u591a\u95ee\u9898\u3002<\/p>\n<p>\u8bbe\u60f3\u4e00\u79cd\u5bb6\u5ead\u573a\u666f\uff1a\u665a\u4e0a\u5c0f\u7a7a\u4e00\u4e2a\u4eba\u5f00\u9501\u8fdb\u5165\u4e86\u623f\u95f4\uff0c\u6253\u5f00\u4e86\u7535\u706f\uff0c\u7136\u540e\u7a81\u7136\u65ad\u7535\u4e86\uff0c\u5c0f\u7a7a\u60f3\u5f00\u95e8\u51fa\u53bb\uff0c\u4f46\u662f\u627e\u4e0d\u5230\u95e8\u9501\u4f4d\u7f6e\uff0c\u90a3\u5c0f\u660e\u5c31\u8fdb\u4e0d\u53bb\u4e86\uff0c\u5916\u9762\u7684\u4eba\u4e5f\u8fdb\u4e0d\u6765\u3002<\/p>\n<p>\u4ece\u6280\u672f\u7684\u89d2\u5ea6\u770b\uff1asetnx \u5360\u9501\u6210\u529f\uff0c\u4e1a\u52a1\u4ee3\u7801\u51fa\u73b0\u5f02\u5e38\u6216\u8005\u670d\u52a1\u5668\u5b95\u673a\uff0c\u6ca1\u6709\u6267\u884c\u5220\u9664\u9501\u7684\u903b\u8f91\uff0c\u5c31\u9020\u6210\u4e86\u6b7b\u9501\u3002<\/p>\n<p>\u90a3\u5982\u4f55\u89c4\u907f\u8fd9\u4e2a\u98ce\u9669\u5462\uff1f<\/p>\n<p>\u8bbe\u7f6e\u9501\u7684\u81ea\u52a8\u8fc7\u671f\u65f6\u95f4\uff0c\u8fc7\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u81ea\u52a8\u5220\u9664\u9501\uff0c\u8fd9\u6837\u5176\u4ed6\u7ebf\u7a0b\u5c31\u80fd\u83b7\u53d6\u5230\u9501\u4e86\u3002<\/p>\n<h2>\u56db\u3001\u767d\u94f6\u65b9\u6848<\/h2>\n<h3>4.1 \u751f\u6d3b\u4e2d\u7684\u4f8b\u5b50<\/h3>\n<p>\u4e0a\u9762\u63d0\u5230\u7684\u9752\u94dc\u65b9\u6848\u4f1a\u6709\u6b7b\u9501\u95ee\u9898\uff0c\u90a3\u6211\u4eec\u5c31\u7528\u4e0a\u9762\u7684\u89c4\u907f\u98ce\u9669\u7684\u65b9\u6848\u6765\u8bbe\u8ba1\u4e0b\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u7684\u767d\u94f6\u65b9\u6848\u3002<\/p>\n<p>\u8fd8\u662f\u751f\u6d3b\u4e2d\u7684\u4f8b\u5b50\uff1a\u5c0f\u7a7a\u5f00\u9501\u6210\u529f\u540e\uff0c\u7ed9\u8fd9\u6b3e\u667a\u80fd\u9501\u8bbe\u7f6e\u4e86\u4e00\u4e2a\u6c99\u6f0f\u5012\u8ba1\u65f6\u23f3\uff0c\u6c99\u6f0f\u5b8c\u540e\uff0c\u95e8\u9501\u81ea\u52a8\u6253\u5f00\u3002\u5373\u4f7f\u623f\u95f4\u7a81\u7136\u65ad\u7535\uff0c\u8fc7\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u9501\u4f1a\u81ea\u52a8\u6253\u5f00\uff0c\u5176\u4ed6\u4eba\u5c31\u53ef\u4ee5\u8fdb\u6765\u4e86\u3002<\/p>\n<h3>4.2 \u6280\u672f\u539f\u7406\u56fe<\/h3>\n<p>\u548c\u9752\u94dc\u65b9\u6848\u4e0d\u540c\u7684\u5730\u65b9\u5728\u4e8e\uff0c\u5728\u5360\u9501\u6210\u529f\u540e\uff0c\u8bbe\u7f6e\u9501\u7684\u8fc7\u671f\u65f6\u95f4\uff0c\u8fd9\u4e24\u6b65\u662f\u5206\u6b65\u6267\u884c\u7684\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<h3>4.3 \u793a\u4f8b\u4ee3\u7801<\/h3>\n<p>\u6e05\u7406 redis key \u7684\u4ee3\u7801\u5982\u4e0b<\/p>\n<p><span style=\"color: #d73a49\">\/\/<\/span> \u5728 <span style=\"color: #005cc5\">10<\/span>s \u4ee5\u540e\uff0c\u81ea\u52a8\u6e05\u7406 lock<br \/>redisTemplate<span style=\"color: #005cc5\">.expire<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;lock&#8221;<\/span><span>,<\/span> <span style=\"color: #005cc5\">10<\/span><span>,<\/span> TimeUnit<span style=\"color: #005cc5\">.SECONDS<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><\/p>\n<p>\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">1<\/span>.\u5148\u62a2\u5360\u9501<br \/><span style=\"color: #22863a\">Boolean<\/span> lock <span style=\"color: #d73a49\">=<\/span> redisTemplate<span style=\"color: #005cc5\">.opsForValue<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #005cc5\">.setIfAbsent<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;lock&#8221;<\/span><span>,<\/span> <span style=\"color: #690\">&#8220;123&#8221;<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/>if<span style=\"color: #997\">(<\/span>lock<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">2<\/span>.\u5728 <span style=\"color: #005cc5\">10<\/span>s \u4ee5\u540e\uff0c\u81ea\u52a8\u6e05\u7406 lock<br \/> redisTemplate<span style=\"color: #005cc5\">.expire<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;lock&#8221;<\/span><span>,<\/span> <span style=\"color: #005cc5\">10<\/span><span>,<\/span> TimeUnit<span style=\"color: #005cc5\">.SECONDS<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">3<\/span>.\u62a2\u5360\u6210\u529f\uff0c\u6267\u884c\u4e1a\u52a1<br \/> List<span style=\"color: #d73a49\">TypeEntity<span style=\"color: #d73a49\">&gt;<\/span> typeEntityListFromDb <span style=\"color: #d73a49\">=<\/span> getDataFromDB<span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">4<\/span>.\u89e3\u9501<br \/> redisTemplate<span style=\"color: #005cc5\">.delete<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;lock&#8221;<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/> return typeEntityListFromDb<span>;<\/span><br \/><span style=\"color: #997\">}<\/span><\/span><\/p>\n<h3>4.4 \u767d\u94f6\u65b9\u6848\u7684\u7f3a\u9677<\/h3>\n<p>\u767d\u94f6\u65b9\u6848\u770b\u4f3c\u89e3\u51b3\u4e86\u7ebf\u7a0b\u5f02\u5e38\u6216\u670d\u52a1\u5668\u5b95\u673a\u9020\u6210\u7684\u9501\u672a\u91ca\u653e\u7684\u95ee\u9898\uff0c\u4f46\u8fd8\u662f\u5b58\u5728\u5176\u4ed6\u95ee\u9898\uff1a<\/p>\n<p>\u56e0\u4e3a\u5360\u9501\u548c\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\u662f\u5206\u4e24\u6b65\u6267\u884c\u7684\uff0c\u6240\u4ee5\u5982\u679c\u5728\u8fd9\u4e24\u6b65\u4e4b\u95f4\u53d1\u751f\u4e86\u5f02\u5e38\uff0c\u5219\u9501\u7684\u8fc7\u671f\u65f6\u95f4\u6839\u672c\u5c31\u6ca1\u6709\u8bbe\u7f6e\u6210\u529f\u3002<\/p>\n<p>\u6240\u4ee5\u548c\u9752\u94dc\u65b9\u6848\u6709\u4e00\u6837\u7684\u95ee\u9898\uff1a\u9501\u6c38\u8fdc\u4e0d\u80fd\u8fc7\u671f\u3002<\/p>\n<h2>\u4e94\u3001\u9ec4\u91d1\u65b9\u6848<\/h2>\n<h3>5.1 \u539f\u5b50\u6307\u4ee4<\/h3>\n<p>\u4e0a\u9762\u7684\u767d\u94f6\u65b9\u6848\u4e2d\uff0c\u5360\u9501\u548c\u8bbe\u7f6e\u9501\u8fc7\u671f\u65f6\u95f4\u662f\u5206\u6b65\u4e24\u6b65\u6267\u884c\u7684\uff0c\u8fd9\u4e2a\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u4ee5\u8054\u60f3\u5230\u4ec0\u4e48\uff1a\u4e8b\u52a1\u7684\u539f\u5b50\u6027\uff08Atom\uff09\u3002<\/p>\n<p>\u539f\u5b50\u6027\uff1a\u591a\u6761\u547d\u4ee4\u8981\u4e48\u90fd\u6210\u529f\u6267\u884c\uff0c\u8981\u4e48\u90fd\u4e0d\u6267\u884c\u3002<\/p>\n<p>\u5c06\u4e24\u6b65\u653e\u5728\u4e00\u6b65\u4e2d\u6267\u884c\uff1a\u5360\u9501+\u8bbe\u7f6e\u9501\u8fc7\u671f\u65f6\u95f4\u3002<\/p>\n<p>Redis \u6b63\u597d\u652f\u6301\u8fd9\u79cd\u64cd\u4f5c\uff1a<\/p>\n<p># \u8bbe\u7f6e\u67d0\u4e2a key \u7684\u503c\u5e76\u8bbe\u7f6e\u591a\u5c11\u6beb\u79d2\u6216\u79d2 \u8fc7\u671f\u3002<br \/><span style=\"color: #d73a49\">set<\/span> <span style=\"color: #d73a49\">key<span style=\"color: #d73a49\">&gt;<\/span> <span style=\"color: #d73a49\">value<span style=\"color: #d73a49\">&gt;<\/span> PX <span style=\"color: #d73a49\">\u591a\u5c11\u6beb\u79d2<span style=\"color: #d73a49\">&gt;<\/span> NX<br \/>\u6216<br \/><span style=\"color: #d73a49\">set<\/span> <span style=\"color: #d73a49\">key<span style=\"color: #d73a49\">&gt;<\/span> <span style=\"color: #d73a49\">value<span style=\"color: #d73a49\">&gt;<\/span> EX <span style=\"color: #d73a49\">\u591a\u5c11\u79d2<span style=\"color: #d73a49\">&gt;<\/span> NX<\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p>\u7136\u540e\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u547d\u4ee4\u67e5\u770b key \u7684\u53d8\u5316<\/p>\n<p>ttl <span style=\"color: #d73a49\">key<span style=\"color: #d73a49\">&gt;<\/span><\/span><\/p>\n<p>\u4e0b\u9762\u6f14\u793a\u4e0b\u5982\u4f55\u8bbe\u7f6e key \u5e76\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\u3002\u6ce8\u610f\uff1a\u6267\u884c\u547d\u4ee4\u4e4b\u524d\u9700\u8981\u5148\u5220\u9664 key\uff0c\u53ef\u4ee5\u901a\u8fc7\u5ba2\u6237\u7aef\u6216\u547d\u4ee4\u5220\u9664\u3002<\/p>\n<p># \u8bbe\u7f6e key<span style=\"color: #d73a49\">=<\/span>wukong\uff0cvalue<span style=\"color: #d73a49\">=<\/span><span style=\"color: #005cc5\">1111<\/span>\uff0c\u8fc7\u671f\u65f6\u95f4<span style=\"color: #d73a49\">=<\/span><span style=\"color: #005cc5\">5000<\/span>ms<br \/><span style=\"color: #d73a49\">set<\/span> wukong <span style=\"color: #005cc5\">1111<\/span> PX <span style=\"color: #005cc5\">5000<\/span> NX<br \/># \u67e5\u770b key \u7684\u72b6\u6001<br \/>ttl wukong<\/p>\n<p>\u6267\u884c\u7ed3\u679c\u5982\u4e0b\u56fe\u6240\u793a\uff1a\u6bcf\u8fd0\u884c\u4e00\u6b21 ttl \u547d\u4ee4\uff0c\u5c31\u53ef\u4ee5\u770b\u5230 wukong \u7684\u8fc7\u671f\u65f6\u95f4\u5c31\u4f1a\u51cf\u5c11\u3002\u6700\u540e\u4f1a\u53d8\u4e3a -2\uff08\u5df2\u8fc7\u671f\uff09\u3002<\/p>\n<h3>5.2 \u6280\u672f\u539f\u7406\u56fe<\/h3>\n<p>\u9ec4\u91d1\u65b9\u6848\u548c\u767d\u94f6\u65b9\u6848\u7684\u4e0d\u540c\u4e4b\u5904\uff1a\u83b7\u53d6\u9501\u7684\u65f6\u5019\uff0c\u4e5f\u9700\u8981\u8bbe\u7f6e\u9501\u7684\u8fc7\u671f\u65f6\u95f4\uff0c\u8fd9\u662f\u4e00\u4e2a\u539f\u5b50\u64cd\u4f5c\uff0c\u8981\u4e48\u90fd\u6210\u529f\u6267\u884c\uff0c\u8981\u4e48\u90fd\u4e0d\u6267\u884c\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<h3>5.3 \u793a\u4f8b\u4ee3\u7801<\/h3>\n<p>\u8bbe\u7f6e&nbsp;lock\u200b&nbsp;\u7684\u503c\u7b49\u4e8e&nbsp;123\u200b\uff0c\u8fc7\u671f\u65f6\u95f4\u4e3a 10 \u79d2\u3002\u5982\u679c&nbsp;10&nbsp;\u79d2 \u4ee5\u540e\uff0clock \u8fd8\u5b58\u5728\uff0c\u5219\u6e05\u7406 lock\u3002<\/p>\n<p>setIfAbsent<span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;lock&#8221;<\/span><span>,<\/span> <span style=\"color: #690\">&#8220;123&#8221;<\/span><span>,<\/span> <span style=\"color: #005cc5\">10<\/span><span>,<\/span> TimeUnit<span style=\"color: #005cc5\">.SECONDS<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><\/p>\n<h3>5.4 \u9ec4\u91d1\u65b9\u6848\u7684\u7f3a\u9677<\/h3>\n<p>\u6211\u4eec\u8fd8\u662f\u4e3e\u751f\u6d3b\u4e2d\u7684\u4f8b\u5b50\u6765\u770b\u4e0b\u9ec4\u91d1\u65b9\u6848\u7684\u7f3a\u9677\u3002<\/p>\n<h4>5.4.1 \u7528\u6237 A \u62a2\u5360\u9501<\/h4>\n<ul>\n<li>\u7528\u6237 A \u5148\u62a2\u5360\u5230\u4e86\u9501\uff0c\u5e76\u8bbe\u7f6e\u4e86\u8fd9\u4e2a\u9501 10 \u79d2\u4ee5\u540e\u81ea\u52a8\u5f00\u9501\uff0c\u9501\u7684\u7f16\u53f7\u4e3a&nbsp;123\u3002<\/li>\n<li>10 \u79d2\u4ee5\u540e\uff0cA \u8fd8\u5728\u6267\u884c\u4efb\u52a1\uff0c\u6b64\u65f6\u9501\u88ab\u81ea\u52a8\u6253\u5f00\u4e86\u3002<\/li>\n<\/ul>\n<h4>5.4.2 \u7528\u6237 B \u62a2\u5360\u9501<\/h4>\n<ul>\n<li>\u7528\u6237 B \u770b\u5230\u623f\u95f4\u7684\u9501\u6253\u5f00\u4e86\uff0c\u4e8e\u662f\u62a2\u5360\u5230\u4e86\u9501\uff0c\u8bbe\u7f6e\u9501\u7684\u7f16\u53f7\u4e3a&nbsp;123\uff0c\u5e76\u8bbe\u7f6e\u4e86\u8fc7\u671f\u65f6\u95f4&nbsp;10 \u79d2\u3002<\/li>\n<li>\u56e0\u623f\u95f4\u5185\u53ea\u5141\u8bb8\u4e00\u4e2a\u7528\u6237\u6267\u884c\u4efb\u52a1\uff0c\u6240\u4ee5\u7528\u6237 A \u548c \u7528\u6237 B \u6267\u884c\u4efb\u52a1\u4ea7\u751f\u4e86\u51b2\u7a81\u3002<\/li>\n<li>\u7528\u6237 A \u5728&nbsp;15 s&nbsp;\u540e\uff0c\u5b8c\u6210\u4e86\u4efb\u52a1\uff0c\u6b64\u65f6 \u7528\u6237 B \u8fd8\u5728\u6267\u884c\u4efb\u52a1\u3002<\/li>\n<li>\u7528\u6237 A \u4e3b\u52a8\u6253\u5f00\u4e86\u7f16\u53f7\u4e3a&nbsp;123\u7684\u9501\u3002<\/li>\n<li>\u7528\u6237 B \u8fd8\u5728\u6267\u884c\u4efb\u52a1\uff0c\u53d1\u73b0\u9501\u5df2\u7ecf\u88ab\u6253\u5f00\u4e86\u3002<\/li>\n<li>\u7528\u6237 B \u975e\u5e38\u751f\u6c14\uff1a\u6211\u8fd8\u6ca1\u6267\u884c\u5b8c\u4efb\u52a1\u5462\uff0c\u9501\u600e\u4e48\u5f00\u4e86\uff1f<\/li>\n<\/ul>\n<h4>5.4.3 \u7528\u6237 C \u62a2\u5360\u9501<\/h4>\n<ul>\n<li>\u7528\u6237 B \u7684\u9501\u88ab A \u4e3b\u52a8\u6253\u5f00\u540e\uff0cA \u79bb\u5f00\u623f\u95f4\uff0cB \u8fd8\u5728\u6267\u884c\u4efb\u52a1\u3002<\/li>\n<li>\u7528\u6237 C \u62a2\u5360\u5230\u9501\uff0cC \u5f00\u59cb\u6267\u884c\u4efb\u52a1\u3002<\/li>\n<li>\u56e0\u623f\u95f4\u5185\u53ea\u5141\u8bb8\u4e00\u4e2a\u7528\u6237\u6267\u884c\u4efb\u52a1\uff0c\u6240\u4ee5\u7528\u6237 B \u548c \u7528\u6237 C \u6267\u884c\u4efb\u52a1\u4ea7\u751f\u4e86\u51b2\u7a81\u3002<\/li>\n<\/ul>\n<p>\u4ece\u4e0a\u9762\u7684\u6848\u4f8b\u4e2d\u6211\u4eec\u53ef\u4ee5\u77e5\u9053\uff0c\u56e0\u4e3a\u7528\u6237 A \u5904\u7406\u4efb\u52a1\u6240\u9700\u8981\u7684\u65f6\u95f4\u5927\u4e8e\u9501\u81ea\u52a8\u6e05\u7406\uff08\u5f00\u9501\uff09\u7684\u65f6\u95f4\uff0c\u6240\u4ee5\u5728\u81ea\u52a8\u5f00\u9501\u540e\uff0c\u53c8\u6709\u5176\u4ed6\u7528\u6237\u62a2\u5360\u5230\u4e86\u9501\u3002\u5f53\u7528\u6237 A \u5b8c\u6210\u4efb\u52a1\u540e\uff0c\u4f1a\u628a\u5176\u4ed6\u7528\u6237\u62a2\u5360\u5230\u7684\u9501\u7ed9\u4e3b\u52a8\u6253\u5f00\u3002<\/p>\n<p>\u8fd9\u91cc\u4e3a\u4ec0\u4e48\u4f1a\u6253\u5f00\u522b\u4eba\u7684\u9501\uff1f\u56e0\u4e3a\u9501\u7684\u7f16\u53f7\u90fd\u53eb\u505a&nbsp;\u201c123\u201d\u200b\uff0c\u7528\u6237 A \u53ea\u8ba4\u9501\u7f16\u53f7\uff0c\u770b\u89c1\u7f16\u53f7\u4e3a&nbsp;\u201c123\u201d\u7684\u9501\u5c31\u5f00\uff0c\u7ed3\u679c\u628a\u7528\u6237 B \u7684\u9501\u6253\u5f00\u4e86\uff0c\u6b64\u65f6\u7528\u6237 B \u8fd8\u672a\u6267\u884c\u5b8c\u4efb\u52a1\uff0c\u5f53\u7136\u751f\u6c14\u4e86\u3002<\/p>\n<h2>\u516d\u3001\u94c2\u91d1\u65b9\u6848<\/h2>\n<h3>6.1 \u751f\u6d3b\u4e2d\u7684\u4f8b\u5b50<\/h3>\n<p>\u4e0a\u9762\u7684\u9ec4\u91d1\u65b9\u6848\u7684\u7f3a\u9677\u4e5f\u5f88\u597d\u89e3\u51b3\uff0c\u7ed9\u6bcf\u4e2a\u9501\u8bbe\u7f6e\u4e0d\u540c\u7684\u7f16\u53f7\u4e0d\u5c31\u597d\u4e86\uff5e<\/p>\n<p>\u5982\u4e0b\u56fe\u6240\u793a\uff0cB \u62a2\u5360\u7684\u9501\u662f\u84dd\u8272\u7684\uff0c\u548c A \u62a2\u5360\u5230\u7eff\u8272\u9501\u4e0d\u4e00\u6837\u3002\u8fd9\u6837\u5c31\u4e0d\u4f1a\u88ab A \u6253\u5f00\u4e86\u3002<\/p>\n<p>\u505a\u4e86\u4e2a\u52a8\u56fe\uff0c\u65b9\u4fbf\u7406\u89e3\uff1a<\/p>\n<p>\u52a8\u56fe\u6f14\u793a<\/p>\n<p>\u9759\u6001\u56fe\u66f4\u9ad8\u6e05\uff0c\u53ef\u4ee5\u770b\u770b\uff1a<\/p>\n<h3>6.2 \u6280\u672f\u539f\u7406\u56fe<\/h3>\n<p>\u4e0e\u9ec4\u91d1\u65b9\u6848\u7684\u4e0d\u540c\u4e4b\u5904\uff1a<\/p>\n<ul>\n<li>\u8bbe\u7f6e\u9501\u7684\u8fc7\u671f\u65f6\u95f4\u65f6\uff0c\u8fd8\u9700\u8981\u8bbe\u7f6e\u552f\u4e00\u7f16\u53f7\u3002<\/li>\n<li>\u4e3b\u52a8\u5220\u9664\u9501\u7684\u65f6\u5019\uff0c\u9700\u8981\u5224\u65ad\u9501\u7684\u7f16\u53f7\u662f\u5426\u548c\u8bbe\u7f6e\u7684\u4e00\u81f4\uff0c\u5982\u679c\u4e00\u81f4\uff0c\u5219\u8ba4\u4e3a\u662f\u81ea\u5df1\u8bbe\u7f6e\u7684\u9501\uff0c\u53ef\u4ee5\u8fdb\u884c\u4e3b\u52a8\u5220\u9664\u3002<\/li>\n<\/ul>\n<h3>6.3 \u4ee3\u7801\u793a\u4f8b<\/h3>\n<p><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">1<\/span>.\u751f\u6210\u552f\u4e00 id<br \/>String uuid <span style=\"color: #d73a49\">=<\/span> UUID<span style=\"color: #005cc5\">.randomUUID<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #005cc5\">.toString<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">2<\/span>. \u62a2\u5360\u9501<br \/><span style=\"color: #22863a\">Boolean<\/span> lock <span style=\"color: #d73a49\">=<\/span> redisTemplate<span style=\"color: #005cc5\">.opsForValue<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #005cc5\">.setIfAbsent<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;lock&#8221;<\/span><span>,<\/span> uuid<span>,<\/span> <span style=\"color: #005cc5\">10<\/span><span>,<\/span> TimeUnit<span style=\"color: #005cc5\">.SECONDS<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/>if<span style=\"color: #997\">(<\/span>lock<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> System<span style=\"color: #005cc5\">.out<\/span><span style=\"color: #005cc5\">.println<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;\u62a2\u5360\u6210\u529f\uff1a&#8221;<\/span> <span style=\"color: #d73a49\">+<\/span> uuid<span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">3<\/span>.\u62a2\u5360\u6210\u529f\uff0c\u6267\u884c\u4e1a\u52a1<br \/> List<span style=\"color: #d73a49\">TypeEntity<span style=\"color: #d73a49\">&gt;<\/span> typeEntityListFromDb <span style=\"color: #d73a49\">=<\/span> getDataFromDB<span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">4<\/span>.\u83b7\u53d6\u5f53\u524d\u9501\u7684\u503c<br \/> String lockValue <span style=\"color: #d73a49\">=<\/span> redisTemplate<span style=\"color: #005cc5\">.opsForValue<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #005cc5\">.get<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;lock&#8221;<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">5<\/span>.\u5982\u679c\u9501\u7684\u503c\u548c\u8bbe\u7f6e\u7684\u503c\u76f8\u7b49\uff0c\u5219\u6e05\u7406\u81ea\u5df1\u7684\u9501<br \/> if<span style=\"color: #997\">(<\/span>uuid<span style=\"color: #005cc5\">.equals<\/span><span style=\"color: #997\">(<\/span>lockValue<span style=\"color: #997\">)<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> System<span style=\"color: #005cc5\">.out<\/span><span style=\"color: #005cc5\">.println<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;\u6e05\u7406\u9501\uff1a&#8221;<\/span> <span style=\"color: #d73a49\">+<\/span> lockValue<span style=\"color: #997\">)<\/span><span>;<\/span><br \/> redisTemplate<span style=\"color: #005cc5\">.delete<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;lock&#8221;<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #997\">}<\/span><br \/> return typeEntityListFromDb<span>;<\/span><br \/><span style=\"color: #997\">}<\/span> else <span style=\"color: #997\">{<\/span><br \/> System<span style=\"color: #005cc5\">.out<\/span><span style=\"color: #005cc5\">.println<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;\u62a2\u5360\u5931\u8d25\uff0c\u7b49\u5f85\u9501\u91ca\u653e&#8221;<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">4<\/span>.\u4f11\u7720\u4e00\u6bb5\u65f6\u95f4<br \/> sleep<span style=\"color: #997\">(<\/span><span style=\"color: #005cc5\">100<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #d73a49\">\/\/<\/span> <span style=\"color: #005cc5\">5<\/span>.\u62a2\u5360\u5931\u8d25\uff0c\u7b49\u5f85\u9501\u91ca\u653e<br \/> return getTypeEntityListByRedisDistributedLock<span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #997\">}<\/span><\/span><\/p>\n<ul>\n<li>1.\u751f\u6210\u968f\u673a\u552f\u4e00 id\uff0c\u7ed9\u9501\u52a0\u4e0a\u552f\u4e00\u503c\u3002<\/li>\n<li>2.\u62a2\u5360\u9501\uff0c\u5e76\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\u4e3a 10 s\uff0c\u4e14\u9501\u5177\u6709\u968f\u673a\u552f\u4e00 id\u3002<\/li>\n<li>3.\u62a2\u5360\u6210\u529f\uff0c\u6267\u884c\u4e1a\u52a1\u3002<\/li>\n<li>4.\u6267\u884c\u5b8c\u4e1a\u52a1\u540e\uff0c\u83b7\u53d6\u5f53\u524d\u9501\u7684\u503c\u3002<\/li>\n<li>5.\u5982\u679c\u9501\u7684\u503c\u548c\u8bbe\u7f6e\u7684\u503c\u76f8\u7b49\uff0c\u5219\u6e05\u7406\u81ea\u5df1\u7684\u9501\u3002<\/li>\n<\/ul>\n<h3>6.4 \u94c2\u91d1\u65b9\u6848\u7684\u7f3a\u9677<\/h3>\n<p>\u4e0a\u9762\u7684\u65b9\u6848\u770b\u4f3c\u5f88\u5b8c\u7f8e\uff0c\u4f46\u8fd8\u662f\u5b58\u5728\u95ee\u9898\uff1a\u7b2c 4 \u6b65\u548c\u7b2c 5 \u6b65\u5e76\u4e0d\u662f\u539f\u5b50\u6027\u7684\u3002<\/p>\n<ul>\n<li>\u65f6\u523b\uff1a0s\u3002\u7ebf\u7a0b A \u62a2\u5360\u5230\u4e86\u9501\u3002<\/li>\n<li>\u65f6\u523b\uff1a9.5s\u3002\u7ebf\u7a0b A \u5411 Redis \u67e5\u8be2\u5f53\u524d key \u7684\u503c\u3002<\/li>\n<li>\u65f6\u523b\uff1a10s\u3002\u9501\u81ea\u52a8\u8fc7\u671f\u3002<\/li>\n<li>\u65f6\u523b\uff1a11s\u3002\u7ebf\u7a0b B \u62a2\u5360\u5230\u9501\u3002<\/li>\n<li>\u65f6\u523b\uff1a12s\u3002\u7ebf\u7a0b A \u5728\u67e5\u8be2\u9014\u4e2d\u8017\u65f6\u957f\uff0c\u7ec8\u4e8e\u62ff\u591a\u9501\u7684\u503c\u3002<\/li>\n<li>\u65f6\u523b\uff1a13s\u3002\u7ebf\u7a0b A \u8fd8\u662f\u62ff\u81ea\u5df1\u8bbe\u7f6e\u7684\u9501\u7684\u503c\u548c\u8fd4\u56de\u7684\u503c\u8fdb\u884c\u6bd4\u8f83\uff0c\u503c\u662f\u76f8\u7b49\u7684\uff0c\u6e05\u7406\u9501\uff0c\u4f46\u662f\u8fd9\u4e2a\u9501\u5176\u5b9e\u662f\u7ebf\u7a0b B \u62a2\u5360\u7684\u9501\u3002<\/li>\n<\/ul>\n<p>\u90a3\u5982\u4f55\u89c4\u907f\u8fd9\u4e2a\u98ce\u9669\u5462\uff1f\u94bb\u77f3\u65b9\u6848\u767b\u573a\u3002<\/p>\n<h2>\u4e03\u3001\u94bb\u77f3\u65b9\u6848<\/h2>\n<p>\u4e0a\u9762\u7684\u7ebf\u7a0b A \u67e5\u8be2\u9501\u548c\u5220\u9664\u9501\u7684\u903b\u8f91\u4e0d\u662f\u539f\u5b50\u6027\u7684\uff0c\u6240\u4ee5\u5c06\u67e5\u8be2\u9501\u548c\u5220\u9664\u9501\u8fd9\u4e24\u6b65\u4f5c\u4e3a\u539f\u5b50\u6307\u4ee4\u64cd\u4f5c\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<h3>7.1 \u6280\u672f\u539f\u7406\u56fe<\/h3>\n<p>\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u7ea2\u8272\u5708\u51fa\u6765\u7684\u90e8\u5206\u662f\u94bb\u77f3\u65b9\u6848\u7684\u4e0d\u540c\u4e4b\u5904\u3002\u7528\u811a\u672c\u8fdb\u884c\u5220\u9664\uff0c\u8fbe\u5230\u539f\u5b50\u64cd\u4f5c\u3002<\/p>\n<h3>7.2 \u4ee3\u7801\u793a\u4f8b<\/h3>\n<p>\u90a3\u5982\u4f55\u7528\u811a\u672c\u8fdb\u884c\u5220\u9664\u5462\uff1f<\/p>\n<p>\u6211\u4eec\u5148\u6765\u770b\u4e00\u4e0b\u8fd9\u6bb5 Redis \u4e13\u5c5e\u811a\u672c\uff1a<\/p>\n<p>if redis<span style=\"color: #005cc5\">.call<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;get&#8221;<\/span><span>,<\/span>KEYS<span style=\"color: #997\">[<\/span><span style=\"color: #005cc5\">1<\/span><span style=\"color: #997\">]<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #d73a49\">==<\/span> ARGV<span style=\"color: #997\">[<\/span><span style=\"color: #005cc5\">1<\/span><span style=\"color: #997\">]<\/span><br \/>then<br \/> return redis<span style=\"color: #005cc5\">.call<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;del&#8221;<\/span><span>,<\/span>KEYS<span style=\"color: #997\">[<\/span><span style=\"color: #005cc5\">1<\/span><span style=\"color: #997\">]<\/span><span style=\"color: #997\">)<\/span><br \/>else<br \/> return <span style=\"color: #005cc5\">0<\/span><br \/>end<\/p>\n<p>\u8fd9\u6bb5\u811a\u672c\u548c\u94c2\u91d1\u65b9\u6848\u7684\u83b7\u53d6key\uff0c\u5220\u9664key\u7684\u65b9\u5f0f\u5f88\u50cf\u3002\u5148\u83b7\u53d6 KEYS[1] \u7684 value\uff0c\u5224\u65ad KEYS[1] \u7684 value \u662f\u5426\u548c ARGV[1] \u7684\u503c\u76f8\u7b49\uff0c\u5982\u679c\u76f8\u7b49\uff0c\u5219\u5220\u9664 KEYS[1]\u3002<\/p>\n<p>\u90a3\u4e48\u8fd9\u6bb5\u811a\u672c\u600e\u4e48\u5728 Java \u9879\u76ee\u4e2d\u6267\u884c\u5462\uff1f<\/p>\n<p>\u5206\u4e24\u6b65\uff1a\u5148\u5b9a\u4e49\u811a\u672c\uff1b\u7528 redisTemplate.execute \u65b9\u6cd5\u6267\u884c\u811a\u672c\u3002<\/p>\n<p><span style=\"color: #d73a49\">\/\/<\/span> \u811a\u672c\u89e3\u9501<br \/>String script <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #690\">&#8220;if redis.call(&#8216;get&#8217;,KEYS[1]) == ARGV[1] then return redis.call(&#8216;del&#8217;,KEYS[1]) else return 0 end&#8221;<\/span><span>;<\/span><br \/>redisTemplate<span style=\"color: #005cc5\">.execute<\/span><span style=\"color: #997\">(<\/span>new DefaultRedisScript<span style=\"color: #d73a49\"><span style=\"color: #22863a\">Long<\/span><span style=\"color: #d73a49\">&gt;<\/span><span style=\"color: #997\">(<\/span>script<span>,<\/span> <span style=\"color: #22863a\">Long<\/span><span style=\"color: #005cc5\">.class<\/span><span style=\"color: #997\">)<\/span><span>,<\/span> Arrays<span style=\"color: #005cc5\">.asList<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;lock&#8221;<\/span><span style=\"color: #997\">)<\/span><span>,<\/span> uuid<span style=\"color: #997\">)<\/span><span>;<\/span><\/span><\/p>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0cKEYS[1] \u5bf9\u5e94\u201clock\u201d\u200b\uff0cARGV[1] \u5bf9\u5e94&nbsp;\u201cuuid\u201d\uff0c\u542b\u4e49\u5c31\u662f\u5982\u679c lock \u7684 value \u7b49\u4e8e uuid \u5219\u5220\u9664 lock\u3002<\/p>\n<p>\u800c\u8fd9\u6bb5 Redis \u811a\u672c\u662f\u7531 Redis \u5185\u5d4c\u7684 Lua \u73af\u5883\u6267\u884c\u7684\uff0c\u6240\u4ee5\u53c8\u79f0\u4f5c Lua \u811a\u672c\u3002<\/p>\n<p>\u90a3\u94bb\u77f3\u65b9\u6848\u662f\u4e0d\u662f\u5c31\u5b8c\u7f8e\u4e86\u5462\uff1f\u6709\u6ca1\u6709\u66f4\u597d\u7684\u65b9\u6848\u5462\uff1f<\/p>\n<p>\u4e0b\u7bc7\uff0c\u6211\u4eec\u518d\u6765\u4ecb\u7ecd\u53e6\u5916\u4e00\u79cd\u5206\u5e03\u5f0f\u9501\u7684\u738b\u8005\u65b9\u6848\uff1aRedisson\u3002<\/p>\n<h2>\u516b\u3001\u603b\u7ed3<\/h2>\n<p>\u672c\u7bc7\u901a\u8fc7\u672c\u5730\u9501\u7684\u95ee\u9898\u5f15\u7533\u51fa\u5206\u5e03\u5f0f\u9501\u7684\u95ee\u9898\u3002\u7136\u540e\u4ecb\u7ecd\u4e86\u4e94\u79cd\u5206\u5e03\u5f0f\u9501\u7684\u65b9\u6848\uff0c\u7531\u6d45\u5165\u6df1\u8bb2\u89e3\u4e86\u4e0d\u540c\u65b9\u6848\u7684\u6539\u8fdb\u4e4b\u5904\u3002<\/p>\n<p>\u4ece\u4e0a\u9762\u51e0\u79cd\u65b9\u6848\u7684\u4e0d\u65ad\u6f14\u8fdb\u7684\u8fc7\u7a0b\u4e2d\uff0c\u77e5\u9053\u4e86\u7cfb\u7edf\u4e2d\u54ea\u4e9b\u5730\u65b9\u53ef\u80fd\u5b58\u5728\u5f02\u5e38\u60c5\u51b5\uff0c\u4ee5\u53ca\u8be5\u5982\u4f55\u66f4\u597d\u5730\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<p>\u4e3e\u4e00\u53cd\u4e09\uff0c\u8fd9\u79cd\u4e0d\u65ad\u6f14\u8fdb\u7684\u601d\u7ef4\u6a21\u5f0f\u4e5f\u53ef\u4ee5\u8fd0\u7528\u5230\u5176\u4ed6\u6280\u672f\u4e2d\u3002<\/p>\n<p>\u4e0b\u9762\u603b\u7ed3\u4e0b\u4e0a\u9762\u4e94\u79cd\u65b9\u6848\u7684\u7f3a\u9677\u548c\u6539\u8fdb\u4e4b\u5904\u3002<\/p>\n<p>\u9752\u94dc\u65b9\u6848\uff1a<\/p>\n<ul>\n<li>\u7f3a\u9677\uff1a\u4e1a\u52a1\u4ee3\u7801\u51fa\u73b0\u5f02\u5e38\u6216\u8005\u670d\u52a1\u5668\u5b95\u673a\uff0c\u6ca1\u6709\u6267\u884c\u4e3b\u52a8\u5220\u9664\u9501\u7684\u903b\u8f91\uff0c\u5c31\u9020\u6210\u4e86\u6b7b\u9501\u3002<\/li>\n<li>\u6539\u8fdb\uff1a\u8bbe\u7f6e\u9501\u7684\u81ea\u52a8\u8fc7\u671f\u65f6\u95f4\uff0c\u8fc7\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u81ea\u52a8\u5220\u9664\u9501\uff0c\u8fd9\u6837\u5176\u4ed6\u7ebf\u7a0b\u5c31\u80fd\u83b7\u53d6\u5230\u9501\u4e86\u3002<\/li>\n<\/ul>\n<p>\u767d\u94f6\u65b9\u6848\uff1a<\/p>\n<ul>\n<li>\u7f3a\u9677\uff1a\u5360\u9501\u548c\u8bbe\u7f6e\u9501\u8fc7\u671f\u65f6\u95f4\u662f\u5206\u6b65\u4e24\u6b65\u6267\u884c\u7684\uff0c\u4e0d\u662f\u539f\u5b50\u64cd\u4f5c\u3002<\/li>\n<li>\u6539\u8fdb\uff1a\u5360\u9501\u548c\u8bbe\u7f6e\u9501\u8fc7\u671f\u65f6\u95f4\u4fdd\u8bc1\u539f\u5b50\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<p>\u9ec4\u91d1\u65b9\u6848\uff1a<\/p>\n<ul>\n<li>\u7f3a\u9677\uff1a\u4e3b\u52a8\u5220\u9664\u9501\u65f6\uff0c\u56e0\u9501\u7684\u503c\u90fd\u662f\u76f8\u540c\u7684\uff0c\u5c06\u5176\u4ed6\u5ba2\u6237\u7aef\u5360\u7528\u7684\u9501\u5220\u9664\u4e86\u3002<\/li>\n<li>\u6539\u8fdb\uff1a\u6bcf\u6b21\u5360\u7528\u7684\u9501\uff0c\u968f\u673a\u8bbe\u4e3a\u8f83\u5927\u7684\u503c\uff0c\u4e3b\u52a8\u5220\u9664\u9501\u65f6\uff0c\u6bd4\u8f83\u9501\u7684\u503c\u548c\u81ea\u5df1\u8bbe\u7f6e\u7684\u503c\u662f\u5426\u76f8\u7b49\u3002<\/li>\n<\/ul>\n<p>\u94c2\u91d1\u65b9\u6848\uff1a<\/p>\n<ul>\n<li>\u7f3a\u9677\uff1a\u83b7\u53d6\u9501\u3001\u6bd4\u8f83\u9501\u7684\u503c\u3001\u5220\u9664\u9501\uff0c\u8fd9\u4e09\u6b65\u662f\u975e\u539f\u5b50\u6027\u7684\u3002\u4e2d\u9014\u53c8\u53ef\u80fd\u9501\u81ea\u52a8\u8fc7\u671f\u4e86\uff0c\u53c8\u88ab\u5176\u4ed6\u5ba2\u6237\u7aef\u62a2\u5360\u4e86\u9501\uff0c\u5bfc\u81f4\u5220\u9501\u65f6\u628a\u5176\u4ed6\u5ba2\u6237\u7aef\u5360\u7528\u7684\u9501\u5220\u4e86\u3002<\/li>\n<li>\u6539\u8fdb\uff1a\u4f7f\u7528 Lua \u811a\u672c\u8fdb\u884c\u83b7\u53d6\u9501\u3001\u6bd4\u8f83\u9501\u3001\u5220\u9664\u9501\u7684\u539f\u5b50\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<p>\u94bb\u77f3\u65b9\u6848\uff1a<\/p>\n<ul>\n<li>\u7f3a\u9677\uff1a\u975e\u4e13\u4e1a\u7684\u5206\u5e03\u5f0f\u9501\u65b9\u6848\u3002<\/li>\n<li>\u6539\u8fdb\uff1aRedission \u5206\u5e03\u5f0f\u9501\u3002<\/li>\n<\/ul>\n<p>\u738b\u8005\u65b9\u6848\uff0c\u4e0b\u7bc7\u89c1\uff5e<\/p>\n<p>\u4e0a\u8ff0\u6240\u6709\u4ee3\u7801\u90fd\u57fa\u4e8e PassJava \u5f00\u6e90\u9879\u76ee\uff0c\u540e\u7aef\u3001\u524d\u7aef\u3001\u5c0f\u7a0b\u5e8f\u90fd\u4e0a\u4f20\u5230\u540c\u4e00\u4e2a\u4ed3\u5e93\u91cc\u9762\u4e86\uff0c\u5927\u5bb6\u53ef\u4ee5\u901a\u8fc7 github \u6216 \u7801\u4e91\u8bbf\u95ee\u3002\u5730\u5740\u5982\u4e0b\uff1a<\/p>\n<p>Github: https:\/\/github.com\/Jackson0714\/PassJava-Platform<\/p>\n<p>\u7801\u4e91\uff1ahttps:\/\/gitee.com\/jayh2018\/PassJava-Platform<\/p>\n<p>\u914d\u5957\u6559\u7a0b\uff1awww.passjava.cn<\/p>\n<p>\u53c2\u8003\u8d44\u6599\uff1a<\/p>\n<p>http:\/\/redis.cn\/commands\/set.html<\/p>\n<p>https:\/\/www.bilibili.com\/video\/BV1np4y1C7Yf<\/p>\n<p>\u6587\u4e2d\u5173\u4e8eredis\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300a\u8be6\u89e3 Redis \u5206\u5e03\u5f0f\u9501\u7684\u4e94\u79cd\u65b9\u6848\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8golang\u5b66\u4e60\u7f51\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n<\/p>\n<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8be6\u89e3 Redis \u5206\u5e03\u5f0f\u9501\u7684\u4e94\u79cd&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201661","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201661"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201661\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}