{"id":1166,"date":"2025-05-14T18:14:44","date_gmt":"2025-05-14T10:14:44","guid":{"rendered":"https:\/\/eve2333.top\/?p=1166"},"modified":"2025-06-16T13:14:12","modified_gmt":"2025-06-16T05:14:12","slug":"saas%e7%9f%ad%e9%93%be%e6%8e%a5%e7%b3%bb%e7%bb%9f-%e6%96%b0%e6%89%8b%e4%bb%8e%e9%9b%b6%e5%ad%a6%e4%b9%a0-2","status":"publish","type":"post","link":"https:\/\/eve2333.top\/?p=1166","title":{"rendered":"SaaS\u77ed\u94fe\u63a5\u7cfb\u7edf-\u65b0\u624b\u4ece\u96f6\u5b66\u4e60 2"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">&nbsp;\u7528\u6237\u654f\u611f\u4fe1\u606f\u63a5\u53e3\u8fd4\u56de\u8131\u654f<\/h3>\n\n\n\n<p>\u6211\u4eec\u770b\u4e00\u4e0b12306\u662f\u5982\u4f55\u5b9e\u73b0\u8fd9\u4e2a\u7684\uff0c\u6211\u4eec\u5728\u8fdb\u5165\u8ba2\u5355\u63d0\u4ea4\u9875\u7684\u65f6\u5019\uff0c\u5c31\u662f\u5728\u4f60\u9009\u597d\u8f66\u6b21\u7684\u65f6\u5019\u9009\u62e9\u4e58\u8f66\u4eba\u7684\u65f6\u5019\u4ed6\u7684\u8bc1\u4ef6\u53f7\u7801\u91cc\u9762\u662f\u52a0\u661f\u53f7\u7684\uff0c\u7136\u540e\u5982\u679c\u8bf4\u8bc1\u4ef6\u53f7\u7801\u6ca1\u6709\u52a0*\uff0c\u5982\u679c\u6709\u4eba\u622a\u65ad\u4f60\u7684\u6d41\u91cf\uff0c\u5e76\u4e14\u4f1a\u89e3\u5305\uff0c\u654f\u611f\u4fe1\u606f\u5c31\u6cc4\u9732\u4e86\uff0c\u66f4\u4e0d\u80fd\u7528\u524d\u7aef\u5904\u7406\u7684\u65b9\u5f0f\uff0c\u524d\u7aef\u662f\u7ed9\u4e0d\u61c2\u7684\u4eba\u73a9\u7684\uff0cpost\u6253\u4e00\u4e0b\u63a5\u53e3\u5c31\u770b\u51fa\u4e86\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\uff0c\u5c31\u662f\u8bf4\u6211\u4eec\u4ece\u540e\u7aef\u8fd4\u56de\u6570\u636e\u7684\u65f6\u5019\uff0c\u5c31\u8981\u628a\u8fd9\u4e2a\u6570\u636e\u662f\u5df2\u7ecf\u8131\u654f\u540e\u7684\uff0c\u5e38\u89c1\u7684\u8fd9\u79cd\u8131\u654f\u7684\u8fd9\u79cd\u4fe1\u606f\u7c7b\u522b\u7684\u8bdd\uff0c\u624b\u673a\u53f7\u8eab\u4efd\u8bc1\u5bb6\u5ead\u4f4f\u5740\uff1bUserController\u6539\u6210\u4e0b\u9762\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@GetMapping(\"\/api\/shortlink\/v1\/user\/{username}\")\npublic Result&lt;UserRespDTO&gt; getUserByUsername(@PathVariable(\"username\")String username) {\n    return Results.success(userService.getUserByUsername(username));\n}<\/pre>\n\n\n\n<p>\u5f53\u6211\u4eecapifox\u53bbget\u4e00\u4e0b\u65f6\uff0c\u8fd4\u56de\u7684json\u91cc\u9762phone\u4e2a\u624b\u673a\u53f7\u7b97\u662f\u4e00\u4e2a\u654f\u611f\u4fe1\u606f\uff0c\u4e00\u822c\u7f51\u4e0a\u6709\u4e24\u4e09\u79cd\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u5728Controller\u52a0\u4e00\u4e2a@XXX\u7684\u81ea\u5b9a\u4e49\u6ce8\u89e3\uff0c\u76f8\u5f53\u4e8e\u7528AOP\u7684\u5f0f\u626b\u63cf\u8fd9\u4e2a\u6ce8\u89e3\uff0c\u4e0a\u9762\u5e26\u7740\u8fd9\u4e2a\u6ce8\u89e3\u7684\u8bdd\uff0c\u5c31\u4ece\u4f60\u7684\u8fd4\u56de\u53bb\u7ed9\u4f60\u4e00\u5c42\u5c42\u7684\u53bb\u53cd\u5c04\u9012\u5f52\u76f4\u5230\u62ff\u5230\u4f60\u7684\u8fd9\u4e2a\u4e0a\u9762DTO\uff0c\u6211\u4eec\u5728UserRespDTO\u91cc\u9762\u6bd4\u5982\u7ed9phone\u53bb@XXX\uff08xxx=\u624b\u673a\u53f7\u7c7b\u578b\uff09\uff0c\u4ed6\u5c31\u4f1a\u53bb\u6807\u8bb0\u8bf4\u4f60\u8fd9\u4e2a\u662f\u4ec0\u4e48\u7c7b\u578b\uff0c\u6bd4\u5982\u4ed6\u62ff\u5230\u8fd9\u4e2a\u624b\u673a\u53f7\u7c7b\u578b\u505a\u900f\u660e\u5c55\u793a\uff0c\u4f46\u662f\u8fd9\u79cd\u592a\u590d\u6742\uff1b&nbsp;<\/p>\n\n\n\n<p>\u8fd8\u53ef\u4ee5JSON\u9ed8\u8ba4\u5e8f\u5217\u5316\u7684\u65b9\u5f0f\uff0c\u7ed9\u4ed6\u8fdb\u884c\u4e00\u4e2a\u989d\u5916\u7684\u5904\u7406\uff0c\u7136\u540e\u8fd4\u56de\u7684\u8bdd\u5c31\u662f\u6b63\u5e38\u8131\u654f\u540e\u7684\u3002\u5c31\u662f\u6211\u4eecUserController&nbsp; \u8fd9\u91cc\u660e\u660e\u8fd4\u56de\u7684\u662f\u5bf9\u8c61\uff0c\u600e\u4e48\u5230\u4e86\u524d\u7aef\u8fd9\u91cc\u8fd4\u56de\u7684\u8bf7\u6c42\u8fd9\u91cc\u4e3a\u4ec0\u4e48\u662fjson\uff1f\u56e0\u4e3aspringboot\u5728web\u8bf7\u6c42\u91cc\u9762\uff0c\u9ed8\u8ba4\u901a\u8fc7jackson\u6846\u67b6\u5e8f\u5217\u5316\u7684\u65b9\u5f0f\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u5229\u7528jackson\u6846\u67b6\u4e86<\/p>\n\n\n\n<p>\u5728common\u4e0b\u521b\u5efaserialize\u5305\uff0c\u65b0\u5efaPhoneDesensitizationSerializer.java\uff0c\u7b2c\u4e00\u4e2a\u503c\u662f\u624b\u673a\u53f7\u672c\u8eab\u7684\u4e00\u4e2a\u503c\uff0c\u7b2c\u4e8c\u4e2a\u5b83\u662f\u5bf9\u8c61\u672c\u8eab\u7684\u4e00\u4e2a\u901a\u7528\u7684\u865a\u62df\u5316\u5668\uff0c\u7b2c\u4e09\u4e2a\u5c31\u662fSerializerProvider\uff08\u5e8f\u5217\u5316\u751f\u4ea7\u503c\uff0c\u6ca1\u6709\u7528\u5230\uff09\u7528\u5e8f\u5217\u5316\u7684\u5199\u5165\u5668\u5199\u5230\u6211\u4eec\u7684\u4e00\u4e2a\u76ee\u6807\u7684\u4e00\u4e2a\u5bf9\u8c61\u91cc\u9762\u53bb<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.nageoffer.shortlink.admin.common.serialize;\nimport cn.hutool.core.util.DesensitizedUtil;\nimport com.fasterxml.jackson.core.JsonGenerator;\nimport com.fasterxml.jackson.databind.JsonSerializer;\nimport com.fasterxml.jackson.databind.SerializerProvider;\n\nimport java.io.IOException;\n\n\/**\n * \u624b\u673a\u53f7\u8131\u654f\u53cd\u5e8f\u5217\u5316\n *\/\npublic class PhoneDesensitizationSerializer extends JsonSerializer&lt;String&gt; {\n\n    @Override\n    public void serialize(String phone, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {\n        String phoneDesensitization = DesensitizedUtil.mobilePhone(phone);\n        jsonGenerator.writeString(phoneDesensitization);\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u53ea\u9700\u8981\u5728\u5bf9\u5e94\u7684\u5305UserRespDTO \uff0cphone\u7684\u90e8\u5206\u4e0a\u9762\u52a0\u5bf9\u5e94\u7684\u76d1\u542c\u7684\u5e8f\u5217\u5316\u5668\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/**\n * \u624b\u673a\u53f7\n *\/\n@JsonSerialize(using  = PhoneDesensitizationSerializer.class)\nprivate String phone;<\/pre>\n\n\n\n<p>\u8fd9\u6837\u53ef\u4ee5\u901a\u8fc7Jackson\u53bb\u8bfb\u53d6\u51fa\u6765\u4f60\u8fd9\u4e2a\u5b57\u6bb5\u7ed9\u5b83\u8fdb\u884c\u4e00\u4e9b\u6cdb\u89e3\u6790\uff0c<img loading=\"lazy\" decoding=\"async\" height=\"335\" width=\"412\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/682986c269f14d96a9eb66c9781d349f.png\" alt=\"\">\uff0c\u5982\u679c\u662f\u4e00\u5b9a\u9700\u8981\u624b\u673a\u53f7\u5b57\u6bb5\u5462\uff1f\u53ef\u4ee5\u7ed9\u4ed6\u518d\u51fa\u4e00\u4e2a\u65b0\u7684\u63a5\u53e3\uff0ccontroller\u91cc\u9762\u5199\u5982\u4e0b\uff1a\uff08BeanUtil.toBean \u65b9\u6cd5\u53ea\u662f\u590d\u5236\u5c5e\u6027\u503c\uff0c\u5e76\u4e0d\u4f1a\u89e6\u53d1 @JsonSerialize \u6ce8\u89e3\u6307\u5b9a\u7684\u5e8f\u5217\u5316\u5668\uff0c\u6240\u4ee5 phone \u5c5e\u6027\u7684\u503c\u4e0d\u4f1a\u88ab\u8131\u654f\u5904\u7406\u3002\uff09<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@GetMapping(\"\/api\/shortlink\/v1\/actual\/user\/{username}\")\npublic Result&lt;UserActualRespDTO&gt; getActualUserByUsername(@PathVariable(\"username\")String username) {\n    return Results.success(BeanUtil.toBean(userService.getUserByUsername(username), UserActualRespDTO.class));\n}<\/pre>\n\n\n\n<p>Resp\u91cc\u9762\u65b0\u5efa\u7c7b&nbsp;UserActualRespDTO.java<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.nageoffer.shortlink.admin.dto.resq;\n\nimport com.baomidou.mybatisplus.annotation.TableName;\nimport lombok.Data;\n@Data\n@TableName\npublic class UserActualRespDTO {\n    \/**\n     * id\n     *\/\n    private Long id;\n    \/**\n     * \u7528\u6237\u540d\n     *\/\n    private String username;\n    \/**\n     \u771f\u5b9e\u59d3\u540d\n     *\/\n    private String realName;\n    \/**\n     * \u624b\u673a\u53f7\n     *\/\n\n    private String phone;\n    \/**\n     * \u90ae\u7bb1\n     *\/\n    private String mail;\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u68c0\u67e5\u7528\u6237\u540d\u662f\u5426\u5b58\u5728\u529f\u80fd<\/h3>\n\n\n\n<p>\u7528\u6237\u540d\u5168\u5c40\u4e3a\u552f\u4e00\u7684\u529f\u80fd\uff0c\u4e8b\u5b9e\u4e0a\uff0c\u8fd9\u4e2a\u662f\u7ed9\u7528\u6237\u81ea\u5df1\u53d6\u4e86\u540d\u5b57\uff0c\u771f\u6b63\u7684\u7528\u6237\u540d\u5e94\u8be5\u540e\u53f0\u9ed8\u8ba4\u4f9d\u6b21\u53d6\u4e00\u4e0bid\uff0c\u7c7b\u4f3c\u4e8e\u6e38\u620fuid\uff0c\u6296\u97f3\u53f7\u7b49\uff1b\u8fd8\u6709\u4e00\u79cd\u662f\u4ec0\u4e48\u82f1\u6587+\u6570\u5b57+\u7b26\u53f7\uff08\u4e0b\u5212\u7ebf\uff09\u7b49\u8fd9\u4e2a\u4f1a\u5f53\u4f5c\u4f60\u7528\u6237\u7684\u4e00\u4e2a\u552f\u4e00\u6807\u8bc6\uff0c\u6700\u597d\u662f\u586b\u5199\u7684\u65f6\u5019\u5c31\u5c0fdiv\u544a\u8bc9\u4f60\u5df2\u7ecf\u6ce8\u518c<\/p>\n\n\n\n<p>\u4e3a\u4e86\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd\uff0c\u9700\u8981\u5b9e\u73b0\u63a5\u53e3hasUsername\uff0cimpl\u5982\u4e0b\uff0ccontroller\uff0cservice\u90e8\u5206\u7701\u7565<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    @Override\n    public Boolean hasUsername(String username) {\n        LambdaQueryWrapper&lt;UserDO&gt; queryWrapper = Wrappers.lambdaQuery(UserDO.class)\n                .eq(UserDO::getUsername, username);\n        UserDO userDO = baseMapper.selectOne(queryWrapper);\n        return userDO == null;\n    }<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>    \/**\n     * \u67e5\u8be2\u7528\u6237\u540d\u662f\u5426\u5b58\u5728\n     *\/\n    @GetMapping(\"\/api\/shortlink\/v1\/user\/has-user-name\")\n    public Result&lt;Boolean&gt; hasUserName(@RequestParam(\"username\")String username) {\n        return Results.success(userService.hasUsername(username));\n    }<\/code><\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"90\" width=\"357\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/3a530647190f441c99a4246857b1096d.png\" alt=\"\">\u8fd9\u6837\u5c31\u662f\u7528\u6237\u7ba1\u7406\u7684\u76f4\u63a5\u6a21\u578b<\/p>\n\n\n\n<p id=\"ud4f66c10\">\u5b58\u5728\u4ec0\u4e48\u95ee\u9898\uff1f<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6d77\u91cf\u7528\u6237\u5982\u679c\u8bf4\u67e5\u8be2\u7684\u7528\u6237\u540d\u5b58\u5728\u6216\u4e0d\u5b58\u5728\uff0c\u5168\u90e8\u8bf7\u6c42\u6570\u636e\u5e93\uff0c\u4f1a\u5c06\u6570\u636e\u5e93\u76f4\u63a5\u6253\u6ee1\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">&nbsp;\u5982\u4f55\u9632\u6b62\u68c0\u67e5\u7528\u6237\u540d\u7f13\u5b58\u7a7f\u900f\uff08\u7406\u8bba\u7bc7\uff09<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"yooq2\">1. \u7528\u6237\u540d\u52a0\u8f7d\u7f13\u5b58<\/h4>\n\n\n\n<p id=\"u7c83d320\">\u7b2c\u4e00\u7248\u89e3\u51b3\u65b9\u6848\uff0c\u5c06\u6570\u636e\u5e93\u5df2\u6709\u7684\u7528\u6237\u540d\u5168\u90e8\u653e\u5230\u7f13\u5b58\u91cc\u3002<\/p>\n\n\n\n<p id=\"u5009cbcf\">\u6d41\u7a0b\u56fe\uff1a<img loading=\"lazy\" decoding=\"async\" height=\"762\" width=\"742\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/f5e41417ddf94ee7850e93c65967cfe0.png\" alt=\"\"><\/p>\n\n\n\n<p id=\"u26874bae\">\u8be5\u65b9\u6848\u95ee\u9898\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u662f\u5426\u8981\u8bbe\u7f6e\u6570\u636e\u7684\u6709\u6548\u671f\uff1f\u53ea\u80fd\u8bbe\u7f6e\u4e3a\u65e0\u65e0\u6709\u6548\u671f\uff0c\u4e5f\u5c31\u662f\u6c38\u4e45\u6570\u636e\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u662f\u6c38\u4e45\u4e0d\u8fc7\u671f\u6570\u636e\uff0c\u5360\u7528 Redis \u5185\u5b58\u592a\u9ad8\uff0c\u8bbe\u4e86\u4e5f\u6ca1\u7528\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"cCL9z\">2. \u5e03\u9686\u8fc7\u6ee4\u5668<\/h4>\n\n\n\n<p id=\"u54837c76\">\u7b2c\u4e8c\u7248\u89e3\u51b3\u65b9\u6848\uff0c\u4f7f\u7528\u5e03\u9686\u8fc7\u6ee4\u5668\u3002<\/p>\n\n\n\n<p id=\"u226a5643\">\u6d41\u7a0b\u56fe\uff1a<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"738\" width=\"754\" src=\"https:\/\/i-blog.csdnimg.cn\/img_convert\/06a10b3da402a0c7877ecbe31cdb0ab7.png\" alt=\"\"><\/p>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"e4wAt\">2.1. \u4ec0\u4e48\u662f\u5e03\u9686\u8fc7\u6ee4\u5668<\/h5>\n\n\n\n<p id=\"u227c413b\">\u5e03\u9686\u8fc7\u6ee4\u5668\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u5feb\u901f\u5224\u65ad\u4e00\u4e2a\u5143\u7d20\u662f\u5426\u5b58\u5728\u4e8e\u4e00\u4e2a\u96c6\u5408\u4e2d\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u5e03\u9686\u8fc7\u6ee4\u5668\u5305\u542b\u4e00\u4e2a\u4f4d\u6570\u7ec4\u548c\u4e00\u7ec4\u54c8\u5e0c\u51fd\u6570\u3002\u4f4d\u6570\u7ec4\u7684\u521d\u59cb\u503c\u5168\u90e8\u7f6e\u4e3a 0\u3002\u5728\u63d2\u5165\u4e00\u4e2a\u5143\u7d20\u65f6\uff0c\u5c06\u8be5\u5143\u7d20\u7ecf\u8fc7\u591a\u4e2a\u54c8\u5e0c\u51fd\u6570\u6620\u5c04\u5230\u4f4d\u6570\u7ec4\u4e0a\u7684\u591a\u4e2a\u4f4d\u7f6e\uff0c\u5e76\u5c06\u8fd9\u4e9b\u4f4d\u7f6e\u7684\u503c\u7f6e\u4e3a 1\u3002<\/p>\n\n\n\n<p id=\"uab29f826\">1\u5b57\u8282\uff08Byte\uff09=8\u4f4d\uff08Bit\uff09<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"547\" width=\"569\" src=\"https:\/\/i-blog.csdnimg.cn\/img_convert\/f84b627b10e80f88bc8562a346254f33.png\" alt=\"\"><\/p>\n\n\n\n<p id=\"uee1aef06\">\u5728\u67e5\u8be2\u4e00\u4e2a\u5143\u7d20\u662f\u5426\u5b58\u5728\u65f6\uff0c\u4f1a\u5c06\u8be5\u5143\u7d20\u7ecf\u8fc7\u591a\u4e2a\u54c8\u5e0c\u51fd\u6570\u6620\u5c04\u5230\u4f4d\u6570\u7ec4\u4e0a\u7684\u591a\u4e2a\u4f4d\u7f6e\uff0c\u5982\u679c\u6240\u6709\u4f4d\u7f6e\u7684\u503c\u90fd\u4e3a 1\uff0c\u5219\u8ba4\u4e3a\u5143\u7d20\u5b58\u5728\uff1b\u5982\u679c\u5b58\u5728\u4efb\u4e00\u4f4d\u7f6e\u7684\u503c\u4e3a 0\uff0c\u5219\u8ba4\u4e3a\u5143\u7d20\u4e0d\u5b58\u5728\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"OrYPw\">2.2. \u4f18\u7f3a\u70b9<\/h5>\n\n\n\n<p id=\"u455e5729\">\u4f18\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9ad8\u6548\u5730\u5224\u65ad\u4e00\u4e2a\u5143\u7d20\u662f\u5426\u5c5e\u4e8e\u4e00\u4e2a\u5927\u89c4\u6a21\u96c6\u5408\u3002<\/li>\n\n\n\n<li>\u8282\u7701\u5185\u5b58\u3002<\/li>\n<\/ul>\n\n\n\n<p id=\"ua1f5417f\">\u7f3a\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u53ef\u80fd\u5b58\u5728\u4e00\u5b9a\u7684\u8bef\u5224\u3002<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"mACga\">2.3. \u5e03\u9686\u8fc7\u6ee4\u5668\u8bef\u5224\u7406\u89e3<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5e03\u9686\u8fc7\u6ee4\u5668\u8981\u8bbe\u7f6e\u521d\u59cb\u5bb9\u91cf\u3002\u5bb9\u91cf\u8bbe\u7f6e\u8d8a\u5927\uff0c\u51b2\u7a81\u51e0\u7387\u8d8a\u4f4e\u3002<\/li>\n\n\n\n<li>\u5e03\u9686\u8fc7\u6ee4\u5668\u4f1a\u8bbe\u7f6e\u9884\u671f\u7684\u8bef\u5224\u503c\u3002<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"LBsQt\">2.4. \u8bef\u5224\u80fd\u5426\u63a5\u53d7<\/h5>\n\n\n\n<p id=\"uc92e4cf5\">\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u8bef\u5224\u662f\u5426\u80fd\u591f\u63a5\u53d7\uff1f<\/p>\n\n\n\n<p id=\"u02297dca\">\u7b54\uff1a\u53ef\u4ee5\u5bb9\u5fcd\u3002\u4e3a\u4ec0\u4e48\uff1f\u56e0\u4e3a\u7528\u6237\u540d\u4e0d\u662f\u7279\u522b\u91cd\u8981\u7684\u6570\u636e\uff0c\u5982\u679c\u8bf4\u6211\u8bbe\u7f6e\u7528\u6237\u540d\u4e3a aaa\uff0c\u7cfb\u7edf\u8fd4\u56de\u6211\u4e0d\u53ef\u7528\uff0c\u90a3\u6211\u5927\u53ef\u4ee5\u5728 aaa \u7684\u57fa\u7840\u4e0a\u518d\u52a0\u4e00\u4e2aa\uff0c\u4e5f\u5c31\u662f aaaa\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"Uej9T\">2.5. \u5e03\u9686\u8fc7\u6ee4\u5668\u6d41\u7a0b\u56fe<\/h5>\n\n\n\n<p id=\"u26346f1d\">\u521d\u59cb\u5316\u6d41\u7a0b\u56fe\uff1a<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"639\" width=\"667\" src=\"https:\/\/i-blog.csdnimg.cn\/img_convert\/4789a447cf3325e6395e4ddf4b41b8ff.png\" alt=\"\"><\/p>\n\n\n\n<p id=\"uaa683291\">\u6267\u884c\u6d41\u7a0b\u56fe\uff1a<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"170\" width=\"659\" src=\"https:\/\/i-blog.csdnimg.cn\/img_convert\/0e6fa672420a43b00e53dc5c391abc88.png\" alt=\"\"><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u6838\u5fc3\u7279\u6027\u51b3\u5b9a\u4e86\u5176\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u4f7f\u7528\u65b9\u5f0f\uff0c\u9488\u5bf9\u95ee\u9898\u548c\u56de\u590d\u7684\u5206\u6790\u5982\u4e0b\uff1a<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\u4e00\u3001\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u7279\u6027<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u65e0\u5047\u9634\u6027\uff08False Negative\uff09<\/strong><br>\u82e5\u5e03\u9686\u8fc7\u6ee4\u5668\u8fd4\u56de\u300c\u4e0d\u5b58\u5728\u300d\uff0c\u5219\u6570\u636e\u5fc5\u7136\u4e0d\u5728\u5e95\u5c42\u5b58\u50a8\uff08\u5982\u6570\u636e\u5e93\uff09\u4e2d\u3002<\/li>\n\n\n\n<li><strong>\u5b58\u5728\u5047\u9633\u6027\uff08False Positive\uff09<\/strong><br>\u82e5\u8fd4\u56de\u300c\u5b58\u5728\u300d\uff0c\u5b9e\u9645\u53ef\u80fd\u4e0d\u5b58\u5728\uff08\u54c8\u5e0c\u78b0\u649e\u5bfc\u81f4\uff09\uff0c\u9700\u4e8c\u6b21\u9a8c\u8bc1\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\u4e8c\u3001\u539f\u95ee\u9898\u4e0e\u56de\u590d\u7684\u6b63\u786e\u6027\u5206\u6790<\/strong><\/p>\n\n\n\n<p><strong>1. \u7528\u6237\u7684\u6838\u5fc3\u7591\u95ee<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5f53\u5e03\u9686\u8fc7\u6ee4\u5668\u8fd4\u56de\u300c\u5b58\u5728\u300d\u65f6\uff0c\u80fd\u5426\u901a\u8fc7\u4e8c\u6b21\u9a8c\u8bc1\uff08\u5982\u67e5\u8be2\u7f13\u5b58\uff09\u51cf\u5c11\u8bef\u5224\u5f71\u54cd\uff1f<\/p>\n<\/blockquote>\n\n\n\n<p><strong>\u7b54\u6848\uff1a\u53ef\u884c\u4f46\u9700\u6743\u8861<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u903b\u8f91\u6709\u6548\u6027 <\/strong>\uff1a<br>\u5e03\u9686\u8fc7\u6ee4\u5668\u4ec5\u4fdd\u8bc1\u300c\u4e0d\u5b58\u5728\u300d\u7684\u51c6\u786e\u6027\uff0c\u4f46\u5bf9\u300c\u5b58\u5728\u300d\u7684\u5224\u65ad\u9700\u7ed3\u5408\u5176\u4ed6\u673a\u5236\u9a8c\u8bc1\u3002\u7528\u6237\u63d0\u51fa\u7684\u300c\u5e03\u9686\u8fc7\u6ee4\u5668\u2192\u7f13\u5b58\u2192\u6570\u636e\u5e93\u300d\u94fe\u5f0f\u67e5\u8be2\uff0c\u672c\u8d28\u662f\u7528\u7f13\u5b58\u4f5c\u4e3a\u4e8c\u6b21\u9a8c\u8bc1\u5c42\uff0c\u53ef\u964d\u4f4e\u8bef\u5224\u5bfc\u81f4\u7684\u6570\u636e\u5e93\u538b\u529b\u3002<\/li>\n\n\n\n<li><strong>\u6027\u80fd\u6743\u8861 <\/strong>\uff1a<br>\u6bcf\u6b21\u8bf7\u6c42\u589e\u52a0\u4e00\u6b21\u7f13\u5b58\u67e5\u8be2\uff08\u5982Redis\uff09\uff0c\u4f1a\u7565\u5fae\u589e\u52a0\u5ef6\u8fdf\uff0c\u4f46\u76f8\u6bd4\u6570\u636e\u5e93\u67e5\u8be2\u4ecd\u9ad8\u6548\u3002\u82e5\u8bef\u5224\u7387\u8f83\u4f4e\uff0c\u989d\u5916\u7684\u7f13\u5b58\u67e5\u8be2\u6210\u672c\u53ef\u63a5\u53d7\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>2. \u56de\u590d\u89c2\u70b9\u8fa8\u6790<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4e4c\u62c9\u5440\u54c8\u6c0f\uff082024-06-16\uff09<\/strong><br>\u2714\ufe0f \u6b63\u786e\u3002\u5e03\u9686\u8fc7\u6ee4\u5668\u8bbe\u8ba1\u521d\u8877\u662f\u5feb\u901f\u6392\u9664\u4e0d\u5b58\u5728\u7684\u8bf7\u6c42\uff0c\u5b58\u5728\u65f6\u9700\u5176\u4ed6\u9a8c\u8bc1\u3002<\/li>\n\n\n\n<li><strong>\u4e4c\u62c9\u5440\u54c8\u6c0f\uff082024-06-21\uff09<\/strong><br>\u274c \u90e8\u5206\u9519\u8bef\u3002\u8bef\u5224\u5728\u6280\u672f\u4e0a\u4e0d\u53ef\u6d88\u9664\uff0c\u4f46\u67d0\u4e9b\u573a\u666f\uff08\u5982\u5bb9\u5fcd\u5c11\u91cf\u8bef\u5224\uff09\u53ef\u80fd\u63a5\u53d7\u3002\u82e5\u4e1a\u52a1\u8981\u6c42\u4e25\u683c\u4e00\u81f4\u6027\uff08\u5982\u652f\u4ed8\u7cfb\u7edf\uff09\uff0c\u8bef\u5224\u4e0d\u53ef\u63a5\u53d7\u3002<\/li>\n\n\n\n<li><strong>Venom\uff082024-10-09\uff09<\/strong><br>\u2714\ufe0f \u90e8\u5206\u6b63\u786e\u3002\u54c8\u5e0c\u78b0\u649e\u662f\u8bef\u5224\u6839\u6e90\uff0c\u4f46\u7528\u6237\u65b9\u6848\u901a\u8fc7\u7f13\u5b58\u9a8c\u8bc1\u53ef\u7f13\u89e3\u8bef\u5224\u5f71\u54cd\uff0c\u903b\u8f91\u5408\u7406\u3002<\/li>\n\n\n\n<li><strong>\u76ae\u86cb\u7626\u8089\u7ca5\uff082024-10-27\uff09<\/strong><br>\u2714\ufe0f \u6b63\u786e\u3002\u8bef\u5224\u7387\u4e0e\u54c8\u5e0c\u51fd\u6570\u6570\u91cf\u3001\u4f4d\u6570\u7ec4\u5927\u5c0f\u76f8\u5173\u3002\u964d\u4f4e\u8bef\u5224\u7387\u9700\u589e\u52a0\u54c8\u5e0c\u51fd\u6570\u6216\u4f4d\u6570\u7ec4\u7a7a\u95f4\uff0c\u53ef\u80fd\u727a\u7272\u6027\u80fd\u3002<\/li>\n\n\n\n<li><strong>\u8001\u6c49\u5821\uff082024-12-10\uff09<\/strong><br>\u274c \u9519\u8bef\u3002\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u300c\u5b58\u5728\u300d\u5224\u65ad\u672c\u5c31\u9700\u8981\u4e8c\u6b21\u9a8c\u8bc1\uff0c\u8fd9\u662f\u5176\u8bbe\u8ba1\u7279\u6027\uff0c\u800c\u975e\u7f3a\u9677\u3002\u4e25\u683c\u573a\u666f\u4e0b\uff08\u5982\u91d1\u878d\uff09\uff0c\u9700\u7ed3\u5408\u6301\u4e45\u5316\u5b58\u50a8\u9a8c\u8bc1\uff0c\u4f46\u975e\u6240\u6709\u573a\u666f\u90fd\u9700\u5982\u6b64\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\u4e09\u3001\u4f18\u5316\u65b9\u6848\u7684\u53ef\u884c\u6027<\/strong><\/p>\n\n\n\n<p>\u7528\u6237\u63d0\u51fa\u7684\u300c\u5e03\u9686\u8fc7\u6ee4\u5668 + \u7f13\u5b58\u9a8c\u8bc1\u300d\u65b9\u6848\u662f\u5426\u5408\u7406\uff1f<\/p>\n\n\n\n<p><strong>1. \u4f18\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u964d\u4f4e\u6570\u636e\u5e93\u538b\u529b <\/strong>\uff1a\u5e03\u9686\u8fc7\u6ee4\u5668\u62e6\u622a\u65e0\u6548\u8bf7\u6c42\uff0c\u8bef\u5224\u65f6\u7f13\u5b58\u9a8c\u8bc1\u907f\u514d\u76f4\u63a5\u67e5\u5e93\u3002<\/li>\n\n\n\n<li><strong>\u51cf\u5c11\u8bef\u5224\u5f71\u54cd <\/strong>\uff1a\u7f13\u5b58\u672a\u547d\u4e2d\u65f6\u624d\u89e6\u53d1\u6570\u636e\u5e93\u67e5\u8be2\uff0c\u8bef\u5224\u4e0d\u4f1a\u76f4\u63a5\u5bfc\u81f4\u6570\u636e\u5e93\u8d1f\u8f7d\u5347\u9ad8\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>2. \u6f5c\u5728\u95ee\u9898<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7f13\u5b58\u7a7f\u900f\u98ce\u9669 <\/strong>\uff1a\u82e5\u5e03\u9686\u8fc7\u6ee4\u5668\u8bef\u5224\u7387\u9ad8\uff0c\u53ef\u80fd\u5bfc\u81f4\u5927\u91cf\u65e0\u6548\u7f13\u5b58\u672a\u547d\u4e2d\uff0c\u589e\u52a0\u6570\u636e\u5e93\u67e5\u8be2\u3002<\/li>\n\n\n\n<li><strong>\u7f13\u5b58\u96ea\u5d29\u98ce\u9669 <\/strong>\uff1a\u82e5\u7f13\u5b58\u8fc7\u671f\u65f6\u95f4\u76f8\u540c\uff0c\u53ef\u80fd\u5f15\u53d1\u6570\u636e\u5e93\u77ac\u65f6\u538b\u529b\u6fc0\u589e\u3002<\/li>\n\n\n\n<li><strong>\u7a7a\u95f4\u4e0e\u590d\u6742\u5ea6 <\/strong>\uff1a\u9700\u7ef4\u62a4\u7f13\u5b58\u4e0e\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u4e00\u81f4\u6027\uff0c\u589e\u52a0\u7cfb\u7edf\u590d\u6742\u5ea6\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>3. \u6539\u8fdb\u5efa\u8bae<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8bbe\u7f6e\u4f4e\u8bef\u5224\u7387\u7684\u5e03\u9686\u8fc7\u6ee4\u5668 <\/strong>\uff1a\u901a\u8fc7\u8c03\u6574\u54c8\u5e0c\u51fd\u6570\u6570\u91cf\u548c\u4f4d\u6570\u7ec4\u5927\u5c0f\uff0c\u5c06\u8bef\u5224\u7387\u63a7\u5236\u5728\u6781\u4f4e\u6c34\u5e73\uff08\u59820.1%\uff09\uff0c\u51cf\u5c11\u4e8c\u6b21\u9a8c\u8bc1\u7684\u9891\u7387\u3002<\/li>\n\n\n\n<li><strong>\u7f13\u5b58\u7a7a\u503c\uff08Negative Caching\uff09 <\/strong>\uff1a\u5bf9\u6570\u636e\u5e93\u67e5\u8be2\u7ed3\u679c\u4e3a\u7a7a\u7684\u8bf7\u6c42\uff0c\u7f13\u5b58\u77ed\u65f6\u95f4\u7684\u7a7a\u503c\uff0c\u9632\u6b62\u91cd\u590d\u7a7f\u900f\u3002<\/li>\n\n\n\n<li><strong>\u5f02\u6b65\u66f4\u65b0\u5e03\u9686\u8fc7\u6ee4\u5668 <\/strong>\uff1a\u5f53\u6570\u636e\u5e93\u65b0\u589e\u6570\u636e\u65f6\uff0c\u4e3b\u52a8\u66f4\u65b0\u5e03\u9686\u8fc7\u6ee4\u5668\uff0c\u907f\u514d\u56e0\u5f02\u6b65\u5ef6\u8fdf\u5bfc\u81f4\u7684\u8bef\u5224\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\u56db\u3001\u7ed3\u8bba<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u5b9a\u4f4d <\/strong>\uff1a\u4ec5\u7528\u4e8e\u5feb\u901f\u6392\u9664\u300c\u4e0d\u5b58\u5728\u300d\u7684\u8bf7\u6c42\uff0c\u5b58\u5728\u65f6\u9700\u4f9d\u8d56\u5176\u4ed6\u5b58\u50a8\uff08\u7f13\u5b58\/\u6570\u636e\u5e93\uff09\u9a8c\u8bc1\u3002<\/li>\n\n\n\n<li><strong>\u7528\u6237\u65b9\u6848\u7684\u5408\u7406\u6027 <\/strong>\uff1a\u5728\u6027\u80fd\u53ef\u63a5\u53d7\u7684\u524d\u63d0\u4e0b\uff0c\u901a\u8fc7\u7f13\u5b58\u9a8c\u8bc1\u51cf\u5c11\u8bef\u5224\u5f71\u54cd\u662f\u5408\u7406\u7684\u4f18\u5316\uff0c\u4f46\u9700\u7ed3\u5408\u7f13\u5b58\u8fc7\u671f\u7b56\u7565\u548c\u4f4e\u8bef\u5224\u7387\u53c2\u6570\u8bbe\u7f6e\u3002<\/li>\n\n\n\n<li><strong>\u56de\u590d\u7684\u6b63\u786e\u6027 <\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u4e4c\u62c9\u5440\u54c8\u6c0f\u548c\u76ae\u86cb\u7626\u8089\u7ca5\u7684\u89c2\u70b9\u6b63\u786e\uff0c\u6307\u51fa\u4e86\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u6838\u5fc3\u7279\u6027\u3002<\/li>\n\n\n\n<li>Venom\u548c\u8001\u6c49\u5821\u7684\u8868\u8ff0\u6709\u504f\u5dee\uff0c\u672a\u51c6\u786e\u7406\u89e3\u7528\u6237\u65b9\u6848\u7684\u76ee\u6807\u548c\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u9002\u7528\u8303\u56f4\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>\u6700\u7ec8\u7ed3\u8bba <\/strong>\uff1a\u7528\u6237\u7684\u601d\u8def\u6b63\u786e\uff0c\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u300c\u5b58\u5728\u300d\u5224\u65ad\u9700\u4e8c\u6b21\u9a8c\u8bc1\uff0c\u4f46\u9700\u6839\u636e\u4e1a\u52a1\u573a\u666f\u6743\u8861\u5b9e\u73b0\u590d\u6742\u5ea6\u548c\u6027\u80fd\u3002<\/p>\n<\/blockquote>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"XxrSJ\">3. \u4ee3\u7801\u4e2d\u4f7f\u7528\u5e03\u9686\u8fc7\u6ee4\u5668<\/h4>\n\n\n\n<p>&nbsp;\u5bfc\u5165redis\u914d\u7f6eyaml\u548cpom\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&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;\/dependency&gt;<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>server:\n  port: 8002\n\nspring:\n  datasource:\n    username: root\n    password: root\n    url: jdbc:mysql:\/\/127.0.0.1:3306\/link?characterEncoding=utf-8&amp;zeroDateTimeBehavior=convertToNull&amp;transformedBitIsBoolean=true&amp;serverTimezone=GMT%2B8\n    driver-class-name: com.mysql.cj.jdbc.Driver\n    hikari:\n      connection-test-query: select 1\n      connection-timeout: 20000\n      idle-timeout: 300000\n      maximum-pool-size: 5\n      minimum-idle: 5\n  data:\n    redis:\n      host: 192.168.111.130\n      password: 123321\n      port: 6379<\/code><\/pre>\n\n\n\n<p>&nbsp;\u5728admin\u65b0\u5efa\u8f6f\u4ef6\u5305config\uff0c\u91cc\u9762\u65b0\u5efajava\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">package com.nageoffer.shortlink.admin.config;\n\nimport org.redisson.api.RBloomFilter;\nimport org.redisson.api.RedissonClient;\nimport org.springframework.boot.context.properties.EnableConfigurationProperties;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\n\n\/**\n * \u5e03\u9686\u8fc7\u6ee4\u5668\u914d\u7f6e\n *\/\n@Configuration\npublic class RBloomFilterConfiguration {\n\n    \/**\n     * \u9632\u6b62\u7528\u6237\u6ce8\u518c\u67e5\u8be2\u6570\u636e\u5e93\u7684\u5e03\u9686\u8fc7\u6ee4\u5668\n     *\/\n    @Bean\n    public RBloomFilter&lt;String&gt; userRegisterCachePenetrationBloomFilter(RedissonClient redissonClient) {\n        RBloomFilter&lt;String&gt; cachePenetrationBloomFilter = redissonClient.getBloomFilter(\"userRegisterCachePenetrationBloomFilter\");\n        cachePenetrationBloomFilter.tryInit(0, 0);\n        return cachePenetrationBloomFilter;\n    }\n}<\/pre>\n\n\n\n<p id=\"ueecd9f00\">tryInit \u6709\u4e24\u4e2a\u6838\u5fc3\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>expectedInsertions\uff1a\u9884\u4f30\u5e03\u9686\u8fc7\u6ee4\u5668\u5b58\u50a8\u7684\u5143\u7d20\u957f\u5ea6\u3002<\/li>\n\n\n\n<li>falseProbability\uff1a\u8fd0\u884c\u7684\u8bef\u5224\u7387\u3002<\/li>\n<\/ul>\n\n\n\n<p id=\"u763274ba\">\u9519\u8bef\u7387\u8d8a\u4f4e\uff0c\u4f4d\u6570\u7ec4\u8d8a\u957f\uff0c\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u5185\u5b58\u5360\u7528\u8d8a\u5927\u3002<\/p>\n\n\n\n<p id=\"u387a89cc\">\u9519\u8bef\u7387\u8d8a\u4f4e\uff0c\u6563\u5217 Hash \u51fd\u6570\u8d8a\u591a\uff0c\u8ba1\u7b97\u8017\u65f6\u8f83\u957f\u3002<\/p>\n\n\n\n<p id=\"u7afb5d1c\">\u4e00\u4e2a\u5e03\u9686\u8fc7\u6ee4\u5668\u5360\u7528\u5927\u5c0f\u7684\u5728\u7ebf\u7f51\u7ad9\uff1a<a href=\"https:\/\/krisives.github.io\/bloom-calculator\/\" target=\"_blank\"  rel=\"nofollow\" >Bloom Filter Calculator<\/a><\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"250\" width=\"678\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/651ecf8f75d7405bb3d8e1154b4cee87.png\" alt=\"\"><\/p>\n\n\n\n<p>\u6563\u5217\u51fd\u6570\u7684function\u7ea6\u7b49\u4e8e10\uff0c \u4f60\u770b\u52301\u4ebf\u6761\u624d\u7ea6\u7b49\u4e8e171.39MB\uff1b\u6211\u4eec\u5c06\u4ee3\u7801\u91ccl\u548cv\u8bbe\u4e3a100000000L, 0.001<\/p>\n\n\n\n<p>&nbsp;impl\u5b9e\u73b0\u5982\u4e0b\uff0c\u7528RequiredArgsConstructor\u5bfc\u5165<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Service\n@RequiredArgsConstructor\npublic class UserServiceImpl extends ServiceImpl&lt;UserMapper, UserDO&gt; implements UserService {\n\n    private final RBloomFilter&lt;String&gt; userRegisterCacheBloomFilter;\n    @Override\n    public UserRespDTO getUserByUsername(String username) {\n        LambdaQueryWrapper&lt;UserDO&gt; queryWrapper = Wrappers.lambdaQuery(UserDO.class)\n                .eq(UserDO::getUsername, username);\n        UserDO userDO = baseMapper.selectOne(queryWrapper);\n        if (userDO == null) {\n            throw new ClientException(UserErrorCodeEnum.USER_NULL);\n        }\n        UserRespDTO result = new UserRespDTO();\n        BeanUtils.copyProperties(userDO,result);\n        \/\/Spring \u7684 BeanUtils.copyProperties(Object source, Object target) \u65b9\u6cd5\u8981\u6c42\u6e90\u5bf9\u8c61\u5728\u524d\uff0c\u76ee\u6807\u5bf9\u8c61\u5728\u540e\n        return result;\n    }\n    @Override\n    public Boolean hasUsername(String username) {\n        return userRegisterCacheBloomFilter.contains(username);\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u56e0\u4e3a\u73b0\u5728\u8fd9\u91cc\u9762\u662f\u6ca1\u6709\u5143\u7d20\u7684\uff0c\u6211\u4eec\u8981\u5728\u6709\u4e86\u6ce8\u518c\u529f\u80fd\u4e4b\u540e\uff0c\u6ce8\u518c\u4ee5\u540e\u5c31\u628a\u7528\u6237\u540d\u7ed9\u653e\u5230\u5e03\u9686\u8fc7\u6ee4\u5668\u91cc\u9762\u53bb<\/p>\n\n\n\n<p id=\"u2409db78\">\u4f7f\u7528\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u4e24\u79cd\u573a\u666f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u521d\u59cb\u4f7f\u7528\uff1a\u6ce8\u518c\u7528\u6237\u65f6\u5c31\u5411\u5bb9\u5668\u4e2d\u65b0\u589e\u6570\u636e\uff0c\u5c31\u4e0d\u9700\u8981\u4efb\u52a1\u5411\u5bb9\u5668\u5b58\u50a8\u6570\u636e\u4e86\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u5f15\u5165\uff1a\u8bfb\u53d6\u6570\u636e\u6e90\u5c06\u76ee\u6807\u6570\u636e\u5237\u5230\u5e03\u9686\u8fc7\u6ee4\u5668\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u95ee\u98981\uff1a\u5728\u4f7f\u7528\u6570\u636e\u5e93\u76f4\u63a5\u67e5\u8be2\u53ef\u4ee5\u67e5\u8be2\u5230\u5df2\u6709\u7684username\uff0c\u4f46\u662f\u4f7f\u7528\u5e03\u9686\u8fc7\u6ee4\u5668\u67e5\u8be2\u5374\u6ca1\u6709\u8fd9\u662f\u4e3a\u4ec0\u4e48\uff1f<\/p>\n\n\n\n<p>\u89e3\u7b54\uff1a\u56e0\u4e3a\u6b64\u65f6\u5e03\u9686\u8fc7\u6ee4\u5668\u91cc\u9762\u662f\u6ca1\u6709\u5143\u7d20\u7684\uff0c\u9700\u8981\u5728\u540e\u9762\u6709\u4e86\u6ce8\u518c\u529f\u80fd\u4e4b\u540e\uff0c\u628a\u7528\u6237\u540d\u653e\u5728\u5e03\u9686\u8fc7\u6ee4\u5668\u624d\u53ef\u4ee5\u67e5\u8be2\u5230\u3002<\/p>\n\n\n\n<p>\u5e03\u9686\u8fc7\u6ee4\u5668\u662f\u4e00\u79cd\u6982\u7387\u6570\u636e\u7ed3\u6784\uff0c\u5176\u672c\u8d28\u662f\u901a\u8fc7\u591a\u4e2a\u54c8\u5e0c\u51fd\u6570\u5c06\u5143\u7d20\u6620\u5c04\u5230\u4f4d\u6570\u7ec4\u4e0a\u3002\u82e5\u5143\u7d20\u672a\u88ab\u663e\u5f0f\u6dfb\u52a0\uff08\u5982\u7528\u6237\u6ce8\u518c\u65f6\u672a\u5c06\u7528\u6237\u540d\u63d2\u5165\u5e03\u9686\u8fc7\u6ee4\u5668\uff09\uff0c\u5373\u4f7f\u6570\u636e\u5e93\u4e2d\u5b58\u5728\u8be5\u7528\u6237\u540d\uff0c\u5e03\u9686\u8fc7\u6ee4\u5668\u4ecd\u4f1a\u8fd4\u56de\u300c\u4e0d\u5b58\u5728\u300d\u3002\u56e0\u6b64\uff0c\u9700\u5728\u7528\u6237\u6ce8\u518c\u65f6\u4e3b\u52a8\u5c06\u7528\u6237\u540d\u63d2\u5165\u5e03\u9686\u8fc7\u6ee4\u5668\uff0c\u5426\u5219\u65e0\u6cd5\u68c0\u6d4b\u5230\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7528\u6237 <code>Alice<\/code> \u6ce8\u518c\u65f6\u672a\u63d2\u5165\u5e03\u9686\u8fc7\u6ee4\u5668 \u2192 \u5e03\u9686\u8fc7\u6ee4\u5668\u5224\u5b9a <code>Alice<\/code> \u4e0d\u5b58\u5728\u3002<\/li>\n\n\n\n<li>\u6570\u636e\u5e93\u4e2d <code>Alice<\/code> \u5b58\u5728 \u2192 \u76f4\u63a5\u67e5\u8be2\u6570\u636e\u5e93\u80fd\u67e5\u5230\u3002<br><strong>\u7ed3\u8bba <\/strong>\uff1a\u5e03\u9686\u8fc7\u6ee4\u5668\u9700\u4e0e\u6ce8\u518c\u903b\u8f91\u7ed1\u5b9a\uff0c\u786e\u4fdd\u6570\u636e\u540c\u6b65\u66f4\u65b0\u3002<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u95ee\u98982\uff1a\u8bf7\u95ee\u8fd9\u4e2a\u5e03\u9686\u8fc7\u6ee4\u5668\u600e\u4e48\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\u5462\uff0c\u4ece\u6570\u636e\u5e93\u4e2d\u5220\u9664\u7528\u6237\uff0c\u4f46\u662fredis\u4e2d\u7684\u8fd8\u5728\uff0c\u5220\u9664\u7684\u7528\u6237\u540d\u4e0d\u80fd\u91cd\u65b0\u6ce8\u518c\u4e86<br>\u56de\u7b54\uff1a<\/p>\n\n\n\n<p>\u5e03\u9686\u8fc7\u6ee4\u5668\u672c\u8eab<strong>\u4e0d\u652f\u6301\u5220\u9664\u64cd\u4f5c <\/strong>\uff08\u666e\u901a\u7248\u672c\uff09\uff08<a href=\"https:\/\/www.cnblogs.com\/Chary\/p\/15682276.html\" target=\"_blank\"  rel=\"nofollow\" >\u589e\u5f3a\u7248\uff0c\u5e03\u8c37\u9e1f\u8fc7\u6ee4\u5668<\/a>\uff09\uff0c\u539f\u56e0\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u54c8\u5e0c\u78b0\u649e\u95ee\u9898 <\/strong>\uff1a\u591a\u4e2a\u5143\u7d20\u53ef\u80fd\u5171\u4eab\u540c\u4e00\u4f4d\uff0c\u5220\u9664\u4e00\u4e2a\u5143\u7d20\u4f1a\u5bfc\u81f4\u5176\u4ed6\u5143\u7d20\u7684\u8bef\u5224\u3002<\/li>\n\n\n\n<li><strong>\u8fc7\u671f\u65f6\u95f4\u9650\u5236 <\/strong>\uff1a\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u4f4d\u6570\u7ec4\u662f\u9759\u6001\u7684\uff0c\u65e0\u6cd5\u76f4\u63a5\u8bbe\u7f6eTTL\u3002<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6b63\u786e\u89e3\u51b3\u65b9\u6848 <\/strong>\uff1a<br><strong>\u8ba1\u6570\u5e03\u9686\u8fc7\u6ee4\u5668\uff08Counting Bloom Filter\uff09 <\/strong>\uff1a\u4f7f\u7528\u8ba1\u6570\u5668\u4ee3\u66ff\u4f4d\u6570\u7ec4\uff0c\u652f\u6301\u5220\u9664\uff08\u9700\u989d\u5916\u7a7a\u95f4\uff09\u3002<\/li>\n\n\n\n<li><strong>\u7f13\u5b58\u7a7a\u503c\uff08Negative Caching\uff09 <\/strong>\uff1a\u5bf9\u5df2\u5220\u9664\u7684\u7528\u6237\u540d\u7f13\u5b58\u77ed\u65f6\u95f4\u7684\u7a7a\u503c\uff0c\u907f\u514d\u7a7f\u900f\u3002<\/li>\n\n\n\n<li><strong>\u5b9a\u65f6\u91cd\u5efa\u5e03\u9686\u8fc7\u6ee4\u5668 <\/strong>\uff1a\u5b9a\u671f\u4ece\u6570\u636e\u5e93\u5168\u91cf\u540c\u6b65\u6570\u636e\u5230\u5e03\u9686\u8fc7\u6ee4\u5668\uff0c\u8986\u76d6\u8fc7\u671f\u6570\u636e\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u540c\u65f6\u77ed\u94fe\u63a5\u6709\u4e2a\u9762\u8bd5\u95ee\u9898\u89e3\u7b54\u6587\u6863\u53ef\u4ee5\u770b\u4e0b\uff0c\u6709\u8bf4\u8fd9\u79cd\u5e26\u5220\u9664\u7684\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&nbsp;\u95ee\u98983\uff1a\u5982\u679c\u5df2\u7ecf\u4f7f\u7528\u4e86\u5e03\u9686\u8fc7\u6ee4\u5668\uff0c\u4f46\u4e00\u5f00\u59cb\u53ea\u8bbe\u7f6e\u4e86\u5e03\u9686\u8fc7\u6ee4\u5668\u5143\u7d20\u957f\u5ea6\u4e3a1\u5343\u4e07\u3002\u9879\u76ee\u8dd1\u4e86\u4e00\u6bb5\u65f6\u95f4\u53d1\u73b0\u7528\u6237\u6ce8\u518c\u6570\u8fdc\u8d85\u4e8e1\u5343\u4e07\uff0c\u8fd9\u65f6\u5019\u5c06\u5143\u7d20\u957f\u5ea6\u8bbe\u7f6e\u62101\u4ebf\uff0c\u90a3\u4e48\u5e03\u9686\u8fc7\u6ee4\u5668\u5df2\u5b58\u5728\u7684\u5386\u53f2\u6570\u636e\u662f\u5426\u9700\u8981\u5220\u6389\uff0c\u7136\u540e\u7528\u4efb\u52a1\u65b9\u5f0f\uff0c\u91cd\u65b0\u5f80\u5e03\u9686\u8fc7\u6ee4\u5668\u91cc\u9762\u8bbe\u7f6e\u503c\uff1f\u8fd8\u662f\u8bf4\u5386\u53f2\u6570\u636e\u4e0d\u4f1a\u88ab\u5f71\u54cd\uff0c\u4f9d\u65e7\u80fd\u88ab\u67e5\u8be2\u5f97\u5230\uff1f<\/p>\n\n\n\n<p>\u56de\u7b54\uff1a\u4f4d\u6570\u7ec4\u957f\u5ea6\u53d8\u7684\u8bdd\uff0c\u54c8\u5e0c\u51fd\u6570\u5c31\u8981\u91cd\u65b0\u9009\u62e9\u4e86\uff0c\u8981\u5c06\u5386\u53f2\u6570\u636e\u901a\u8fc7\u65b0\u7684\u54c8\u5e0c\u51fd\u6570\u91cd\u65b0\u6620\u5c04\u5230\u65b0\u7684\u4f4d\u6570\u7ec4\u4e0a<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&nbsp;\u95ee\u98984\uff1a\u52a0\u5165redis\u6302\u4e86\u91cd\u542f\u540e\uff0c\u539f\u5e03\u9686\u8fc7\u6ee4\u5668\u4e2d\u7684\u6570\u636e\u4f1a\u4e22\u5931\uff0c\u8fd9\u79cd\u8fd8\u662f\u8981\u901a\u8fc7\u4efb\u52a1\u91cd\u65b0\u521d\u59cb\u5316\u5e03\u9686\u8fc7\u6ee4\u5668\u5427\uff1f<\/p>\n\n\n\n<p>\u56de\u7b54\uff1a<\/p>\n\n\n\n<p>\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u6570\u636e\u662f\u5426\u4e22\u5931\u53d6\u51b3\u4e8eRedis\u7684\u6301\u4e45\u5316\u914d\u7f6e\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6301\u4e45\u5316\u5f00\u542f\uff08RDB\/AOF\uff09 <\/strong>\uff1a\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u4f4d\u6570\u7ec4\u6570\u636e\u4f1a\u88ab\u4fdd\u5b58\uff0c\u91cd\u542f\u540e\u53ef\u6062\u590d\u3002<\/li>\n\n\n\n<li><strong>\u6301\u4e45\u5316\u672a\u5f00\u542f <\/strong>\uff1a\u6570\u636e\u4e22\u5931\uff0c\u9700\u901a\u8fc7\u4efb\u52a1\u91cd\u65b0\u521d\u59cb\u5316\u5e03\u9686\u8fc7\u6ee4\u5668\uff08\u5982\u4ece\u6570\u636e\u5e93\u5168\u91cf\u52a0\u8f7d\uff09\u3002<br><strong>\u8865\u5145\u5efa\u8bae <\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b9a\u671f\u5907\u4efd\u5e03\u9686\u8fc7\u6ee4\u5668\uff08\u5982\u5bfc\u51fa\u4f4d\u6570\u7ec4\u5230\u6587\u4ef6\uff09\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528Redis\u7684 <code>SAVE<\/code> \u6216 <code>BGSAVE<\/code> \u624b\u52a8\u89e6\u53d1\u6301\u4e45\u5316\u3002<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">\u7528\u6237\u5982\u4f55\u5b9e\u73b0\u6d77\u91cf\u8bf7\u6c42\u6ce8\u518c\u529f\u80fd &nbsp;<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.nageoffer.shortlink.admin.dto.req;\n\nimport lombok.Data;\n\n@Data\npublic class UserRegisterReqDTO {\n    \/**\n     * \u7528\u6237\u540d\n     *\/\n    private String username;\n    \/**\n     * \u5bc6\u7801\n     *\/\n    private String password;\n    \/**\n     * \u90ae\u7bb1\n     *\/\n    private String email;\n    \/**\n     * \u624b\u673a\u53f7\n     *\/\n    private String phone;\n    \/**\n     * \u771f\u5b9e\u59d3\u540d\n     *\/\n    private String realName;\n}\n<\/code><\/pre>\n\n\n\n<p>&nbsp;\u6211\u76f8\u4fe1\u5927\u5bb6\u6709\u5f88\u591a\u4eba\u90fd\u662f\u7528\u7684userRegisterReqDTO\uff0c\u8fd9\u6837\u5176\u5b9e\u663e\u5f97\u975e\u5e38\u590d\u6742\u4e5f\u4e0d\u7edf\u4e00\uff0c\u8001\u5e08\u7684\u4e60\u60ef\u50cf\u8fd9\u79cd\u5bf9\u8c61\u5c31\u7528requestparam\uff0c\u4e00\u6574\u4e2a\u5bf9\u8c61\uff0c\u5f88\u591a\u5f88\u591a\u4e0d\u540c\u7684\u5bf9\u8c61\u5efa\u8baerequestparam\u4ee3\u66ff\uff1b<br>\u4e3aUserErrorCodeEnum.java\u6dfb\u52a0\u9519\u8bef\u7801<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">USER_NAME_EXIST(\"B000201\",\"\u7528\u6237\u540d\u5df2\u5b58\u5728\"),\nUSER_EXIST(\"B000202\",\"\u7528\u6237\u8bb0\u5f55\u5df2\u5b58\u5728\");\nUSER_SAVE_ERROR(\"B000203\",\"\u7528\u6237\u6ce8\u518c\u5931\u8d25\");<\/pre>\n\n\n\n<p>\u7528\u6237\u6ce8\u518c\u6d41\u7a0b\u56fe\uff1a\u00a0<img loading=\"lazy\" decoding=\"async\" height=\"532\" width=\"1656\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/e15be87524c748438d11834251f6ebb7.png\" alt=\"\"><\/p>\n\n\n\n<p>&nbsp;\u4e0b\u9762\u662fcontroller\uff0cservice\u4ee5\u53caimpl\uff0c\u4e3a\u4e86\u4e0d\u663e\u793a\u6ce2\u6d6a\u7ebf\uff0c\u5c06\u6240\u6709url\u7684shortlink\u6539\u6210\u4e86short-link<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    \/**\n     * \u6ce8\u518c\u7528\u6237\n     *\/\n    @PostMapping(\"\/api\/short-link\/v1\/user\")\n    public Result&lt;Void&gt; register(@RequestBody UserRegisterReqDTO requestParam) {\n        userService.Register(requestParam);\n        return Results.success();\n    }<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>    \/**\n     * \u6ce8\u518c\u7528\u6237\n     *\n     * @param requestParam \u6ce8\u518c\u7528\u6237\u8bf7\u6c42\u53c2\u6570\n     *\/\n    void Register(UserRegisterReqDTO requestParam);<\/code><\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"15\" src=\"blob:https:\/\/eve2333.top\/df4b90c6-370b-40d2-b1d3-9b76e7e789ca\" width=\"15\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    @Override\n    public void Register(UserRegisterReqDTO requestParam) {\n        if (hasUsername(requestParam.getUsername())) {\n            throw new ClientException(USER_NAME_EXIST);\n        }\n        int inserted = baseMapper.insert(BeanUtil.toBean(requestParam, UserDO.class));\n        if (inserted &lt; 1) {\n            throw new ClientException(USER_SAVE_ERROR);\n        }\n    }    <\/code><\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"853\" width=\"1036\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/c886ef8a044947feb2d866c4a759edae.png\" alt=\"\"><img loading=\"lazy\" decoding=\"async\" height=\"114\" width=\"1213\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/58bcfcc3071b42c491a11acdb1a58b6a.png\" alt=\"\"><\/p>\n\n\n\n<p>\u4f60\u53d1\u73b0mail\u548ccreate update time \u662f\u7a7a\u7684\uff0c\u6240\u4ee5<strong>userRegisterReqDTO\u91cc\u9762email\u5e94\u8be5\u7ed9\u5230mail<\/strong>\uff0c\u8fd8\u6709\u4e24\u4e2atime\u53ef\u4ee5\u7528mybatis-plus\u5b9e\u73b0\uff1a\u6bcf\u4e2a\u8868\u91cc\u9762\u57fa\u672c\u4e0a\u90fd\u6709\u8fd93\u4e2a\u5b57\u6bb5\uff0c\u65b0\u589e\u7684\u65f6\u5019\u8981\u4fdd\u8bc1\u8fd9\u4e09\u4e2a\u8981\u6307\u5b9a\u7684\u503c\uff0c\u6bd4\u5982\u8bf4\u8fd9\u4e24\u4e2a\u65f6\u95f4\u5c31\u662f\u5f53\u5730\u65f6\u95f4\uff0cflag\u9ed8\u8ba40\uff0c<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u81ea\u5b9a\u4e49\u5728config\u4e2d\u8bbe\u7f6eMyMetaObjectHandler\uff0cUserDTO\u91cc\u9762\u4e3acreatetime\uff0cupdatetime\u548cdelflag\u8bbe\u7f6e\u6807\u8bb0<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   \/*\u521b\u5efa\u65f6\u95f4*\/\n    @TableField(fill = FieldFill.INSERT)\n    private Date createTime;\n    \/**\n     * \u4fee\u6539\u65f6\u95f4\n     *\/\n    @TableField(fill = FieldFill.INSERT)\n    private Date updateTime;\n    \/**\n     * \u5220\u9664\u6807\u8bc60\uff1a\u672a\u5220\u96641\uff1a\u5df2\u5220\u9664\n     *\/\n    @TableField(fill = FieldFill.INSERT)\n    private Integer delFlag;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.nageoffer.shortlink.admin.config;\nimport com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;\nimport org.apache.ibatis.reflection.MetaObject;\nimport org.springframework.stereotype.Component;\n\nimport java.time.LocalDateTime;\n\n@Component\npublic class MyMetaObjectHandler implements MetaObjectHandler {\n    @Override\n    public void insertFill(MetaObject metaObject) {\n        this.strictInsertFill(metaObject, \"createTime\", LocalDateTime::now, LocalDateTime.class);\n        this.strictInsertFill(metaObject, \"updateTime\", LocalDateTime::now, LocalDateTime.class);\n        this.strictInsertFill(metaObject, \"delFlag\", () -> 0, Integer.class);\n    }\n\n    @Override\n    public void updateFill(MetaObject metaObject) {\n        this.strictInsertFill(metaObject, \"updateTime\", LocalDateTime::now, LocalDateTime.class);\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u7531\u4e8e\u81ea\u52a8\u7c7b\u578b\u6ca1\u6709\u5339\u914d\u4e0a\uff0c\u56e0\u6b64\u4fee\u6539\u6210\u5982\u4e0b\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@Component\npublic class MyMetaObjectHandler implements MetaObjectHandler {\n    @Override\n    public void insertFill(MetaObject metaObject) {\n        strictInsertFill(metaObject, \"createTime\", Date::new, Date.class);\n        strictInsertFill(metaObject, \"updateTime\", Date::new, Date.class);\n        strictInsertFill(metaObject, \"delFlag\", () -&gt; 0, Integer.class);\n    }\n\n    @Override\n    public void updateFill(MetaObject metaObject) {\n        strictInsertFill(metaObject, \"updateTime\", LocalDateTime::now, LocalDateTime.class);\n    }\n}\n<\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"158\" width=\"1345\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/9fa39318c7c149bb82566e0d01d47adc.png\" alt=\"\"><\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u7ed9username\u52a0\u4e00\u4e2a\u552f\u4e00\u7684\u9650\u5236\uff0c\u54ea\u6015\u5e03\u9686\u8fc7\u6ee4\u5668\u4e5f\u8981\u6709\u4e00\u5b9a\u51e0\u7387\u9519\u8bef\uff0c\u5e95\u5c42redis\u5728\u4e3b\u4ece\u590d\u5236\u7684\u65f6\u5019\uff0c\u54ea\u6015\u662f\u96c6\u7fa4\u4e3b\u4ece\u590d\u5236\uff0c\u4e5f\u6709\u51e0\u7387\u4e3b\u6302\u4e86\uff0c\u4ece\u6ca1\u63a5\u5230\uff0c\u90a3\u90e8\u5206\u6570\u636e\u5c31\u53d8\u6210\u810f\u6570\u636e\u4e86\uff0c\u56e0\u4e3a\u810f\u6570\u636e\u5728\u6570\u636e\u5e93\u4e2d\u6ca1\u6709\u515c\u5e95<\/p>\n\n\n\n<p>\u5728 Navicat Premium \u4e2d\uff0c\u53f3\u952e\u5355\u51fb\u8981\u6dfb\u52a0\u7d22\u5f15\u7684\u8868\uff0c\u9009\u62e9 \u201c\u8bbe\u8ba1\u8868\u201d\u3002\u70b9\u51fb \u201c\u7d22\u5f15\u201d \u9009\u9879\u5361\uff0c\u518d\u70b9\u51fb \u201c\u6dfb\u52a0\u7d22\u5f15\u201d \u6309\u94ae\u3002\u6dfb\u52a0\u552f\u4e00\u7d22\u5f15\uff0c\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u4e00\u4e0b\uff0c\u8fd9\u6837\u5c31\u80fd\u770b\u5230\u201c\u91cd\u590d\u7684\u5bf9\u8c61tom id_unique_username\u201d<img loading=\"lazy\" decoding=\"async\" height=\"121\" width=\"669\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/0c3ad999536644e3b7b2e1067081e73f.png\" alt=\"\"><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"vVbNe\">\u5982\u4f55\u9632\u6b62\u7528\u6237\u540d\u91cd\u590d\uff1f<\/p>\n\n\n\n<p id=\"ua0c43a3c\">\u901a\u8fc7\u5e03\u9686\u8fc7\u6ee4\u5668\u628a\u6240\u6709\u7528\u6237\u540d\u8fdb\u884c\u52a0\u8f7d\u3002\u8fd9\u6837\u8be5\u529f\u80fd\u5c31\u80fd\u5b8c\u5168\u9694\u79bb\u6570\u636e\u5e93\u3002<\/p>\n\n\n\n<p id=\"u279d450b\">\u6570\u636e\u5e93\u5c42\u9762\u6dfb\u52a0\u552f\u4e00\u7d22\u5f15\u3002<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-preformatted\">@Override\npublic void Register(UserRegisterReqDTO requestParam) {\n    if (hasUsername(requestParam.getUsername())) {\n        throw new ClientException(USER_NAME_EXIST);\n    }\n    int inserted = baseMapper.insert(BeanUtil.toBean(requestParam, UserDO.class));\n    if (inserted &lt; 1) {\n        throw new ClientException(USER_SAVE_ERROR);\n    }\n    userRegisterCacheBloomFilter.add(requestParam.getUsername());\n}<\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&nbsp;2. \u5982\u4f55\u9632\u6b62\u6076\u610f\u8bf7\u6c42\u6beb\u79d2\u7ea7\u89e6\u53d1\u5927\u91cf\u8bf7\u6c42\u53bb\u4e00\u4e2a\u672a\u6ce8\u518c\u7684\u7528\u6237\u540d\uff1f<\/p>\n\n\n\n<p id=\"u13ce93bc\">\u56e0\u4e3a\u7528\u6237\u540d\u6ca1\u6ce8\u518c\uff0c\u6240\u4ee5\u5e03\u9686\u8fc7\u6ee4\u5668\u4e0d\u5b58\u5728\uff0c\u4ee3\u8868\u7740\u53ef\u4ee5\u89e6\u53d1\u6ce8\u518c\u6d41\u7a0b\u63d2\u5165\u6570\u636e\u5e93\u3002\u4f46\u662f\u5982\u679c\u6076\u610f\u8bf7\u6c42\u77ed\u65f6\u95f4\u6d77\u91cf\u8bf7\u6c42\uff0c\u8fd9\u4e9b\u8bf7\u6c42\u90fd\u4f1a\u843d\u5230\u6570\u636e\u5e93\uff0c\u9020\u6210\u6570\u636e\u5e93\u8bbf\u95ee\u538b\u529b\u3002\u8fd9\u91cc\u901a\u8fc7\u5206\u5e03\u5f0f\u9501\uff0c\u9501\u5b9a\u7528\u6237\u540d\u8fdb\u884c\u4e32\u884c\u6267\u884c\uff0c\u9632\u6b62\u6076\u610f\u8bf7\u6c42\u5229\u7528\u672a\u6ce8\u518c\u7528\u6237\u540d\u5c06\u8bf7\u6c42\u6253\u5230\u6570\u636e\u5e93\u3002<img loading=\"lazy\" decoding=\"async\" height=\"279\" width=\"639\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/d9ba7e3acab24425bd12c1dc878c9e98.png\" alt=\"\"><\/p>\n\n\n\n<p>3. \u5982\u679c\u6076\u610f\u8bf7\u6c42\u5168\u90e8\u4f7f\u7528\u672a\u6ce8\u518c\u7528\u6237\u540d\u53d1\u8d77\u6ce8\u518c&nbsp;<\/p>\n\n\n\n<p>\u7ed3\u8bba\uff1a\u7cfb\u7edf\u65e0\u6cd5\u8fdb\u884c\u5b8c\u5168\u98ce\u63a7\uff0c\u53ea\u6709\u901a\u8fc7\u7c7b\u4f3c\u4e8e\u9650\u6d41\u7684\u529f\u80fd\u8fdb\u884c\u4fdd\u969c\u7cfb\u7edf\u5b89\u5168&nbsp;<\/p>\n<\/blockquote>\n\n\n\n<p>&nbsp;UserController\u52a0\u4e2a\u975e\uff0cimpl\u4e5f\u662f<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public Result&lt;Boolean&gt; hasUserName(@RequestParam(\"username\")String username) {\n    return Results.success(!userService.hasUsername(username));\n}<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">public Boolean hasUsername(String username) {\n    return !userRegisterCacheBloomFilter.contains(username);\n}\nif (!hasUsername(requestParam.getUsername())) {\n    throw new ClientException(USER_NAME_EXIST);\n}<\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"484\" width=\"682\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/927cef71f4f54b57bbc9a5fd33704b41.png\" alt=\"\">\u8fd4\u56defalse\u8bf4\u660e\u9884\u671f\u7ed3\u679c\u6b63\u5e38<\/p>\n\n\n\n<p>&nbsp;\u63a5\u4e0b\u6765\u8fdb\u4e00\u6b65\u6539\u9020\uff0credisson\u5206\u5e03\u5f0f\u9501\u6709\u4e00\u79cd\u770b\u95e8\u72d7\u7684\u673a\u5236\uff0c\u66f4\u5b89\u5168\uff0c\u5e95\u5c42\u7528net\u505a\u7684\u7f51\u7edc\u901a\u4fe1\u66f4\u9ad8\u6548\uff0c\u5728constant\u4e2d\u65b0\u5efa\u5982\u4e0b\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.nageoffer.shortlink.admin.common.constant;\n\n\/**\n * redisson \u7684\u5e38\u91cf\u547d\u540d\n *\/\npublic class RedisCacheConstant {\n    public static final String LOCK_USER_REGISTER_KEY = \"short-link:lock-user-register:\";\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>    @Override\n    public void Register(UserRegisterReqDTO requestParam) {\n        if (!hasUsername(requestParam.getUsername())) {\n            throw new ClientException(USER_NAME_EXIST);\n        }\n        \/\/\u540e\u9762\u5e94\u8be5\u52a0\u4e00\u4e2arequestParam.getUsername()\uff0c\u4e0d\u62fc\u7684\u8bdd\u5c31\u53d8\u6210\u5168\u5c40\u9501\u4e86\uff0c\u62fc\u4e86\u624d\u4f1a\u4e24\u4e2a\u52a0\u4e00\u8d77\u6574\u4f53\u7684\u9501\n        RLock lock = redissonClient.getLock(LOCK_USER_REGISTER_KEY+requestParam.getUsername());\n        \/**\n         * \u8fd9\u91cc\u4e0d\u80fd\u7528lock\uff0c\u56e0\u4e3a\u5b83\u4f1a\u4e00\u76f4\u7b49\u5f85\u4f60\u4e0a\u4e00\u4e2a\u9501\u91ca\u653e\n         * \u8fd9\u91cc\u4e0d\u9700\u8981\uff0c\u53ea\u8981\u6709\u4e00\u83b7\u53d6\u5230\u9501\uff0c\u6211\u4eec\u5c31\u8ba4\u4e3a\u8fd9\u4e2a\u80fd\u83b7\u53d6\u5230\u9501\u7684\u7528\u6237\u53ef\u4ee5\u6ce8\u518c\u6210\u529f\n         *  \u6240\u4ee5\u8bf4\u5176\u4ed6\u90a3\u79cd\u6ca1\u83b7\u53d6\u5230\u9501\u7684\u76f4\u63a5try lock\uff0ctry lock\u4e4b\u540e\u6211\u4eec\u4e5f\u4e0d\u7528\u53bb\u7ed9\u4ed6\u7b49\uff0c\u76f4\u63a5\u6ce8\u518c\n         *  try lock\u5931\u8d25\u7684\n         *\/\n        try {\n            if (lock.tryLock()) {\n                int inserted = baseMapper.insert(BeanUtil.toBean(requestParam, UserDO.class));\n                if (inserted &lt; 1) {\n                    throw new ClientException(USER_SAVE_ERROR);\n                }\n                userRegisterCachePenetrationBloomFilter.add(requestParam.getUsername());\n                return;\n            }\n            throw new ClientException(USER_NAME_EXIST);\n        } finally {\n            lock.unlock();\n        }\n    }<\/code><\/pre>\n\n\n\n<p>\u901a\u8fc7\u5206\u5e03\u5f0f\u9501\u5b8c\u5584\u7528\u6237\u6ce8\u518c\u529f\u80fd\uff0c\u9632\u6b62\u6076\u610f\u8bf7\u6c42\u6bb5\u65f6\u95f4\u4f7f\u7528\u7edf\u4e00\u672a\u6ce8\u518c\u7528\u6237\u540d\u6ce8\u518c\u65b0\u7528\u6237<\/p>\n\n\n\n<p>&nbsp;\u5982\u679c\u6d77\u91cf\u7528\u6237\u600e\u4e48\u529e\uff1f\uff1f\uff1f<\/p>\n\n\n\n<p>\u4e00\u4e9b\u95ee\u9898&nbsp;<\/p>\n\n\n\n<p>### **\u95ee\u98981\uff1a\u53ef\u4ee5\u4f7f\u7528MyBatis Plus\u7684\u903b\u8f91\u5220\u9664\u5417\uff1f**<br>**\u56de\u7b54\u6b63\u786e\u6027\uff1a\u2705 \u6b63\u786e\uff08\u9700\u8865\u5145\u8bf4\u660e\uff09** &nbsp;<br>**\u5206\u6790**\uff1a &nbsp;<br>MyBatis Plus\u7684\u903b\u8f91\u5220\u9664\u914d\u7f6e\uff08`logic-delete-field`\u3001`logic-delete-value`\u7b49\uff09\u4f1a\u5728\u4ee5\u4e0b\u573a\u666f\u751f\u6548\uff1a &nbsp;<br>- **\u67e5\u8be2\u65f6**\uff1a\u81ea\u52a8\u6dfb\u52a0 `WHERE flag = 0` \u6761\u4ef6\uff0c\u8fc7\u6ee4\u5df2\u903b\u8f91\u5220\u9664\u7684\u6570\u636e\u3002 &nbsp;<br>- **\u66f4\u65b0\u65f6**\uff1a\u8c03\u7528 `removeById` \u7b49\u65b9\u6cd5\u65f6\uff0c\u81ea\u52a8\u5c06 `flag` \u8bbe\u4e3a `1`\uff08\u903b\u8f91\u5220\u9664\uff09\u3002 &nbsp;<br>**\u4ee3\u7801\u4e2d\u7684\u5b9e\u8df5**\uff1a &nbsp;<br>- \u7528\u6237\u6ce8\u518c\u65f6\u63d2\u5165\u6570\u636e\uff08`baseMapper.insert(...)`\uff09\u9700\u663e\u5f0f\u8bbe\u7f6e `flag` \u5b57\u6bb5\u503c\uff08\u5982 `0`\uff09\uff0c\u5426\u5219\u6570\u636e\u5e93\u9ed8\u8ba4\u503c\u6216MP\u81ea\u52a8\u586b\u5145\u9700\u4fdd\u8bc1\u3002 &nbsp;<br>- \u82e5\u672a\u914d\u7f6e\u9ed8\u8ba4\u503c\u4e14\u672a\u624b\u52a8\u8d4b\u503c\uff0c\u53ef\u80fd\u5bfc\u81f4\u63d2\u5165\u6570\u636e\u65f6 `flag` \u4e3a `NULL`\uff0c\u903b\u8f91\u5220\u9664\u5931\u6548\u3002 &nbsp;<br>**\u7ed3\u8bba**\uff1a &nbsp;MP\u63d0\u4f9b\u7684\u8fd9\u4e2a\u914d\u7f6e\u662f\u67e5\u8be2\u548c\u66f4\u65b0\u65f6\u81ea\u52a8\u62fc\u63a5\u903b\u8f91\u5220\u9664\u5b57\u6bb5\u503c\uff0c\u9a6c\u54e5\u4ee3\u7801\u5199\u7684\u662f\u63d2\u5165\u6570\u636e\u5e93\u586b\u5145\u7684\u903b\u8f91\u5220\u9664\u5b57\u6bb5\u7684\u503c\uff0c\u5c31\u4e0d\u7528\u5728\u6570\u636e\u5e93\u91cc\u8bbe\u7f6e\u9ed8\u8ba4\u503c\u4e86\uff0c\u4e2a\u4eba\u7406\u89e3\uff0c\u6709\u9519\u8bf7\u6307\u6b63<br>- **MP\u903b\u8f91\u5220\u9664\u914d\u7f6e\u6709\u6548**\uff0c\u4f46\u9700\u786e\u4fdd\u63d2\u5165\u64cd\u4f5c\u65f6\u903b\u8f91\u5220\u9664\u5b57\u6bb5\u6709\u503c\uff08\u901a\u8fc7\u6570\u636e\u5e93\u9ed8\u8ba4\u503c\u6216\u4ee3\u7801\u81ea\u52a8\u586b\u5145\uff09\u3002 &nbsp;<br>- \u539f\u56de\u7b54\u6b63\u786e\uff0c\u4f46\u9700\u660e\u786e\u63d2\u5165\u6570\u636e\u65f6\u9700\u4fdd\u8bc1\u903b\u8f91\u5220\u9664\u5b57\u6bb5\u521d\u59cb\u5316\u3002<\/p>\n\n\n\n<p>### **\u95ee\u98982\uff1a\u7528\u6237\u540d\u552f\u4e00\u7d22\u5f15\u7684\u91cd\u8981\u6027\u53ca\u5206\u5e03\u5f0f\u9501\u95ee\u9898**<\/p>\n\n\n\n<p>1. \u7528\u6237\u540d\u8bbe\u7f6e\u552f\u4e00\u7d22\u5f15\u7684\u91cd\u8981\u6027\uff0c\u4ece\u76ee\u524d\u4ee3\u7801\u6765\u770b\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u63d2\u5165\u6570\u636e\u5e93\u6210\u529f\uff0c\u4f46\u5199\u5e03\u9686\u8fc7\u6ee4\u5668\u5931\u8d25\u7684\u60c5\u51b5\u3002\u5982\u679c\u53c8\u6765\u4e00\u4e2a\u8be5\u7528\u6237\u540d\u7684\u8bf7\u6c42\uff0c\u4ee3\u7801\u4f1a\u6267\u884c\u5230\u63d2\u5165\u6570\u636e\u5e93\u8fd9\u884c\uff0c\u8fd9\u65f6\u5982\u679c\u6ca1\u6709\u552f\u4e00\u7d22\u5f15\u7684\u9650\u5236\u7684\u8bdd\uff0c\u4f1a\u51fa\u73b0\u91cd\u590d\u7528\u6237\u540d\u8bb0\u5f55\u3002<br>2. \u7ee7\u7eed\u4f53\u4f1a\u6ca1\u6709\u94f6\u5f39\u8fd9\u53e5\u8bdd\uff0c\u4ee3\u7801\u4e2d\u901a\u8fc7\u52a0\u5206\u5e03\u5f0f\u9501\u9632\u6b62\u591a\u4e2a\u8bf7\u6c42\u6ce8\u518c\u540c\u4e00\u7528\u6237\u540d\u7684\u60c5\u51b5\u3002\u4f46\u662f\u4e5f\u53ef\u80fd\u51fa\u73b0\uff0c\u62ff\u5230\u5206\u5e03\u5f0f\u9501\u7684\u8bf7\u6c42\u56e0\u4e3a\u67d0\u4e9b\u8bf7\u6c42\u6ca1\u6709\u6210\u529f\u6ce8\u518c\u8be5\u7528\u6237\u540d\uff0c\u800c\u540c\u4e00\u65f6\u95f4\u5176\u5b83\u8bf7\u6c42\u56e0\u4e3a\u6ca1\u6709\u62ff\u5230\u5206\u5e03\u5f0f\u9501\uff0c\u800c\u663e\u793a\u7528\u6237\u540d\u5df2\u88ab\u4f7f\u7528\uff08\u5b9e\u9645\u4e0a\u5e76\u6ca1\u6709\u88ab\u4f7f\u7528\uff09\u3002\u4ece\u7528\u6237\u7684\u89d2\u5ea6\u51fa\u53d1\uff0c\u4ed6\u5e76\u4e0d\u77e5\u9053\u7528\u6237\u540d\u5e76\u6ca1\u6709\u88ab\u4f7f\u7528\uff0c\u800c\u540e\u7eed\u7684\u7528\u6237\u5982\u679c\u7ee7\u7eed\u4f7f\u7528\u8be5\u7528\u6237\u540d\u6ce8\u518c\u4e5f\u662f\u53ef\u4ee5\u7684\u3002<\/p>\n\n\n\n<p>**\u56de\u7b54\u6b63\u786e\u6027\uff1a\u2705 \u6b63\u786e\uff08\u9700\u8865\u5145\u89e3\u51b3\u65b9\u6848\uff09** &nbsp;<br>#### **1. \u552f\u4e00\u7d22\u5f15\u7684\u5fc5\u8981\u6027** &nbsp;<br>- **\u95ee\u9898**\uff1a\u82e5\u6570\u636e\u5e93\u65e0\u552f\u4e00\u7d22\u5f15\uff0c\u63d2\u5165\u6210\u529f\u4f46\u5e03\u9686\u8fc7\u6ee4\u5668\u5199\u5165\u5931\u8d25\u65f6\uff0c\u540e\u7eed\u8bf7\u6c42\u53ef\u80fd\u56e0\u5e03\u9686\u8fc7\u6ee4\u5668\u8bef\u5224\uff08\u8ba4\u4e3a\u7528\u6237\u4e0d\u5b58\u5728\uff09\u800c\u518d\u6b21\u63d2\u5165\uff0c\u5bfc\u81f4\u91cd\u590d\u6570\u636e\u3002 &nbsp;<br>- **\u89e3\u51b3\u65b9\u6848**\uff1a &nbsp;<br>&nbsp; - **\u6570\u636e\u5e93\u552f\u4e00\u7d22\u5f15**\uff1a\u786e\u4fdd\u7528\u6237\u540d\u5b57\u6bb5\uff08\u5982 `username`\uff09\u6709\u552f\u4e00\u7ea6\u675f\uff0c\u9632\u6b62\u91cd\u590d\u63d2\u5165\u3002 &nbsp;<br>&nbsp; - **\u5e03\u9686\u8fc7\u6ee4\u5668\u91cd\u8bd5\u673a\u5236**\uff1a\u63d2\u5165\u6570\u636e\u5e93\u540e\uff0c\u82e5\u5e03\u9686\u8fc7\u6ee4\u5668\u5199\u5165\u5931\u8d25\uff0c\u901a\u8fc7\u5f02\u6b65\u4efb\u52a1\u91cd\u8bd5\u6216\u8865\u507f\u673a\u5236\u66f4\u65b0\u5e03\u9686\u8fc7\u6ee4\u5668\u3002 &nbsp;<\/p>\n\n\n\n<p>#### **2. \u5206\u5e03\u5f0f\u9501\u7684\u8bef\u5224\u95ee\u9898** &nbsp;<br>- **\u95ee\u9898**\uff1a\u6301\u6709\u9501\u7684\u7ebf\u7a0b\u56e0\u5f02\u5e38\uff08\u5982\u8d85\u65f6\u3001\u7f51\u7edc\u6545\u969c\uff09\u672a\u5b8c\u6210\u6ce8\u518c\uff0c\u5176\u4ed6\u7ebf\u7a0b\u56e0\u672a\u83b7\u53d6\u9501\u800c\u8bef\u5224\u7528\u6237\u540d\u5df2\u88ab\u5360\u7528\u3002 &nbsp;<br>- **\u89e3\u51b3\u65b9\u6848**\uff1a &nbsp;<br>&nbsp; - **\u9501\u7eed\u671f\u673a\u5236**\uff1a\u4f7f\u7528Redisson\u7684\u770b\u95e8\u72d7\uff08Watchdog\uff09\u81ea\u52a8\u5ef6\u957f\u9501\u8fc7\u671f\u65f6\u95f4\u3002 &nbsp;<br>&nbsp; - **\u6ce8\u518c\u72b6\u6001\u68c0\u67e5**\uff1a\u83b7\u53d6\u9501\u5931\u8d25\u524d\uff0c\u5148\u68c0\u67e5\u6570\u636e\u5e93\u6216\u5e03\u9686\u8fc7\u6ee4\u5668\u662f\u5426\u5df2\u5b58\u5728\u8be5\u7528\u6237\u540d\uff0c\u907f\u514d\u8bef\u5224\u3002 &nbsp;<\/p>\n\n\n\n<p>**\u7ed3\u8bba**\uff1a\u7528\u6237\u6307\u51fa\u7684\u95ee\u9898\u6b63\u786e\uff0c\u9700\u7ed3\u5408\u552f\u4e00\u7d22\u5f15\u548c\u9501\u4f18\u5316\u65b9\u6848\u89e3\u51b3\u3002<\/p>\n\n\n\n<p>\u95ee\u98983\uff1a\u4e3a\u4f55\u4f7f\u7528MP\u81ea\u52a8\u586b\u5145\u800c\u975e\u6570\u636e\u5e93\u9ed8\u8ba4\u8bed\u53e5'`update_time` datetime DEFAULT current_timestamp on update current_timestamp COMMENT '\u4fee\u6539\u65f6\u95f4''\uff1f&nbsp;<br>**\u56de\u7b54\u6b63\u786e\u6027\uff1a\u2705 \u6b63\u786e\uff08\u9700\u5bf9\u6bd4\u4f18\u7f3a\u70b9\uff09** &nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>MP\u81ea\u52a8\u586b\u5145 vs \u6570\u636e\u5e93\u9ed8\u8ba4\u503c<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><strong>\u7279\u6027<\/strong><\/th><th><strong>MP\u81ea\u52a8\u586b\u5145<\/strong><\/th><th><strong>\u6570\u636e\u5e93\u9ed8\u8ba4\u503c<\/strong><\/th><\/tr><\/thead><tbody><tr><td><strong>\u53ef\u63a7\u6027<\/strong><\/td><td>\u4ee3\u7801\u5c42\u63a7\u5236\uff0c\u907f\u514d\u4f9d\u8d56\u6570\u636e\u5e93\u914d\u7f6e<\/td><td>\u6570\u636e\u5e93\u5c42\u63a7\u5236\uff0c\u4ee3\u7801\u65e0\u9700\u5904\u7406<\/td><\/tr><tr><td><strong>\u7075\u6d3b\u6027<\/strong><\/td><td>\u53ef\u6839\u636e\u4e1a\u52a1\u903b\u8f91\u52a8\u6001\u8bbe\u7f6e\u503c<\/td><td>\u56fa\u5b9a\u503c\uff0c\u65e0\u6cd5\u52a8\u6001\u8c03\u6574<\/td><\/tr><tr><td><strong>\u4e00\u81f4\u6027<\/strong><\/td><td>\u9700\u786e\u4fdd\u63d2\u5165\u64cd\u4f5c\u59cb\u7ec8\u7ecf\u8fc7MP\u903b\u8f91\uff0c\u5426\u5219\u5931\u6548<\/td><td>\u6240\u6709\u63d2\u5165\u64cd\u4f5c\u5747\u751f\u6548\uff08\u5305\u62ec\u624b\u52a8SQL\uff09<\/td><\/tr><tr><td><strong>\u53ef\u7ef4\u62a4\u6027<\/strong><\/td><td>\u4ee3\u7801\u96c6\u4e2d\u7ba1\u7406\uff0c\u6613\u7ef4\u62a4<\/td><td>\u5206\u6563\u5728\u6570\u636e\u5e93\u914d\u7f6e\u4e2d\uff0c\u6613\u88ab\u5ffd\u7565<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>**\u539f\u56de\u7b54\u8865\u5145**\uff1a &nbsp;<br>- **MP\u81ea\u52a8\u586b\u5145\u4f18\u52bf**\uff1a\u907f\u514d\u7a0b\u5e8f\u5458\u5fd8\u8bb0\u8d4b\u503c\uff0c\u4e14\u53ef\u5728\u4e1a\u52a1\u903b\u8f91\u4e2d\u52a8\u6001\u8c03\u6574\uff08\u5982\u6839\u636e\u6761\u4ef6\u8bbe\u7f6e\u4e0d\u540c\u503c\uff09\u3002 &nbsp;<br>- **\u6570\u636e\u5e93\u9ed8\u8ba4\u503c\u4f18\u52bf**\uff1a\u5bf9\u6240\u6709\u63d2\u5165\u64cd\u4f5c\u751f\u6548\uff08\u5305\u62ec\u975eMP\u8c03\u7528\u7684SQL\uff09\u3002 &nbsp;<br>**\u7ed3\u8bba**\uff1a\u4e24\u8005\u5747\u53ef\uff0cMP\u81ea\u52a8\u586b\u5145\u66f4\u9002\u5408\u9700\u8981\u52a8\u6001\u63a7\u5236\u7684\u573a\u666f\u3002<\/p>\n\n\n\n<p>\u95ee\u98984\uff1a`hasUsername` \u65b9\u6cd5\u4e0d\u52a0 `!` \u662f\u5426\u6b63\u786e\uff1f**<br>**\u56de\u7b54\u6b63\u786e\u6027\uff1a\u274c \u9519\u8bef\uff08\u4ee3\u7801\u903b\u8f91\u9519\u8bef\uff09** \u00a0<br>#### **\u5e03\u9686\u8fc7\u6ee4\u5668\u903b\u8f91\u5206\u6790** \u00a0<br>- **\u5e03\u9686\u8fc7\u6ee4\u5668\u7528\u9014**\uff1a\u7528\u4e8e\u5feb\u901f\u5224\u65ad\u5143\u7d20\u662f\u5426\u5b58\u5728\uff0c\u4f46\u5b58\u5728\u5047\u9633\u6027\uff08\u53ef\u80fd\u8bef\u5224\u5b58\u5728\uff09\u3002 \u00a0<br>- **\u4ee3\u7801\u4e2d\u7684 `hasUsername` \u65b9\u6cd5**\uff1a \u00a0<br>\u00a0 public Boolean hasUsername(String username) {<br>\u00a0 \u00a0 \u00a0 return !userRegisterCachePenetrationBloomFilter.contains(username);<br>\u00a0 }<br>\u00a0 - **`contains` \u65b9\u6cd5\u8fd4\u56de `true`**\uff1a\u8868\u793a\u7528\u6237\u540d\u53ef\u80fd\u5b58\u5728\uff08\u9700\u8fdb\u4e00\u6b65\u9a8c\u8bc1\uff09\u3002 \u00a0<br>\u00a0 - **`contains` \u8fd4\u56de `false`**\uff1a\u7528\u6237\u540d\u4e00\u5b9a\u4e0d\u5b58\u5728\u3002 \u00a0<br>- **\u5f53\u524d\u903b\u8f91\u95ee\u9898**\uff1a \u00a0<br>\u00a0 - `!contains(...)` \u7684\u542b\u4e49\u662f\u300c\u7528\u6237\u540d\u4e0d\u5b58\u5728\u300d\uff0c\u4f46 `hasUsername` \u65b9\u6cd5\u540d\u6697\u793a\u300c\u7528\u6237\u540d\u662f\u5426\u5b58\u5728\u300d\u3002 \u00a0<br>\u00a0 - \u8c03\u7528 `hasUsername(\"Alice\")` \u8fd4\u56de `true` \u65f6\uff0c\u5b9e\u9645\u8868\u793a\u300c\u7528\u6237\u540d\u4e0d\u5b58\u5728\u300d\uff0c\u8bed\u4e49\u77db\u76fe\u3002 \u00a0<\/p>\n\n\n\n<p>\u6b63\u786e\u903b\u8f91<br>public Boolean hasUsername(String username) {<br>\u00a0 \u00a0 \/\/ \u8fd4\u56de true \u8868\u793a\u7528\u6237\u540d\u5b58\u5728\uff08\u53ef\u80fd\u8bef\u5224\uff09\uff0cfalse \u8868\u793a\u4e00\u5b9a\u4e0d\u5b58\u5728<br>\u00a0 \u00a0 return userRegisterCachePenetrationBloomFilter.contains(username);<br>}<br><br>**\u7ed3\u8bba**\uff1a\u539f\u4ee3\u7801\u903b\u8f91\u9519\u8bef\uff0c`hasUsername` \u65b9\u6cd5\u5e94\u76f4\u63a5\u8fd4\u56de `contains(...)` \u7684\u7ed3\u679c\uff0c\u800c\u975e\u53d6\u53cd\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u95ee\u98985\uff1a`unlock()` \u653e\u5728 `finally` \u4e2d\u662f\u5426\u5bfc\u81f4\u5f02\u5e38\uff1f<br>\u56de\u7b54\u6b63\u786e\u6027\uff1a\u2705 \u6b63\u786e\uff08\u9700\u4ee3\u7801\u4f18\u5316\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>try {\n    if (lock.tryLock()) {\n        \/\/ \u6ce8\u518c\u903b\u8f91\n        return;\n    }\n    throw new ClientException(USER_NAME_EXIST);\n} finally {\n    lock.unlock();\n}<\/code><\/pre>\n\n\n\n<p>\u95ee\u9898\uff1a\u82e5 `tryLock()` \u5931\u8d25\uff08\u672a\u83b7\u53d6\u9501\uff09\uff0c`finally` \u5757\u4ecd\u8c03\u7528 `unlock()`\uff0c\u5bfc\u81f4 `IllegalMonitorStateException`\u3002 &nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (!lock.tryLock()) {\n&nbsp; &nbsp; throw new ClientException(USER_NAME_EXIST);\n}\ntry {\n&nbsp; &nbsp; \/\/ \u6ce8\u518c\u903b\u8f91\n} finally {\n&nbsp; &nbsp; lock.unlock();\n}<\/code><\/pre>\n\n\n\n<p>\u6539\u8fdb\u70b9\uff1a &nbsp;<br>&nbsp; 1. **\u63d0\u524d\u5224\u65ad\u9501\u83b7\u53d6**\uff1a\u672a\u83b7\u53d6\u9501\u76f4\u63a5\u629b\u5f02\u5e38\uff0c\u907f\u514d\u65e0\u6548\u89e3\u9501\u3002 &nbsp;<br>&nbsp; 2. **\u786e\u4fdd\u4ec5\u6301\u6709\u9501\u7684\u7ebf\u7a0b\u89e3\u9501**\uff1a`finally` \u5757\u4ec5\u5728\u83b7\u53d6\u9501\u540e\u6267\u884c `unlock()`\u3002 &nbsp;<br>\u89e3\u51b3\u65b9\u6848\u6b63\u786e\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6628\u5929\u5728\u7fa4\u91cc\u770b\u5230\u6709\u4eba\u8bf4\u8fd9\u4e2a\uff0c\u6211\u5728\u70b9\u8bc4\u91cc\u5b66\u5230\u7684\u662f\u53ef\u4ee5\u628atrylock\u63d0\u51fa\u6765\uff0c\u8fd9\u6837\u5176\n\u4ed6\u7ebf\u7a0b\u6ca1\u83b7\u53d6\u5230\u9501\u7684\u8bdd\u76f4\u63a5\u629b\u5f02\u5e38\uff0c\u5982\u679c\u83b7\u53d6\u5230\u9501\u7684\u8bdd\u5c31\u8fdb\u884c\u6ce8\u518c\uff0c\u8fd9\u6837\u7684\u8bdd\u5c31\u4e0d\n\u7528\u52a0\u989d\u5916\u7684\u5224\u65ad\u3002\u4ee3\u7801\u5982\u4e0b\uff1a\n\/\/ \u4e0a\u9501\uff0c\u5f00\u59cb\u64cd\u4f5c\uff0c\u5bf9\u5f53\u524d\u7528\u6237\u52a0\u9501\nRLock lock = redissonClient.getLock(LOCK_USER_REGISTER_KEY + username);\n\/\/ \u8c03\u7528\u7528\u6237\u670d\u52a1\u83b7\u53d6\u9501\nif(lock.tryLock()){\n    \/\/ \u7528\u6237\u83b7\u53d6\u4e0d\u5230\u9501\uff0c\u76f4\u63a5\u5931\u8d25\n    throw new ClientException(UserCodeEnum.USER_SAVE_FAIL);\n}\ntry{\n    \/\/ \u5c06\u6ce8\u518c\u8bf7\u6c42\uff0c\u5c06\u6ce8\u518c\u4fe1\u606f\u5b58\u5165\u6570\u636e\u5e93\n    \/\/ \u6570\u636e\u5e93\u4fdd\u5b58\u6210\u529f\n    UserDao userDao = BeanUtil.toBean(userRegisterRequestDTO, UserDao.class);\n    \/\/ \u5b58\u5165\u6570\u636e\u5e93\n    boolean isSuccess = save(userDao);\n    if(isSuccess){\n        \/\/ \u5c06\u7528\u6237\u540d\u5b58\u5165\u7f13\u5b58\n        userRegisterCachePermissionUtil.add(userDao.getUsername());\n        \/\/ \u5c06\u5f53\u524d\u6ce8\u518c\u6210\u529f\u7684\u7528\u6237\u4fe1\u606f\u5b58\u5165\u5206\u7ec4\n        groupPermissionUtil.add(userDao.getUsername(), \"user\");\n        return Result.success();\n    }\n    \/\/ \u6570\u636e\u5e93\u4fdd\u5b58\u5931\u8d25\uff0c\u629b\u51fa\u5f02\u5e38\n    throw new ClientException(UserCodeEnum.USER_SAVE_FAIL);\n}finally {\n    \/\/ \u65e0\u8bba\u4e0a\u8ff0\u6b65\u9aa4\u662f\u5426\u6210\u529f\uff0c\u89e3\u9501\n    lock.unlock();\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u95ee\u9898<\/th><th>\u56de\u7b54\u6b63\u786e\u6027<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><strong>\u95ee\u98981<\/strong><\/td><td>\u2705 \u6b63\u786e<\/td><td>MP\u903b\u8f91\u5220\u9664\u914d\u7f6e\u6709\u6548\uff0c\u4f46\u9700\u786e\u4fdd\u63d2\u5165\u65f6\u903b\u8f91\u5220\u9664\u5b57\u6bb5\u6709\u503c\u3002<\/td><\/tr><tr><td><strong>\u95ee\u98982<\/strong><\/td><td>\u2705 \u6b63\u786e<\/td><td>\u9700\u7ed3\u5408\u552f\u4e00\u7d22\u5f15\u548c\u9501\u4f18\u5316\u65b9\u6848\u89e3\u51b3\u91cd\u590d\u6ce8\u518c\u548c\u8bef\u5224\u95ee\u9898\u3002<\/td><\/tr><tr><td><strong>\u95ee\u98983<\/strong><\/td><td>\u2705 \u6b63\u786e<\/td><td>MP\u81ea\u52a8\u586b\u5145\u66f4\u7075\u6d3b\u53ef\u63a7\uff0c\u4f46\u9700\u6839\u636e\u573a\u666f\u9009\u62e9\u3002<\/td><\/tr><tr><td><strong>\u95ee\u98984<\/strong><\/td><td>\u274c \u9519\u8bef<\/td><td><code>hasUsername<\/code>\u65b9\u6cd5\u903b\u8f91\u9519\u8bef\uff0c\u9700\u76f4\u63a5\u8fd4\u56de<code>contains(...)<\/code>\u7ed3\u679c\u3002<\/td><\/tr><tr><td><strong>\u95ee\u98985<\/strong><\/td><td>\u2705 \u6b63\u786e<\/td><td>\u63d0\u524d\u5224\u65ad\u9501\u83b7\u53d6\u72b6\u6001\uff0c\u907f\u514d<code>unlock()<\/code>\u5f02\u5e38\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>- \u5bf9\u95ee\u98984\u4fee\u6b63 `hasUsername` \u65b9\u6cd5\u903b\u8f91\u3002 &nbsp;<br>- \u5bf9\u95ee\u98982\u8865\u5145\u552f\u4e00\u7d22\u5f15\u548c\u9501\u7eed\u671f\u65b9\u6848\u3002 \u200b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;\u7528\u6237\u654f\u611f\u4fe1\u606f\u63a5\u53e3\u8fd4\u56de\u8131\u654f \u6211\u4eec\u770b\u4e00\u4e0b12306\u662f\u5982\u4f55\u5b9e\u73b0\u8fd9\u4e2a\u7684\uff0c\u6211\u4eec\u5728\u8fdb\u5165\u8ba2\u5355\u63d0\u4ea4\u9875\u7684\u65f6\u5019\uff0c\u5c31\u662f\u5728\u4f60\u9009\u597d\u8f66\u6b21\u7684\u65f6\u5019\u9009\u62e9 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[3],"tags":[16,20],"class_list":["post-1166","post","type-post","status-publish","format-standard","hentry","category-3","tag-sql","tag-20"],"_links":{"self":[{"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts\/1166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1166"}],"version-history":[{"count":1,"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts\/1166\/revisions"}],"predecessor-version":[{"id":1167,"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts\/1166\/revisions\/1167"}],"wp:attachment":[{"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}