{"id":4363,"date":"2024-10-14T22:10:54","date_gmt":"2024-10-14T14:10:54","guid":{"rendered":"https:\/\/www.talktop.cn\/?p=4363"},"modified":"2024-11-11T21:46:18","modified_gmt":"2024-11-11T13:46:18","slug":"%e8%b6%85%e8%af%a6%e7%bb%86%ef%bc%81redis%e5%88%86%e5%b8%83%e5%bc%8f%e9%94%81%e6%9c%80%e4%bd%b3%e5%ae%9e%e8%b7%b5%e4%b8%8e%e9%ab%98%e6%95%88%e4%bc%98%e5%8c%96%e7%ad%96%e7%95%a5","status":"publish","type":"post","link":"https:\/\/www.talktop.cn\/?p=4363","title":{"rendered":"\u8d85\u8be6\u7ec6\uff01Redis\u5206\u5e03\u5f0f\u9501\u6700\u4f73\u5b9e\u8df5\u4e0e\u9ad8\u6548\u4f18\u5316\u7b56\u7565"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\"><strong>\u4e00\u3001\u57fa\u4e8eRedis\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501<\/strong><\/h5>\n\n\n\n<p><strong>\uff081\uff09\u57fa\u4e8eLua\u811a\u672c(\u5305\u542bSETNX + EXPIRE\u4e24\u6761\u6307\u4ee4)\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-4919c7f0bf03a7f32f82693bf3b8abc2\"><code>\n\/\/ \u5c1d\u8bd5\u83b7\u53d6\u9501\npublic boolean tryLock(String lockKey, String lockValue, int expireTime) {\n    \/\/ Lua \u811a\u672c\n    String luaScript = \n        \"if redis.call('setnx', KEYS&#91;1], ARGV&#91;1]) == 1 then \" +\n        \"   redis.call('expire', KEYS&#91;1], ARGV&#91;2]) \" +\n        \"   return 1 \" +\n        \"else \" +\n        \"   return 0 \" +\n        \"end\";\n\n    \/\/ \u8c03\u7528 Lua \u811a\u672c\n    Object result = jedis.eval(luaScript,\n                               Collections.singletonList(lockKey),\n                               Arrays.asList(lockValue, String.valueOf(expireTime)));\n\n    \/\/ \u5224\u65ad\u662f\u5426\u6210\u529f\u83b7\u53d6\u9501\n    return result.equals(1L);\n}\n\n\/\/ \u91ca\u653e\u9501\npublic void releaseLock(String lockKey) {\n    jedis.del(lockKey);\n}    <\/code><\/pre>\n\n\n\n<p><strong>\uff082\uff09\u57fa\u4e8eSET\u7684\u6269\u5c55\u547d\u4ee4\uff08SET EX PX NX\uff09\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501<\/strong><\/p>\n\n\n\n<p>SET\u547d\u4ee4\u6269\u5c55\u547d\u4ee4<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-bd5d10329936afc6995bb9eb279dac11\"><code>SET key value &#91;EX seconds | PX milliseconds] &#91;NX | XX]<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>NX :\u8868\u793akey\u4e0d\u5b58\u5728\u7684\u65f6\u5019\uff0c\u624d\u80fdset\u6210\u529f\uff0c\u4e5f\u5373\u4fdd\u8bc1\u53ea\u6709\u7b2c\u4e00\u4e2a\u5ba2\u6237\u7aef\u8bf7\u6c42\u624d\u80fd\u83b7\u5f97\u9501\uff0c\u800c\u5176\u4ed6\u5ba2\u6237\u7aef\u8bf7\u6c42\u53ea\u80fd\u7b49\u5176\u91ca\u653e\u9501\uff0c\u624d\u80fd\u83b7\u53d6\u3002<\/li>\n\n\n\n<li>EX seconds :\u8bbe\u5b9akey\u7684\u8fc7\u671f\u65f6\u95f4\uff0c\u65f6\u95f4\u5355\u4f4d\u662f\u79d2\u3002<\/li>\n\n\n\n<li>PX milliseconds: \u8bbe\u5b9akey\u7684\u8fc7\u671f\u65f6\u95f4\uff0c\u5355\u4f4d\u4e3a\u6beb\u79d2<\/li>\n\n\n\n<li>XX: \u4ec5\u5f53key\u5b58\u5728\u65f6\u8bbe\u7f6e\u503c<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-c5addd036cc9320bddd32504a1d92447\"><code>\nimport redis.clients.jedis.Jedis;\nimport java.util.UUID;\n\npublic class RedisDistributedLock {\n    \n    \/**\n     * \u5c1d\u8bd5\u83b7\u53d6\u9501\n     *\n     * @param lockKey    \u9501\u7684\u952e\n     * @param lockValue  \u9501\u7684\u503c\uff08\u901a\u5e38\u4f7f\u7528\u552f\u4e00\u503c\u6765\u786e\u4fdd\u53ea\u6709\u6301\u6709\u8be5\u503c\u7684\u5ba2\u6237\u7aef\u624d\u80fd\u91ca\u653e\u9501\uff09\n     * @param expireTime \u9501\u7684\u8fc7\u671f\u65f6\u95f4\uff08\u5355\u4f4d\uff1a\u79d2\uff09\n     * @return true \u8868\u793a\u83b7\u53d6\u9501\u6210\u529f\uff0cfalse \u8868\u793a\u83b7\u53d6\u9501\u5931\u8d25\n     *\/\n    public boolean tryLock(String lockKey, String lockValue, int expireTime) {\n        String result = jedis.set(lockKey, lockValue, \"NX\", \"EX\", expireTime);\n        return \"OK\".equals(result);  \/\/ \u8fd4\u56de \"OK\" \u8868\u793a\u6210\u529f\u83b7\u53d6\u9501\n    }\n\n    \/**\n     * \u91ca\u653e\u9501\n     *\n     * @param lockKey   \u9501\u7684\u952e\n     * @param lockValue \u9501\u7684\u503c\uff0c\u786e\u4fdd\u53ea\u6709\u6301\u6709\u8be5\u503c\u7684\u5ba2\u6237\u7aef\u624d\u80fd\u91ca\u653e\u9501\n     *\/\n    public void releaseLock(String lockKey, String lockValue) {\n        \/\/ Lua \u811a\u672c\u786e\u4fdd\u53ea\u6709\u6301\u6709\u8be5\u503c\u7684\u5ba2\u6237\u7aef\u624d\u80fd\u91ca\u653e\u9501\n        String luaScript = \"if redis.call('get', KEYS&#91;1]) == ARGV&#91;1] then \" +\n                           \"return redis.call('del', KEYS&#91;1]) \" +\n                           \"else return 0 end\";\n        jedis.eval(luaScript, 1, lockKey, lockValue);\n    }\n\n    public static void main(String&#91;] args) {\n        \/\/ \u521b\u5efa Jedis \u5b9e\u4f8b\u8fde\u63a5\u5230 Redis\n        Jedis jedis = new Jedis(\"localhost\");\n\n        \/\/ \u5b9e\u4f8b\u5316 RedisDistributedLock\n        RedisDistributedLock lock = new RedisDistributedLock(jedis);\n\n        String lockKey = \"lock:resource\";  \/\/ \u9501\u7684\u952e\n        String lockValue = UUID.randomUUID().toString();  \/\/ \u4f7f\u7528 UUID \u751f\u6210\u552f\u4e00\u7684\u9501\u503c\n        int expireTime = 10;  \/\/ \u9501\u7684\u8fc7\u671f\u65f6\u95f4\uff0c\u5355\u4f4d\u4e3a\u79d2\n\n        \/\/ \u5c1d\u8bd5\u83b7\u53d6\u9501\n        if (lock.tryLock(lockKey, lockValue, expireTime)) {\n            try {\n                System.out.println(\"\u9501\u83b7\u53d6\u6210\u529f\uff0c\u6267\u884c\u64cd\u4f5c...\");\n\n                \/\/ \u6267\u884c\u9700\u8981\u52a0\u9501\u7684\u64cd\u4f5c\n                \/\/ ...\n\n            } finally {\n                \/\/ \u91ca\u653e\u9501\n                lock.releaseLock(lockKey, lockValue);\n                System.out.println(\"\u9501\u5df2\u91ca\u653e\");\n            }\n        } else {\n            System.out.println(\"\u9501\u83b7\u53d6\u5931\u8d25\uff0c\u8d44\u6e90\u88ab\u5360\u7528\");\n        }\n\n        \/\/ \u5173\u95ed Jedis \u8fde\u63a5\n        jedis.close();\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>\uff083\uff09\u57fa\u4e8eRedisson+Redlock\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501<\/strong><\/p>\n\n\n\n<p>Redisson\u5e95\u5c42\u539f\u7406\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"643\" src=\"https:\/\/www.talktop.cn\/wp-content\/uploads\/2024\/10\/image-43-1024x643.png\" alt=\"\" class=\"wp-image-4364\" srcset=\"https:\/\/www.talktop.cn\/wp-content\/uploads\/2024\/10\/image-43-1024x643.png 1024w, https:\/\/www.talktop.cn\/wp-content\/uploads\/2024\/10\/image-43-300x188.png 300w, https:\/\/www.talktop.cn\/wp-content\/uploads\/2024\/10\/image-43-768x482.png 768w, https:\/\/www.talktop.cn\/wp-content\/uploads\/2024\/10\/image-43.png 1080w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Redisson\u4e5f\u662f\u4f7f\u7528Redis\u7684SET key value NX PX expireTime \u547d\u4ee4\uff08\u5373 SET \u547d\u4ee4\u7684\u6269\u5c55\u9009\u9879 NX \u548c PX\uff09\uff0c\u8fd9\u662f\u4e00\u4e2a\u539f\u5b50\u6027\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>Redisson \u91c7\u7528\u4e86\u201c\u770b\u95e8\u72d7\u201d\u673a\u5236\uff0c\u5f53\u5ba2\u6237\u7aef\u83b7\u53d6\u9501\u6210\u529f\u540e\uff0cRedisson \u4f1a\u542f\u52a8\u4e00\u4e2a\u540e\u53f0\u7ebf\u7a0b\u5b9a\u671f\u4e3a\u9501\u7eed\u671f\u3002<\/p>\n\n\n\n<p>Redisson \u4e3a\u6bcf\u4e2a\u7ebf\u7a0b\u751f\u6210\u4e00\u4e2a\u552f\u4e00\u7684 UUID \u6807\u8bc6\uff0c\u4ee5\u786e\u4fdd\u9501\u7684\u6301\u6709\u8005\u662f\u552f\u4e00\u7684\u3002<\/p>\n\n\n\n<p>Redisson \u5206\u5e03\u5f0f\u9501\u662f\u53ef\u91cd\u5165\u7684\uff0c\u5373\u4e00\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u591a\u6b21\u83b7\u53d6\u540c\u4e00\u628a\u9501\uff0c\u800c\u4e0d\u4f1a\u53d1\u751f\u6b7b\u9501\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-7377b6161e22737be986fa83ceb802ba\"><code>import org.redisson.Redisson;\nimport org.redisson.api.RLock;\nimport org.redisson.api.RedissonClient;\nimport org.redisson.config.Config;\n\nimport java.util.concurrent.TimeUnit;\n\npublic class RedissonRedlockExample {\n\n    public static void main(String&#91;] args) {\n        \/\/ 1. \u914d\u7f6e\u591a\u4e2a Redis \u8282\u70b9\n        Config config = new Config();\n        config.useReplicatedServers()\n              .addNodeAddress(\"redis:\/\/127.0.0.1:6379\", \"redis:\/\/127.0.0.2:6379\",\n                              \"redis:\/\/127.0.0.3:6379\", \"redis:\/\/127.0.0.4:6379\",\n                              \"redis:\/\/127.0.0.5:6379\");\n\n        \/\/ 2. \u521b\u5efa Redisson \u5ba2\u6237\u7aef\n        RedissonClient redissonClient = Redisson.create(config);\n\n        \/\/ 3. \u83b7\u53d6\u5206\u5e03\u5f0f\u9501\n        RLock lock = redissonClient.getLock(\"redlockKey\");\n        try {\n            \/\/ 4. \u5c1d\u8bd5\u52a0\u9501\uff0c\u7b49\u5f85\u65f6\u95f410\u79d2\uff0c\u9501\u5b9a\u65f6\u95f430\u79d2\n            if (lock.tryLock(10, 30, TimeUnit.SECONDS)) {\n                try {\n                    System.out.println(\"\u6210\u529f\u83b7\u53d6 Redlock \u9501\uff0c\u6267\u884c\u64cd\u4f5c...\");\n                    \/\/ \u6267\u884c\u9700\u8981\u52a0\u9501\u7684\u4e1a\u52a1\u903b\u8f91\n                } finally {\n                    \/\/ 5. \u91ca\u653e\u9501\n                    lock.unlock();\n                    System.out.println(\"Redlock \u9501\u91ca\u653e\u6210\u529f\");\n                }\n            } else {\n                System.out.println(\"\u672a\u80fd\u83b7\u53d6\u9501\uff0c\u8d44\u6e90\u88ab\u5360\u7528\");\n            }\n        } catch (InterruptedException e) {\n            e.printStackTrace();\n        } finally {\n            \/\/ 6. \u5173\u95ed Redisson \u5ba2\u6237\u7aef\n            redissonClient.shutdown();\n        }\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u57fa\u4e8eRedis\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501 \uff081\uff09\u57fa\u4e8eLua\u811a\u672c(\u5305\u542bSETNX + EXPIRE\u4e24\u6761\u6307\u4ee4)\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[118],"tags":[186,16],"class_list":["post-4363","post","type-post","status-publish","format-standard","hentry","category-118","tag-186","tag-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u8d85\u8be6\u7ec6\uff01Redis\u5206\u5e03\u5f0f\u9501\u6700\u4f73\u5b9e\u8df5\u4e0e\u9ad8\u6548\u4f18\u5316\u7b56\u7565<\/title>\n<meta name=\"description\" content=\"Redis\u5206\u5e03\u5f0f\u9501\u6700\u4f73\u5b9e\u8df5Redisson\uff0c\u57fa\u4e8eRedis\u7684setNX\u547d\u4ee4\uff0cRedisson \u91c7\u7528\u4e86\u201c\u770b\u95e8\u72d7\u201d\u673a\u5236\uff0c\u5f53\u5ba2\u6237\u7aef\u83b7\u53d6\u9501\u6210\u529f\u540e\uff0cRedisson \u4f1a\u542f\u52a8\u4e00\u4e2a\u540e\u53f0\u7ebf\u7a0b\u5b9a\u671f\u4e3a\u9501\u7eed\u671f\u3002\" \/>\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.talktop.cn\/?p=4363\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.talktop.cn\/?p=4363#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.talktop.cn\/?p=4363\"},\"author\":{\"name\":\"AI\u98ce\u5411\u6807\",\"@id\":\"https:\/\/www.talktop.cn\/#\/schema\/person\/25908db5f654913a22bc38d48fad71ab\"},\"headline\":\"\u8d85\u8be6\u7ec6\uff01Redis\u5206\u5e03\u5f0f\u9501\u6700\u4f73\u5b9e\u8df5\u4e0e\u9ad8\u6548\u4f18\u5316\u7b56\u7565\",\"datePublished\":\"2024-10-14T14:10:54+00:00\",\"dateModified\":\"2024-11-11T13:46:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.talktop.cn\/?p=4363\"},\"wordCount\":41,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.talktop.cn\/#\/schema\/person\/25908db5f654913a22bc38d48fad71ab\"},\"image\":{\"@id\":\"https:\/\/www.talktop.cn\/?p=4363#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.talktop.cn\/wp-content\/uploads\/2024\/10\/image-43-1024x643.png\",\"keywords\":[\"\u5206\u5e03\u5f0f\u9501\",\"\u7f16\u7a0b\"],\"articleSection\":[\"\u540e\u7aef\u5f00\u53d1\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.talktop.cn\/?p=4363#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.talktop.cn\/?p=4363\",\"url\":\"https:\/\/www.talktop.cn\/?p=4363\",\"name\":\"\u8d85\u8be6\u7ec6\uff01Redis\u5206\u5e03\u5f0f\u9501\u6700\u4f73\u5b9e\u8df5\u4e0e\u9ad8\u6548\u4f18\u5316\u7b56\u7565\",\"isPartOf\":{\"@id\":\"https:\/\/www.talktop.cn\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.talktop.cn\/?p=4363#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.talktop.cn\/?p=4363#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.talktop.cn\/wp-content\/uploads\/2024\/10\/image-43-1024x643.png\",\"datePublished\":\"2024-10-14T14:10:54+00:00\",\"dateModified\":\"2024-11-11T13:46:18+00:00\",\"description\":\"Redis\u5206\u5e03\u5f0f\u9501\u6700\u4f73\u5b9e\u8df5Redisson\uff0c\u57fa\u4e8eRedis\u7684setNX\u547d\u4ee4\uff0cRedisson \u91c7\u7528\u4e86\u201c\u770b\u95e8\u72d7\u201d\u673a\u5236\uff0c\u5f53\u5ba2\u6237\u7aef\u83b7\u53d6\u9501\u6210\u529f\u540e\uff0cRedisson \u4f1a\u542f\u52a8\u4e00\u4e2a\u540e\u53f0\u7ebf\u7a0b\u5b9a\u671f\u4e3a\u9501\u7eed\u671f\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/www.talktop.cn\/?p=4363#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.talktop.cn\/?p=4363\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.talktop.cn\/?p=4363#primaryimage\",\"url\":\"https:\/\/www.talktop.cn\/wp-content\/uploads\/2024\/10\/image-43.png\",\"contentUrl\":\"https:\/\/www.talktop.cn\/wp-content\/uploads\/2024\/10\/image-43.png\",\"width\":1080,\"height\":678},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.talktop.cn\/?p=4363#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.talktop.cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u8d85\u8be6\u7ec6\uff01Redis\u5206\u5e03\u5f0f\u9501\u6700\u4f73\u5b9e\u8df5\u4e0e\u9ad8\u6548\u4f18\u5316\u7b56\u7565\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.talktop.cn\/#website\",\"url\":\"https:\/\/www.talktop.cn\/\",\"name\":\"AI\u98ce\u5411\u6807\",\"description\":\"ChatGPT \u4eba\u5de5\u667a\u80fd \u7f16\u7a0b\u6280\u672f AIGC \u540e\u7aef\u6280\u672f \u524d\u7aef\u6280\u672f \u70ed\u95e8\u63d2\u4ef6 \u8fd0\u8425\u76f8\u5173 ChatGPT\u8ba2\u9605 Claude\u5145\u503c \u6d77\u5916\u5145\u503c \u8c37\u6b4c\u90ae\u7bb1\",\"publisher\":{\"@id\":\"https:\/\/www.talktop.cn\/#\/schema\/person\/25908db5f654913a22bc38d48fad71ab\"},\"alternateName\":\"AI\u98ce\u5411\u6807\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.talktop.cn\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.talktop.cn\/#\/schema\/person\/25908db5f654913a22bc38d48fad71ab\",\"name\":\"AI\u98ce\u5411\u6807\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.talktop.cn\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.talktop.cn\/wp-content\/uploads\/2023\/10\/cropped-f09060ba975518b80d3b0b63b47108a6.jpeg\",\"contentUrl\":\"https:\/\/www.talktop.cn\/wp-content\/uploads\/2023\/10\/cropped-f09060ba975518b80d3b0b63b47108a6.jpeg\",\"width\":512,\"height\":512,\"caption\":\"AI\u98ce\u5411\u6807\"},\"logo\":{\"@id\":\"https:\/\/www.talktop.cn\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/\/\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u8d85\u8be6\u7ec6\uff01Redis\u5206\u5e03\u5f0f\u9501\u6700\u4f73\u5b9e\u8df5\u4e0e\u9ad8\u6548\u4f18\u5316\u7b56\u7565","description":"Redis\u5206\u5e03\u5f0f\u9501\u6700\u4f73\u5b9e\u8df5Redisson\uff0c\u57fa\u4e8eRedis\u7684setNX\u547d\u4ee4\uff0cRedisson \u91c7\u7528\u4e86\u201c\u770b\u95e8\u72d7\u201d\u673a\u5236\uff0c\u5f53\u5ba2\u6237\u7aef\u83b7\u53d6\u9501\u6210\u529f\u540e\uff0cRedisson \u4f1a\u542f\u52a8\u4e00\u4e2a\u540e\u53f0\u7ebf\u7a0b\u5b9a\u671f\u4e3a\u9501\u7eed\u671f\u3002","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.talktop.cn\/?p=4363","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.talktop.cn\/?p=4363#article","isPartOf":{"@id":"https:\/\/www.talktop.cn\/?p=4363"},"author":{"name":"AI\u98ce\u5411\u6807","@id":"https:\/\/www.talktop.cn\/#\/schema\/person\/25908db5f654913a22bc38d48fad71ab"},"headline":"\u8d85\u8be6\u7ec6\uff01Redis\u5206\u5e03\u5f0f\u9501\u6700\u4f73\u5b9e\u8df5\u4e0e\u9ad8\u6548\u4f18\u5316\u7b56\u7565","datePublished":"2024-10-14T14:10:54+00:00","dateModified":"2024-11-11T13:46:18+00:00","mainEntityOfPage":{"@id":"https:\/\/www.talktop.cn\/?p=4363"},"wordCount":41,"commentCount":0,"publisher":{"@id":"https:\/\/www.talktop.cn\/#\/schema\/person\/25908db5f654913a22bc38d48fad71ab"},"image":{"@id":"https:\/\/www.talktop.cn\/?p=4363#primaryimage"},"thumbnailUrl":"https:\/\/www.talktop.cn\/wp-content\/uploads\/2024\/10\/image-43-1024x643.png","keywords":["\u5206\u5e03\u5f0f\u9501","\u7f16\u7a0b"],"articleSection":["\u540e\u7aef\u5f00\u53d1"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.talktop.cn\/?p=4363#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.talktop.cn\/?p=4363","url":"https:\/\/www.talktop.cn\/?p=4363","name":"\u8d85\u8be6\u7ec6\uff01Redis\u5206\u5e03\u5f0f\u9501\u6700\u4f73\u5b9e\u8df5\u4e0e\u9ad8\u6548\u4f18\u5316\u7b56\u7565","isPartOf":{"@id":"https:\/\/www.talktop.cn\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.talktop.cn\/?p=4363#primaryimage"},"image":{"@id":"https:\/\/www.talktop.cn\/?p=4363#primaryimage"},"thumbnailUrl":"https:\/\/www.talktop.cn\/wp-content\/uploads\/2024\/10\/image-43-1024x643.png","datePublished":"2024-10-14T14:10:54+00:00","dateModified":"2024-11-11T13:46:18+00:00","description":"Redis\u5206\u5e03\u5f0f\u9501\u6700\u4f73\u5b9e\u8df5Redisson\uff0c\u57fa\u4e8eRedis\u7684setNX\u547d\u4ee4\uff0cRedisson \u91c7\u7528\u4e86\u201c\u770b\u95e8\u72d7\u201d\u673a\u5236\uff0c\u5f53\u5ba2\u6237\u7aef\u83b7\u53d6\u9501\u6210\u529f\u540e\uff0cRedisson \u4f1a\u542f\u52a8\u4e00\u4e2a\u540e\u53f0\u7ebf\u7a0b\u5b9a\u671f\u4e3a\u9501\u7eed\u671f\u3002","breadcrumb":{"@id":"https:\/\/www.talktop.cn\/?p=4363#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.talktop.cn\/?p=4363"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.talktop.cn\/?p=4363#primaryimage","url":"https:\/\/www.talktop.cn\/wp-content\/uploads\/2024\/10\/image-43.png","contentUrl":"https:\/\/www.talktop.cn\/wp-content\/uploads\/2024\/10\/image-43.png","width":1080,"height":678},{"@type":"BreadcrumbList","@id":"https:\/\/www.talktop.cn\/?p=4363#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.talktop.cn\/"},{"@type":"ListItem","position":2,"name":"\u8d85\u8be6\u7ec6\uff01Redis\u5206\u5e03\u5f0f\u9501\u6700\u4f73\u5b9e\u8df5\u4e0e\u9ad8\u6548\u4f18\u5316\u7b56\u7565"}]},{"@type":"WebSite","@id":"https:\/\/www.talktop.cn\/#website","url":"https:\/\/www.talktop.cn\/","name":"AI\u98ce\u5411\u6807","description":"ChatGPT \u4eba\u5de5\u667a\u80fd \u7f16\u7a0b\u6280\u672f AIGC \u540e\u7aef\u6280\u672f \u524d\u7aef\u6280\u672f \u70ed\u95e8\u63d2\u4ef6 \u8fd0\u8425\u76f8\u5173 ChatGPT\u8ba2\u9605 Claude\u5145\u503c \u6d77\u5916\u5145\u503c \u8c37\u6b4c\u90ae\u7bb1","publisher":{"@id":"https:\/\/www.talktop.cn\/#\/schema\/person\/25908db5f654913a22bc38d48fad71ab"},"alternateName":"AI\u98ce\u5411\u6807","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.talktop.cn\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/www.talktop.cn\/#\/schema\/person\/25908db5f654913a22bc38d48fad71ab","name":"AI\u98ce\u5411\u6807","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.talktop.cn\/#\/schema\/person\/image\/","url":"https:\/\/www.talktop.cn\/wp-content\/uploads\/2023\/10\/cropped-f09060ba975518b80d3b0b63b47108a6.jpeg","contentUrl":"https:\/\/www.talktop.cn\/wp-content\/uploads\/2023\/10\/cropped-f09060ba975518b80d3b0b63b47108a6.jpeg","width":512,"height":512,"caption":"AI\u98ce\u5411\u6807"},"logo":{"@id":"https:\/\/www.talktop.cn\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/\/"]}]}},"_links":{"self":[{"href":"https:\/\/www.talktop.cn\/index.php?rest_route=\/wp\/v2\/posts\/4363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.talktop.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.talktop.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.talktop.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.talktop.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4363"}],"version-history":[{"count":0,"href":"https:\/\/www.talktop.cn\/index.php?rest_route=\/wp\/v2\/posts\/4363\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.talktop.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.talktop.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.talktop.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}