{"id":113575,"date":"2026-10-06T21:25:11","date_gmt":"2026-10-06T13:25:11","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/113575.html"},"modified":"2026-10-06T21:25:11","modified_gmt":"2026-10-06T13:25:11","slug":"%e5%9f%ba%e4%ba%8eredis%e5%ae%9e%e7%8e%b0%e5%88%86%e5%b8%83%e5%bc%8f%e9%94%81","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/113575.html","title":{"rendered":"\u57fa\u4e8eredis\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501"},"content":{"rendered":"<h2>\u521d\u6b65\u5b9e\u73b0<\/h2>\n<p>\u4e3b\u8981\u4e1a\u52a1\u6d41\u7a0b:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1190\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261006132508-6ac4f6b4847c1.png\" width=\"2465\" \/><\/p>\n<p>\u5728Utils\u521b\u5efaILock\u63a5\u53e3:<\/p>\n<p>package com.hmdp.utils;<\/p>\n<p>public interface ILock {<\/p>\n<p>    \/**<br \/>\n     * \u5c1d\u8bd5\u83b7\u53d6\u9501<br \/>\n     * &#064;param timeoutSec \u9501\u6301\u6709\u7684\u8d85\u65f6\u65f6\u95f4&#xff0c;\u8fc7\u671f\u540e\u81ea\u52a8\u91ca\u653e<br \/>\n     * &#064;return true\u4ee3\u8868\u83b7\u53d6\u9501\u6210\u529f&#xff1b;false\u4ee3\u8868\u83b7\u53d6\u9501\u5931\u8d25<br \/>\n     *\/<br \/>\n    boolean tryLock(long timeoutSec);<\/p>\n<p>    \/**<br \/>\n     * \u91ca\u653e\u9501<br \/>\n     *\/<br \/>\n    void unlock();<br \/>\n}<\/p>\n<p>\u521b\u5efa\u5b9e\u73b0\u7c7bSimpleRedisLock\u5e76\u5b9e\u73b0ILock\u63a5\u53e3:<\/p>\n<p>package com.hmdp.service.impl;<\/p>\n<p>import com.hmdp.utils.ILock;<\/p>\n<p>import org.springframework.data.redis.core.StringRedisTemplate;<\/p>\n<p>import java.util.concurrent.TimeUnit;<\/p>\n<p>public class SimpleRedisLock implements ILock{<\/p>\n<p>    private String name;<br \/>\n    private StringRedisTemplate stringRedisTemplate;<\/p>\n<p>    public SimpleRedisLock(String name, StringRedisTemplate stringRedisTemplate) {<br \/>\n        this.name &#061; name;<br \/>\n        this.stringRedisTemplate &#061; stringRedisTemplate;<br \/>\n    }<\/p>\n<p>    private static final String KEY_PROFIX &#061; &#034;lock:&#034;;<\/p>\n<p>    \/**<br \/>\n     * \u5c1d\u8bd5\u83b7\u53d6\u9501<br \/>\n     * &#064;param timeoutSec \u9501\u6301\u6709\u7684\u8d85\u65f6\u65f6\u95f4&#xff0c;\u8fc7\u671f\u540e\u81ea\u52a8\u91ca\u653e<br \/>\n     * &#064;return true\u4ee3\u8868\u83b7\u53d6\u9501\u6210\u529f&#xff1b;false\u4ee3\u8868\u83b7\u53d6\u9501\u5931\u8d25<br \/>\n     *\/<br \/>\n    &#064;Override<br \/>\n    public boolean tryLock(long timeoutSec) {<br \/>\n        \/\/\u83b7\u53d6\u7ebf\u7a0b\u6807\u793a<br \/>\n        long threadId &#061; Thread.currentThread().getId();<br \/>\n        \/\/\u83b7\u53d6\u9501<br \/>\n        Boolean success &#061; stringRedisTemplate.opsForValue()<br \/>\n                .setIfAbsent(KEY_PROFIX &#043; name, threadId &#043; &#034;&#034;, timeoutSec, TimeUnit.SECONDS);<br \/>\n        return Boolean.TRUE.equals(success);<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u91ca\u653e\u9501<br \/>\n     *\/<br \/>\n    &#064;Override<br \/>\n    public void unlock() {<br \/>\n        stringRedisTemplate.delete(KEY_PROFIX &#043; name);<br \/>\n    }<br \/>\n}<\/p>\n<p>\u5c06VoucherOrderServiceImpl\u4fee\u6539\u4e3a\u5982\u4e0b\u4ee3\u7801<\/p>\n<p>import com.hmdp.utils.UserHolder;<br \/>\nimport org.springframework.aop.framework.AopContext;<br \/>\nimport org.springframework.beans.factory.annotation.Autowired;<br \/>\nimport org.springframework.data.redis.core.StringRedisTemplate;<br \/>\nimport org.springframework.stereotype.Service;<br \/>\nimport org.springframework.transaction.annotation.Transactional;<\/p>\n<p>public class VoucherOrderServiceImpl extends ServiceImpl&lt;VoucherOrderMapper, Vou<br \/>\n    private ISeckillVoucherService seckillVoucherService;<br \/>\n    &#064;Autowired<br \/>\n    private RedisIdWorker redisIdWorker;<br \/>\n    &#064;Autowired<br \/>\n    private StringRedisTemplate stringRedisTemplate;<\/p>\n<p>    &#064;Override<br \/>\n    public Result secVoucherKill(Long voucherId) {<br \/>\n        public Result secVoucherKill(Long voucherId) {<\/p>\n<p>        \/\/8.\u8fd4\u56de\u8ba2\u5355id<br \/>\n        Long userId &#061; UserHolder.getUser().getId();<br \/>\n        synchronized (userId.toString().intern()) {<\/p>\n<p>        \/\/\u521b\u5efa\u9501\u5bf9\u8c61<br \/>\n        SimpleRedisLock lock &#061; new SimpleRedisLock(&#034;order:&#034; &#043; userId, stringRedisTemplate);<\/p>\n<p>        \/\/\u83b7\u53d6\u9501<br \/>\n        boolean isLock &#061; lock.tryLock(1200);<\/p>\n<p>        \/\/\u5224\u65ad\u662f\u5426\u83b7\u53d6\u6210\u529f<br \/>\n        if (!isLock){<br \/>\n            return Result.fail(&#034;\u4e0d\u5141\u8bb8\u91cd\u590d\u4e0b\u5355&#034;);<br \/>\n        }<\/p>\n<p>        try {<br \/>\n            \/\/\u83b7\u53d6\u4ee3\u7406\u5bf9\u8c61(\u4e8b\u52a1)<br \/>\n            IVoucherOrderService proxy &#061; (IVoucherOrderService) AopContext.currentProxy();<br \/>\n            return proxy.createVoucherOrder(voucherId);<br \/>\n        }finally{<br \/>\n            \/\/\u91ca\u653e\u9501<br \/>\n            lock.unlock();<br \/>\n        }<\/p>\n<p>    }<\/p>\n<p>    &#064;Transactional<br \/>\n    public Result createVoucherOrder(Long voucherId) {<br \/>\n        \/\/5.\u4e00\u4eba\u4e00\u5355<br \/>\n        Long userId &#061; UserHolder.getUser().getId();<br \/>\n            \/\/\u67e5\u8be2\u8ba2\u5355<br \/>\n            int count &#061; query().eq(&#034;user_id&#034;, userId).eq(&#034;voucher_id&#034;, voucherId).count();<br \/>\n            if (count &gt; 0){<br \/>\n                return Result.fail(&#034;\u8be5\u4f18\u60e0\u5238\u6bcf\u4eba\u4ec5\u9650\u4e00\u5355!&#034;);<br \/>\n            }<br \/>\n            \/\/6.\u6263\u51cf\u5e93\u5b58<br \/>\n            boolean success &#061; seckillVoucherService.update()<br \/>\n                    .setSql(&#034;stock &#061; stock &#8211; 1&#034;)<br \/>\n                    .eq(&#034;voucher_id&#034;, voucherId).gt(&#034;stock&#034;,0)<br \/>\n                    .update();<br \/>\n            if (!success){<br \/>\n                \/\/\u6263\u51cf\u5931\u8d25<br \/>\n                return Result.fail(&#034;\u5e93\u5b58\u4e0d\u8db3&#034;);<br \/>\n            }<br \/>\n            \/\/7.\u521b\u5efa\u8ba2\u5355<br \/>\n            VoucherOrder voucherOrder &#061; new VoucherOrder();<br \/>\n            \/\/7.1\u8ba2\u5355id<br \/>\n            long orderID &#061; redisIdWorker.nextId(&#034;order&#034;);<br \/>\n            voucherOrder.setId(orderID);<br \/>\n            \/\/7.2\u7528\u6237id<br \/>\n            voucherOrder.setUserId(userId);<br \/>\n            \/\/7.3\u4f18\u60e0\u5238id<br \/>\n            voucherOrder.setVoucherId(voucherId);<br \/>\n            \/\/7.4\u521b\u5efa\u8ba2\u5355<br \/>\n            save(voucherOrder);<br \/>\n            return Result.ok(orderID);<br \/>\n    }<br \/>\n}<\/p>\n<h2>\u89e3\u51b3redis\u5206\u5e03\u5f0f\u9501\u7684\u8bef\u5220\u95ee\u9898:<\/h2>\n<h3>\u8bef\u5220\u95ee\u9898\u51fa\u73b0\u7684\u539f\u56e0:<\/h3>\n<p>\u7ebf\u7a0bA\u83b7\u53d6\u9501\u6210\u529f\u540e,\u5904\u7406\u81ea\u5df1\u7684\u4e1a\u52a1\u903b\u8f91\u65f6\u7531\u4e8e\u79cd\u79cd\u539f\u56e0\u53ef\u80fd\u4f1a\u51fa\u73b0\u5904\u7406\u7f13\u6162\u6216\u7a0b\u5e8f\u4f11\u7720\u7b49\u60c5\u51b5,\u800credis\u9501\u5728\u83b7\u53d6\u65f6\u8bbe\u7f6e\u7684\u8fc7\u671f\u65f6\u95f4\u5df2\u7ecf\u8fc7\u671f,\u7ebf\u7a0bB\u73b0\u5728\u53ef\u4ee5\u8fdb\u884c\u83b7\u53d6\u9501\u548c\u5904\u7406\u81ea\u8eab\u4e1a\u52a1\u7684\u64cd\u4f5c,\u6b64\u65f6\u7ebf\u7a0bA\u7684\u4e1a\u52a1\u6267\u884c\u5b8c\u6210\u5f00\u59cb\u8fdb\u884c\u91ca\u653e\u9501,\u800c\u73b0\u5728redis\u4e2d\u7684\u9501\u5c5e\u4e8e\u7ebf\u7a0bB,\u6b64\u65f6\u5c31\u4f1a\u51fa\u73b0\u8bef\u5220\u95ee\u9898<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"986\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261006132509-6ac4f6b5d07f2.png\" width=\"2375\" \/><\/p>\n<h3>\u89e3\u51b3\u65b9\u6848:<\/h3>\n<p>\u5728\u83b7\u53d6\u9501\u65f6\u6dfb\u52a0\u7ebf\u7a0b\u6807\u793a(UUID&#043;\u7ebf\u7a0bid),\u5728\u91ca\u653e\u9501\u65f6\u8fdb\u884c\u6807\u793a\u5224\u65ad,\u4e00\u81f4\u5219\u53ef\u4ee5\u91ca\u653e;\u4e0d\u4e00\u81f4\u5219\u8bf4\u660e\u5f53\u524d\u7ebf\u7a0b\u7684\u6807\u793a\u65e9\u5df2\u8fc7\u671f,\u4e0d\u9700\u8981\u518d\u8fdb\u884c\u624b\u52a8\u5220\u9664<\/p>\n<p>\u4ee3\u7801\u903b\u8f91\u6539\u52a8\u5982\u4e0b:<\/p>\n<p>\/**<br \/>\n     * \u5c1d\u8bd5\u83b7\u53d6\u9501<br \/>\n     * &#064;param timeoutSec \u9501\u6301\u6709\u7684\u8d85\u65f6\u65f6\u95f4&#xff0c;\u8fc7\u671f\u540e\u81ea\u52a8\u91ca\u653e<br \/>\n     * &#064;return true\u4ee3\u8868\u83b7\u53d6\u9501\u6210\u529f&#xff1b;false\u4ee3\u8868\u83b7\u53d6\u9501\u5931\u8d25<br \/>\n     *\/<br \/>\n    &#064;Override<br \/>\n    public boolean tryLock(long timeoutSec) {<br \/>\n        \/\/\u83b7\u53d6\u7ebf\u7a0b\u6807\u793a<br \/>\n        String threadId &#061; ID_profix &#043; Thread.currentThread().getId();<br \/>\n        \/\/\u83b7\u53d6\u9501<br \/>\n        Boolean success &#061; stringRedisTemplate.opsForValue()<br \/>\n                .setIfAbsent(KEY_PROFIX &#043; name, threadId &#043; &#034;&#034;, timeoutSec, TimeUnit.SECONDS);<br \/>\n        return Boolean.TRUE.equals(success);<br \/>\n    }<\/p>\n<p>\/**<br \/>\n     * \u91ca\u653e\u9501<br \/>\n     *\/<br \/>\n    &#064;Override<br \/>\n    public void unlock() {<br \/>\n        \/\/\u83b7\u53d6\u7ebf\u7a0b\u6807\u793a<br \/>\n        String threadId &#061; ID_profix &#043; Thread.currentThread().getId();<br \/>\n        \/\/\u83b7\u53d6\u9501\u4e2d\u7684\u6807\u793a<br \/>\n        String id &#061; stringRedisTemplate.opsForValue().get(KEY_PROFIX &#043; name);<br \/>\n        \/\/\u5224\u65ad\u6807\u793a\u662f\u5426\u4e00\u81f4<br \/>\n        if (threadId.equals(id)){<br \/>\n            \/\/\u91ca\u653e\u9501<br \/>\n            stringRedisTemplate.delete(KEY_PROFIX &#043; name);<br \/>\n        }<br \/>\n    }<\/p>\n<h2>\u57fa\u4e8eLua\u811a\u672c\u786e\u4fdd\u91ca\u653e\u9501\u64cd\u4f5c\u7684\u539f\u5b50\u6027<\/h2>\n<p>\u5728\u7ebf\u7a0bA\u91ca\u653e\u9501\u64cd\u4f5c\u65f6,\u5224\u65ad\u7ebf\u7a0b\u8868\u793a\u4e0e\u9501\u6807\u793a\u4e00\u81f4\u540e,\u8fdb\u884c\u91ca\u653e\u64cd\u4f5c\u53ef\u80fd\u4f1a\u51fa\u73b0\u4e1a\u52a1\u963b\u585e,\u9501\u5230\u671f\u81ea\u52a8\u91ca\u653e;\u6b64\u65f6\u7ebf\u7a0bB\u53ef\u4ee5\u83b7\u53d6\u9501\u64cd\u4f5c\u6210\u529f,\u5982\u679c\u7ebf\u7a0bA\u4e1a\u52a1\u6062\u590d\u5c31\u53ef\u80fd\u5220\u6389\u5176\u4ed6\u7ebf\u7a0b\u7684\u9501<\/p>\n<h3>\u5b9e\u73b0\u65b9\u6848:<\/h3>\n<p>\u7f16\u5199Lua\u811a\u672c<\/p>\n<p>&#8212; \u6bd4\u8f83\u7ebf\u7a0b\u6807\u793a\u4e0e\u9501\u4e2d\u7684\u6807\u793a\u662f\u5426\u4e00\u81f4<br \/>\nif (redis.call(&#039;get&#039;, KEYS[1]) &#061;&#061; ARGV[1] ) then<br \/>\n    &#8212;\u91ca\u653e\u9501<br \/>\n    redis.call(&#039;del&#039;,KEYS[1])<br \/>\nend<br \/>\nreturn 0<\/p>\n<p>\u4fee\u6539\u91ca\u653e\u9501\u903b\u8f91<\/p>\n<p>    \/**<br \/>\n     * \u91ca\u653e\u9501<br \/>\n     *\/<br \/>\n    public void unlock(){<br \/>\n        \/\/\u8c03\u7528lua\u811a\u672c<br \/>\n        stringRedisTemplate.execute(<br \/>\n                UNLOCK_SCRIPT,<br \/>\n                Collections.singletonList(KEY_PROFIX &#043; name),<br \/>\n                ID_profix &#043; Thread.currentThread().getId());<\/p>\n<p>    }<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u521d\u6b65\u5b9e\u73b0\u4e3b\u8981\u4e1a\u52a1\u6d41\u7a0b:\u5728Utils\u521b\u5efaILock\u63a5\u53e3:package com.hmdp.utils;public interface ILock {\/*** \u5c1d\u8bd5\u83b7\u53d6\u9501* param timeoutSec \u9501\u6301\u6709\u7684\u8d85\u65f6\u65f6\u95f4&#xff0c;\u8fc7\u671f\u540e\u81ea\u52a8\u91ca\u653e* return true\u4ee3\u8868\u83b7\u53d6\u9501\u6210\u529f&#xff1b;false\u4ee3\u8868\u83b7\u53d6\u9501\u5931\u8d25*\/boolean tryLock(long timeoutSec);\/*** \u91ca\u653e\u9501*\/void unlock();<br \/>\n}\u521b\u5efa\u5b9e\u73b0\u7c7bSimpleRe<\/p>\n","protected":false},"author":2,"featured_media":113573,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11653,99,105,569,664,100],"topic":[],"class_list":["post-113575","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-11653","tag-java","tag-redis","tag-569","tag-664","tag-100"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u57fa\u4e8eredis\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/113575.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u57fa\u4e8eredis\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u521d\u6b65\u5b9e\u73b0\u4e3b\u8981\u4e1a\u52a1\u6d41\u7a0b:\u5728Utils\u521b\u5efaILock\u63a5\u53e3:package com.hmdp.utils;public interface ILock {\/*** \u5c1d\u8bd5\u83b7\u53d6\u9501* param timeoutSec \u9501\u6301\u6709\u7684\u8d85\u65f6\u65f6\u95f4&#xff0c;\u8fc7\u671f\u540e\u81ea\u52a8\u91ca\u653e* return true\u4ee3\u8868\u83b7\u53d6\u9501\u6210\u529f&#xff1b;false\u4ee3\u8868\u83b7\u53d6\u9501\u5931\u8d25*\/boolean tryLock(long timeoutSec);\/*** \u91ca\u653e\u9501*\/void unlock(); }\u521b\u5efa\u5b9e\u73b0\u7c7bSimpleRe\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/113575.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-06T13:25:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261006132508-6ac4f6b4847c1.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/113575.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/113575.html\",\"name\":\"\u57fa\u4e8eredis\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-06T13:25:11+00:00\",\"dateModified\":\"2026-10-06T13:25:11+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/113575.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/113575.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/113575.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u57fa\u4e8eredis\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u57fa\u4e8eredis\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/113575.html","og_locale":"zh_CN","og_type":"article","og_title":"\u57fa\u4e8eredis\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u521d\u6b65\u5b9e\u73b0\u4e3b\u8981\u4e1a\u52a1\u6d41\u7a0b:\u5728Utils\u521b\u5efaILock\u63a5\u53e3:package com.hmdp.utils;public interface ILock {\/*** \u5c1d\u8bd5\u83b7\u53d6\u9501* param timeoutSec \u9501\u6301\u6709\u7684\u8d85\u65f6\u65f6\u95f4&#xff0c;\u8fc7\u671f\u540e\u81ea\u52a8\u91ca\u653e* return true\u4ee3\u8868\u83b7\u53d6\u9501\u6210\u529f&#xff1b;false\u4ee3\u8868\u83b7\u53d6\u9501\u5931\u8d25*\/boolean tryLock(long timeoutSec);\/*** \u91ca\u653e\u9501*\/void unlock(); }\u521b\u5efa\u5b9e\u73b0\u7c7bSimpleRe","og_url":"https:\/\/www.wsisp.com\/helps\/113575.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-06T13:25:11+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261006132508-6ac4f6b4847c1.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/113575.html","url":"https:\/\/www.wsisp.com\/helps\/113575.html","name":"\u57fa\u4e8eredis\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-06T13:25:11+00:00","dateModified":"2026-10-06T13:25:11+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/113575.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/113575.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/113575.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u57fa\u4e8eredis\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/113575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=113575"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/113575\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/113573"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=113575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=113575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=113575"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=113575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}