{"id":201596,"date":"2025-05-10T08:18:10","date_gmt":"2025-05-10T00:18:10","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201596\/"},"modified":"2025-05-10T08:18:10","modified_gmt":"2025-05-10T00:18:10","slug":"redis%e7%bc%93%e5%ad%98%e5%ae%9e%e4%be%8b%e8%b6%85%e8%af%a6%e7%bb%86%e8%ae%b2%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201596\/","title":{"rendered":"Redis\u7f13\u5b58\u5b9e\u4f8b\u8d85\u8be6\u7ec6\u8bb2\u89e3"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Redis\u7f13\u5b58\u5b9e\u4f8b\u8d85\u8be6\u7ec6\u8bb2\u89e3<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300aRedis\u7f13\u5b58\u5b9e\u4f8b\u8d85\u8be6\u7ec6\u8bb2\u89e3\u300b\uff0c\u4e3b\u8981\u5305\u62ec\u7b56\u7565\u3001redis\u7f13\u5b58\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002<\/p>\n<h2>1 \u524d\u8a00<\/h2>\n<h3>1.1 \u4ec0\u4e48\u662f\u7f13\u5b58<\/h3>\n<p>\u7f13\u5b58\u5c31\u662f\u6570\u636e\u4ea4\u6362\u7684\u7f13\u51b2\u533a\uff08\u79f0\u4f5cCache [ k\u00e6\u0283 ] \uff09\uff0c\u662f\u5b58\u8d2e\u6570\u636e\u7684\u4e34\u65f6\u5730\u65b9\uff0c\u4e00\u822c\u8bfb\u5199\u6027\u80fd\u8f83\u9ad8\u3002<\/p>\n<p>\u7f13\u5b58\u6709\u5f88\u591a\u4e2d\u5b9e\u73b0\u573a\u666f\uff1a\u5bf9\u4e8eweb\u5f00\u53d1\uff0c\u5e38\u89c1\u7684\u6709\u5982\u4e0b\u51e0\u79cd\uff1a<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728964963f968b1c9e0c.png\" class=\"aligncenter\"><\/p>\n<p>\u800c\u6211\u4eec\u7684Redis\u7f13\u5b58\u529f\u80fd\u5c31\u662f\u5c5e\u4e8e\u5728\u5e94\u7528\u5c42\u7f13\u5b58 \u3002<\/p>\n<h3>1.2 \u7f13\u5b58\u7684\u4f5c\u7528\u53ca\u6210\u672c<\/h3>\n<p>\u4f5c\u7528\uff1a\u6beb\u65e0\u7591\u95ee\uff0c\u5c31\u662f\u63d0\u9ad8\u8bfb\u5199\u7684\u6548\u7387\uff0c\u6709\u6548\u964d\u4f4e\u540e\u7aef\u670d\u52a1\u5668\u7684\u8d1f\u8f7d\uff0c\u6709\u6548\u964d\u4f4e\u54cd\u5e94\u65f6\u95f4\u3002<\/p>\n<p>\u6210\u672c\uff1a\u4efb\u4f55\u4e1c\u897f\u90fd\u6709\u4e24\u9762\u6027\uff0c\u7f13\u5b58\u5728\u5e26\u6765\u9ad8\u6548\u7684\u8bfb\u5199\u6548\u7387\u7684\u540c\u65f6\uff0c\u4e5f\u6709\u7740\u5bf9\u5e94\u7684\u4ece\u6210\u672c\u3002<\/p>\n<p>\u6bd4\u5982\uff1a\u6570\u636e\u4e00\u81f4\u6027\u6210\u672c\u3001\u4ee3\u7801\u7ef4\u62a4\u6210\u672c\u3001\u8fd0\u7ef4\u6210\u672c\u7b49\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965063f968b2307c0.png\" class=\"aligncenter\"><\/p>\n<h3>1.3 Redis\u7f13\u5b58\u6a21\u578b<\/h3>\n<p>\u5982\u4e0b\u56fe<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965063f968b28cef4.png\" class=\"aligncenter\"><\/p>\n<p>\u539f\u672c\u7684\u6a21\u578b\u5e94\u8be5\u662f\u5ba2\u6237\u7aef\u53d1\u9001\u8bf7\u6c42\u7ed9\u6570\u636e\u5e93\uff0c\u6570\u636e\u5e93\u8fd4\u56de\u6570\u636e\u7ed9\u5ba2\u6237\u7aef\uff0c\u800cReids\u7684\u7f13\u5b58\u6a21\u578b\u5c31\u662f\u5728\u539f\u6709\u7684\u57fa\u7840\u4e0a\uff0c\u5728\u4e2d\u95f4\u52a0\u4e0a\u4e00\u5c42Redis\uff08\u7ecf\u5178\u7684\u4e2d\u95f4\u4ef6\u601d\u60f3~\uff09\u7528\u6237\u6bcf\u6b21\u90fd\u4f1a\u5148\u53bbredis\u4e2d\u67e5\u627e\u6570\u636e\uff0c\u5982\u679c\u672a\u547d\u4e2d\u624d\u4f1a\u53bb\u6570\u636e\u5e93\u4e2d\u67e5\u627e\u6570\u636e\uff0c\u5e76\u5199\u5165Reis\u5f53\u4e2d\uff0c\u8fd9\u4e48\u4e00\u6765\uff0c\u7528\u4e8e\u4e0b\u6b21\u9700\u8981\u76f8\u540c\u7684\u6570\u636e\u7684\u65f6\u5019\uff0c\u5c31\u53ef\u4ee5\u5728Reis\u5f53\u4e2d\u8fdb\u884c\u83b7\u53d6\uff0c\u53c8\u56e0\u4e3aRedis\u7684\u9ad8\u8bfb\u5199\u6548\u7387\uff0c\u5b9e\u73b0\u4e86\u7f13\u5b58\u7684\u6548\u679c~<\/p>\n<h2>2 \u7ed9\u5546\u6237\u4fe1\u606f\u6dfb\u52a0\u7f13\u5b58<\/h2>\n<p>\u57fa\u4e8e\u4e0a\u8ff0\u7684Redis\u7f13\u5b58\u6a21\u578b\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa\u4e0b\u9762\u7684\u7f13\u5b58\u6dfb\u52a0\u903b\u8f91\uff1a<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965063f968b2dd9d0.png\" class=\"aligncenter\"><\/p>\n<p>\u4ee3\u7801\u5b9e\u73b0\uff1a\uff08\u76f4\u63a5\u770bService\u5c42\u5b9e\u73b0\uff09<\/p>\n<p>\u6bcf\u6b21\u67e5\u8be2\u5230\u5546\u54c1\u7528\u6237\u4fe1\u606f\u540e\uff0c\u6dfb\u52a0\u7f13\u5b58\u3002<\/p>\n<pre>package com.hmdp.service.impl;\nimport cn.hutool.core.util.StrUtil;\nimport cn.hutool.json.JSONUtil;\nimport com.hmdp.dto.Result;\nimport com.hmdp.entity.Shop;\nimport com.hmdp.mapper.ShopMapper;\nimport com.hmdp.service.IShopService;\nimport com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;\nimport org.springframework.data.redis.core.StringRedisTemplate;\nimport org.springframework.stereotype.Service;\nimport org.springframework.transaction.annotation.Transactional;\nimport javax.annotation.Resource;\nimport java.util.concurrent.TimeUnit;\nimport static com.hmdp.utils.RedisConstants.CACHE_SHOP_KEY;\nimport static com.hmdp.utils.RedisConstants.CACHE_SHOP_TTL;\n\/**\n * <p>\n *  \u670d\u52a1\u5b9e\u73b0\u7c7b\n * <\/p>\n *\n *\/\n@Service\npublic class ShopServiceImpl extends ServiceImpl\n   \n     implements IShopService {\n    @Resource\n    private StringRedisTemplate stringRedisTemplate;\n    @Override\n    public Result queryShopById(Long id) {\n        \/\/1.\u53bbredis\u4e2d\u67e5\u8be2\u5546\u54c1\u662f\u5426\u5b58\u5728\n        String key = CACHE_SHOP_KEY+id;\n        String shopJson = stringRedisTemplate.opsForValue().get(key);\n        if (StrUtil.isNotBlank(shopJson)){\n            \/\/2.\u5b58\u5728\uff0c\u76f4\u63a5\u8fd4\u56de\u7ed9\u7528\u6237\n            Shop shop = JSONUtil.toBean(shopJson, Shop.class);\n            return Result.ok(shop);\n        }\n        \/\/3.\u4e0d\u5b58\u5728\uff0c\u5e26\u7740id\u53bb\u6570\u636e\u5e93\u67e5\u8be2\u662f\u5426\u5b58\u5728\u5546\u54c1\n        Shop shop = getById(id);\n        if (shop == null){\n            \/\/4.\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\n            Result.fail(\"\u5546\u54c1\u4fe1\u606f\u4e0d\u5b58\u5728\uff01\");\n        }\n        \/\/5.\u5b58\u5728\uff0c\u5b58\u5165redis\n        stringRedisTemplate.opsForValue().set(key,JSONUtil.toJsonStr(shop));\n        \/\/6.\u8fd4\u56de\u5546\u54c1\u4fe1\u606f\n        return Result.ok(shop);\n    }\n}\n   <\/pre>\n<h2>3 \u7f13\u5b58\u66f4\u65b0\u7b56\u7565<\/h2>\n<h3>3.1 \u66f4\u65b0\u7b56\u7565\u4ecb\u7ecd<\/h3>\n<p>\u4f7f\u7528Redis\u505a\u7f13\u5b58\u65f6\uff0c\u7f13\u5b58\u8fd8\u662f\u8981\u53ca\u65f6\u66f4\u65b0\u7684\uff0c\u4e0d\u7136\u5c31\u4f1a\u51fa\u73b0\u6570\u636e\u5e93\u548c\u7f13\u5b58\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\uff0c\u4e5f\u662f\u6211\u4eec\u5e38\u8bf4\u7684Redis\u6210\u672c\u2014\u2014\u6570\u636e\u4e00\u81f4\u6027\u6210\u672c<\/p>\n<p>\u7f13\u5b58\u5927\u81f4\u6709\u4ee5\u4e0b\u4e09\u79cd\u66f4\u65b0\u7b56\u7565\uff1a<\/p>\n<p>1. \u5185\u5b58\u6dd8\u6c70\u7b56\u7565\uff1a\u8fd9\u79cd\u7b56\u7565\u6ca1\u6709\u7ef4\u62a4\u6210\u672c\uff0c\u8fd9\u662f\u5229\u7528Redis\u7684\u5185\u5b58\u6dd8\u6c70\u673a\u5236\uff0c\u5f53\u5185\u5b58\u4e0d\u8db3\u7684\u65f6\u5019\u81ea\u52a8\u6dd8\u6c70\uff0c\u4e0b\u6b21\u8bf7\u6c42\u65f6\u518d\u7ee7\u7eed\u5b58\u5165\u6570\u636e\u3002<\/p>\n<p>\u8fd9\u79cd\u7b56\u7565\u6a21\u578b\u4f18\u70b9\u5728\u4e8e\u6ca1\u6709\u7ef4\u62a4\u6210\u672c\uff0c\u4f46\u662f\u5185\u5b58\u4e0d\u8db3\u8fd9\u79cd\u65e0\u6cd5\u9884\u5b9a\u7684\u60c5\u51b5\u5c31\u5bfc\u81f4\u4e86\u7f13\u5b58\u4e2d\u4f1a\u6709\u5f88\u591a\u65e7\u7684\u6570\u636e\uff0c\u6570\u636e\u4e00\u81f4\u6027\u5dee\u3002<\/p>\n<p>2. \u8d85\u65f6\u5254\u9664\uff1a\u8fd9\u79cd\u7b56\u7565\u5c31\u662f\u6bd4\u8f83\u5b9e\u7528\u7684\uff0c\u5c31\u662f\u7ed9\u7f13\u5b58\u6dfb\u52a0TTL\u5b58\u6d3b\u65f6\u95f4\uff0c\u4e0b\u6b21\u67e5\u8be2\u662f\u66f4\u65b0\u7f13\u5b58\u3002<\/p>\n<p>\u8fd9\u79cd\u7b56\u7565\u6570\u636e\u4e00\u81f4\u6027\u4e00\u822c\uff0c\u7ef4\u62a4\u6210\u672c\u6709\u4f46\u662f\u8f83\u4f4e\uff0c\u4e00\u822c\u7528\u4e8e\u515c\u5e95\u65b9\u6848~<\/p>\n<p>3.\u4e3b\u52a8\u66f4\u65b0\u7b56\u7565\uff1a\u5c31\u662f\u6211\u4eec\u7a0b\u5e8f\u5458\u624b\u52a8\u7684\u8fdb\u884c\u6570\u636e\u5e93\u548c\u7f13\u5b58\u4e4b\u95f4\u7684\u66f4\u65b0\uff0c\u4f46\u6570\u636e\u5e93\u66f4\u65b0\u65f6\uff0c\u7f13\u5b58\u4e5f\u8fdb\u884c\u66f4\u65b0\u3002<\/p>\n<p>\u8fd9\u79cd\u7b56\u7565\u6570\u636e\u4e00\u81f4\u6027\u5c31\u662f\u6700\u9ad8\u7684\uff08\u6bd5\u7adf\u81ea\u5df1\u52a8\u624b\uff0c\u4e30\u8863\u8db3\u98df\uff09\uff0c\u4f46\u540c\u65f6\u7ef4\u62a4\u6210\u672c\u4e5f\u662f\u6700\u9ad8\u7684\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965163f968b35f399.png\" class=\"aligncenter\"><\/p>\n<p>\u90a3\u4e48\uff0c\u53c8\u8be5\u5982\u4f55\u9009\u62e9\u7f13\u5b58\u66f4\u65b0\u7b56\u7565\u5462\uff1f<\/p>\n<p>\u6211\u7684\u89c9\u5f97\u5e94\u8be5\u662f\u6839\u636e\u4e1a\u52a1\u573a\u666f\u4e0d\u540c\u6765\u9009\u62e9\u4e0d\u540c\u7684\u66f4\u65b0\u7b56\u7565\uff1a<\/p>\n<p>\u5f53\u6570\u636e\u4e00\u81f4\u6027\u8981\u6c42\u4f4e\u65f6\uff1al\u4f7f\u7528\u5185\u5b58\u6dd8\u6c70\u673a\u5236\u3002\u4f8b\u5982\u5e97\u94fa\u7c7b\u578b\u7684\u67e5\u8be2\u7f13\u5b58\u3002<\/p>\n<p>\u5f53\u6709\u9ad8\u4e00\u81f4\u6027\u9700\u6c42\uff1a\u4f7f\u7528\u4e3b\u52a8\u66f4\u65b0\uff0c\u5e76\u4ee5\u8d85\u65f6\u5254\u9664\u4f5c\u4e3a\u515c\u5e95\u65b9\u6848\u3002\u4f8b\u5982\u5e97\u94fa\u8be6\u60c5\u67e5\u8be2\u7684\u7f13\u5b58<\/p>\n<h3>3.2 \u4e3b\u52a8\u66f4\u65b0\u7b56\u7565<\/h3>\n<p>\u4e0a\u8ff0\u63d0\u5230\u7684\u4e3b\u52a8\u66f4\u65b0\u7b56\u7565\uff0c\u65e0\u7591\u662f\u7ef4\u62a4\u6210\u672c\u6700\u9ad8\u7684\uff0c\u4f46\u5177\u4f53\u53c8\u6709\u54ea\u4e9b\u7ef4\u62a4\u65b9\u5f0f\u5462\uff1f\u600e\u4e48\u53bb\u505a\u4e3b\u52a8\u66f4\u65b0\u7ef4\u62a4\u5462\uff1f<\/p>\n<p>\u5982\u4e0b\u56fe\uff1a\u4e3b\u52a8\u66f4\u65b0\u4e3b\u8981\u5206\u4e3a\u4e0b\u9762\u4e09\u79cd\uff1a<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965163f968b3bd9e3.png\" class=\"aligncenter\"><\/p>\n<p>\u53c8\u56e0\u4e3a\u540e\u4e24\u79cd\u5b9e\u73b0\u65b9\u5f0f\u8fc7\u4e8e\u590d\u6742\uff0c\u6240\u4ee5\u91cd\u70b9\u8bf4\u7b2c\u4e00\u79cd\u3002<\/p>\n<p>\u7b2c\u4e00\u79cd\uff1aCache Aside Pattern\uff0c\u7531\u7f13\u5b58\u8c03\u7528\u8005\u8fdb\u884c\u64cd\u4f5c\uff0c\u5c31\u662f\u5728\u6211\u4eec\u6570\u636e\u5e93\u8fdb\u884c\u66f4\u65b0\u65f6\uff0c\u5bf9\u7f13\u5b58\u4e5f\u8fdb\u884c\u66f4\u65b0\u3002<\/p>\n<p>\u8fd9\u53c8\u5f15\u51fa\u4e86\u597d\u51e0\u4e2a\u95ee\u9898\u4e86~<\/p>\n<p>1. \u7f13\u5b58\u66f4\u65b0\uff1f\u662f\u66f4\u65b0\u7f13\u5b58\u8fd8\u662f\u76f4\u63a5\u5220\u9664\u7f13\u5b58\uff1f<\/p>\n<p>2. \u5982\u4f55\u4fdd\u8bc1\u6570\u636e\u5e93\u66f4\u65b0\u548c\u7f13\u5b58\u66f4\u65b0\u540c\u65f6\u6210\u529f\u6216\u5931\u8d25\uff1f<\/p>\n<p>3. \u64cd\u4f5c\u65f6\u5e94\u8be5\u5148\u64cd\u4f5c\u7f13\u5b58\u8fd8\u662f\u5148\u64cd\u4f5c\u6570\u636e\u5e93\uff1f<\/p>\n<p>\u7b2c\u4e00\u4e2a\u95ee\u9898\uff1a<\/p>\n<p>\u6211\u60f3\u8bf4\uff0c\u7f13\u5b58\u66f4\u65b0\u5982\u679c\u662f\u6570\u636e\u66f4\u65b0\u7684\u8bdd\uff0c\u6bcf\u6b21\u66f4\u65b0\u6570\u636e\u5e93\u90fd\u8981\u5bf9\u7f13\u5b58\u6570\u636e\u8fdb\u884c\u66f4\u65b0\uff0c\u6709\u592a\u591a\u65e0\u6548\u7684\u8bfb\u5199\u64cd\u4f5c\uff0c\u6240\u4ee5\u64cd\u4f5c\u7f13\u5b58\u65f6\uff0c\u9009\u62e9\u5220\u9664\u7f13\u5b58~<\/p>\n<p>\u7b2c\u4e8c\u4e2a\u95ee\u9898\uff1a<\/p>\n<p>\u8981\u505a\u5230\u4e24\u4e2a\u64cd\u4f5c\u4e00\u81f4\u6027\uff0c\u7b2c\u4e00\u60f3\u5230\u7684\u5c31\u5e94\u8be5\u662f\u4e8b\u52a1\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6848\uff1a\u5f53\u6211\u4eec\u662f\u5355\u4f53\u7cfb\u7edf\u65f6\uff0c\u5c06\u7f13\u5b58\u548c\u6570\u636e\u5e93\u64cd\u4f5c\u653e\u5728\u540c\u4e00\u4e2a\u4e8b\u52a1\u91cc\u3002<\/p>\n<p>\u5f53\u6211\u4eec\u662f\u5206\u5e03\u5f0f\u7cfb\u7edf\u65f6\uff0c\u5229\u7528TTC\u7b49\u5206\u5e03\u5f0f\u4e8b\u52a1\u65b9\u6848<\/p>\n<p>\u6700\u540e\u4e00\u4e2a\u95ee\u9898\uff1a\u5148\u64cd\u4f5c\u6570\u636e\u5e93\u8fd8\u662f\u5148\u64cd\u4f5c\u7f13\u5b58\uff1f<\/p>\n<p>\u5c31\u53ea\u6709\u4e0b\u9762\u4e24\u79cd\u60c5\u51b5\uff1a<\/p>\n<p>1.\u5148\u5220\u9664\u7f13\u5b58\uff0c\u518d\u64cd\u4f5c\u6570\u636e\u5e93<\/p>\n<p>2.\u5148\u64cd\u4f5c\u6570\u636e\u5e93\uff0c\u518d\u5220\u9664\u7f13\u5b58<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4e24\u79cd\u60c5\u51b5\u90fd\u6765\u770b\u770b~<\/p>\n<p>\u7b2c\u4e00\u79cd\u60c5\u51b5\uff0c\u5148\u5220\u9664\u7f13\u5b58\u7684\u60c5\u51b5\uff0c\u6211\u4eec\u60f3\u7684\u6b63\u5e38\u7684\u4e0d\u4f1a\u51fa\u73b0\u95ee\u9898\u7684\u64cd\u4f5c\u6d41\u7a0b\uff08\u5de6\u8fb9\uff09\u548c\u64cd\u4f5c\u4f1a\u51fa\u73b0\u95ee\u9898\u7684\u6d41\u7a0b\uff08\u53f3\u8fb9\uff09<\/p>\n<p>\u8865\u5145\u4e00\u4e0b\uff1a\u8fd9\u8fb9\u4e24\u4e2a\u7ebf\u7a0b\u6700\u521d\u7684\u6570\u636e\u5e93\u548c\u7f13\u5b58\u6570\u636e\u90fd\u5047\u5b9a\u4e3a10~<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965263f968b41cb4d.png\" class=\"aligncenter\"><\/p>\n<p>\u51fa\u73b0\u95ee\u9898\u7684\u60c5\u51b5\u4e3a\u6211\u4eec\u7ebf\u7a0b1\u5148\u5220\u9664\u7f13\u5b58\uff0c\u7ebf\u7a0b2\u672a\u547d\u4e2d\u7f13\u5b58\uff0c\u76f4\u63a5\u67e5\u5230\u6570\u636e\u5e93\u4e2d\u6570\u636e\u4e3a10\u5e76\u5199\u5165\u7f13\u5b58\u4e2d\uff0c\u800c\u7ebf\u7a0b1\u5728\u7ebf\u7a0b2\u540e\u5199\u5165\u7f13\u5b58\u540e\uff0c\u628a\u6570\u636e\u5e93\u66f4\u65b0\u6210\u4e8620\uff0c\u8fd9\u6837\u6700\u540e\u6570\u636e\u5e93\u6570\u636e\u4e3a20\uff0c\u800c\u7f13\u5b58\u4e2d\u7684\u6570\u636e\u4e3a10\uff0c\u8fd9\u5c31\u5bfc\u81f4\u6570\u636e\u4e0d\u4e00\u81f4\u4e86\u3002<\/p>\n<p>2.\u5148\u64cd\u4f5c\u6570\u636e\u5e93\u7684\u60c5\u51b5<\/p>\n<p>\u6b63\u786e\u60c5\u51b5\uff08\u5de6\u8fb9\uff09\u9519\u8bef\u60c5\u51b5\uff08\u53f3\u8fb9\uff09\uff0c\u6570\u636e\u5e93\u548c\u7f13\u5b58\u6700\u521d\u6570\u636e\u4e5f\u90fd\u8fd8\u662f10~<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965263f968b47de3f.png\" class=\"aligncenter\"><\/p>\n<p>\u7b2c\u4e8c\u79cd\u5148\u64cd\u4f5c\u6570\u636e\u5e93\u7684\u65b9\u5f0f\uff0c\u5b83\u51fa\u73b0\u7684\u9519\u8bef\u60c5\u51b5\u4e3b\u8981\u662f\uff0c\u7ebf\u7a0b1\u7ebf\u7a0b\u67e5\u8be2\u4e86\u7f13\u5b58\uff0c\u672a\u547d\u4e2d\u540e\u53bb\u67e5\u8be2\u6570\u636e\u5e93\u7684\u540c\u65f6\uff0c\u7ebf\u7a0b2\u66f4\u65b0\u4e86\u6570\u636e\u5e93\uff0c\u5e76\u4e14\u5220\u9664\u4e86\u7f13\u5b58\uff0c\u7136\u540e\u7ebf\u7a0b1\u624d\u628a\u6570\u636e\u5e93\u4e2d\u67e5\u51fa\u6765\u768410\u5199\u5165\u7f13\u5b58\uff0c\u5bfc\u81f4\u7f13\u5b58\u4e3a10\uff0c\u6570\u636e\u5e93\u4e3a20\u3002<\/p>\n<p>\u7ec8\u4e0a\u6240\u8ff0\uff0c\u7b2c\u4e00\u79cd\u5931\u8d25\u7684\u60c5\u51b5\u662f\u6bd4\u7b2c\u4e8c\u79cd\u5931\u8d25\u7684\u60c5\u51b5\u591a\u7684\uff0c\u56e0\u4e3a\u7b2c\u4e00\u79cd\u60c5\u51b5\u51fa\u73b0\u9519\u8bef\u7684\u65f6\u95f4\u662f\u5728\u5220\u9664\u7f13\u5b58\u5e76\u66f4\u65b0\u6570\u636e\u5e93\u540e\uff0c\u7ebf\u7a0b2\u6709\u7740\u5145\u8db3\u7684\u65f6\u95f4\u5728\u8fd9\u6bb5\u65f6\u95f4\u5185\u5199\u5165\u7f13\u5b58\uff0c\u800c\u5bf9\u4e8e\u7b2c\u4e8c\u79cd\u60c5\u51b5\u6765\u8bf4\uff0c\u51fa\u73b0\u95ee\u9898\u53d1\u751f\u5728\u67e5\u5b8c\u6570\u636e\u5e93\u5230\u5199\u5165\u7f13\u5b58\u8fd9\u6bb5\u65f6\u95f4\u5185\uff0c\u8fd9\u6bb5\u65f6\u95f4\u51e0\u4e4e\u662f\u6beb\u79d2\u7ea7\u522b\u7684\uff0c\u7ebf\u7a0b2\u5728\u8fd9\u6bb5\u65f6\u95f4\u5185\u66f4\u65b0\u6570\u636e\u5e93\u5e76\u5220\u9664\u7f13\u5b58\uff0c\u663e\u7136\u51e0\u7387\u662f\u5f88\u4f4e\u7684\uff08\u9664\u4e86\u9ad8\u9ad8\u9ad8\u5e76\u53d1\u7684\u72b6\u51b5\u4e0b\uff09\uff0c\u6240\u4ee5\u6211\u4eec\u9009\u62e9\u5148\u64cd\u4f5c\u6570\u636e\u5e93\u5728\u64cd\u4f5c\u7f13\u5b58~<\/p>\n<p>\u603b\u7ed3\uff1a<\/p>\n<p>\u7f13\u5b58\u66f4\u65b0\u7b56\u7565\u7684\u6700\u4f73\u5b9e\u8df5\u65b9\u6848\uff1a<\/p>\n<p>1.\u4f4e\u4e00\u81f4\u6027\u9700\u6c42\uff1a\u4f7f\u7528Redis\u81ea\u5e26\u7684\u5185\u5b58\u6dd8\u6c70\u673a\u5236<\/p>\n<p>2.\u9ad8\u4e00\u81f4\u6027\u9700\u6c42\uff1a\u4e3b\u52a8\u66f4\u65b0\uff0c\u5e76\u4ee5\u8d85\u65f6\u5254\u9664\u4f5c\u4e3a\u515c\u5e95\u65b9\u6848<\/p>\n<p>\u4e3b\u52a8\u66f4\u65b0\u65f6<\/p>\n<p>\u8fdb\u884c\u8bfb\u64cd\u4f5c\uff1a<\/p>\n<ul>\n<li>\u7f13\u5b58\u547d\u4e2d\u5219\u76f4\u63a5\u8fd4\u56de<\/li>\n<li>\u7f13\u5b58\u672a\u547d\u4e2d\u5219\u67e5\u8be2\u6570\u636e\u5e93\uff0c\u5e76\u5199\u5165\u7f13\u5b58\uff0c\u8bbe\u5b9a\u8d85\u65f6\u65f6\u95f4<\/li>\n<\/ul>\n<p>\u8fdb\u884c\u5199\u64cd\u4f5c\uff1a<\/p>\n<ul>\n<li>\u5148\u5199\u6570\u636e\u5e93\uff0c\u7136\u540e\u518d\u5220\u9664\u7f13\u5b58<\/li>\n<li>\u8981\u786e\u4fdd\u6570\u636e\u5e93\u4e0e\u7f13\u5b58\u64cd\u4f5c\u7684\u539f\u5b50\u6027<\/li>\n<\/ul>\n<h3>3.3 \u4e3b\u52a8\u66f4\u65b0\u7b56\u7565\u7ec3\u4e60<\/h3>\n<p>\u4fee\u6539\u5546\u54c1\u7f13\u5b58<\/p>\n<p>1. \u6839\u636eid\u67e5\u8be2\u5e97\u94fa\u65f6\uff0c\u5982\u679c\u7f13\u5b58\u672a\u547d\u4e2d\uff0c\u5219\u67e5\u8be2\u6570\u636e\u5e93\uff0c\u5c06\u6570\u636e\u5e93\u7ed3\u679c\u5199\u5165\u7f13\u5b58\uff0c\u5e76\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4<\/p>\n<p>2. \u6839\u636eid\u4fee\u6539\u5e97\u94fa\u65f6\uff0c\u5148\u4fee\u6539\u6570\u636e\u5e93\uff0c\u518d\u5220\u9664\u7f13\u5b58<\/p>\n<p>\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\uff08Service\u5c42\u5b9e\u73b0\uff09\uff1a<\/p>\n<pre>package com.hmdp.service.impl;\nimport cn.hutool.core.util.StrUtil;\nimport cn.hutool.json.JSONUtil;\nimport com.hmdp.dto.Result;\nimport com.hmdp.entity.Shop;\nimport com.hmdp.mapper.ShopMapper;\nimport com.hmdp.service.IShopService;\nimport com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;\nimport org.springframework.data.redis.core.StringRedisTemplate;\nimport org.springframework.stereotype.Service;\nimport org.springframework.transaction.annotation.Transactional;\nimport javax.annotation.Resource;\nimport java.util.concurrent.TimeUnit;\nimport static com.hmdp.utils.RedisConstants.CACHE_SHOP_KEY;\nimport static com.hmdp.utils.RedisConstants.CACHE_SHOP_TTL;\n\/**\n * <p>\n *  \u670d\u52a1\u5b9e\u73b0\u7c7b\n * <\/p>\n *\n * @author \u864e\u54e5\n * @since 2021-12-22\n *\/\n@Service\npublic class ShopServiceImpl extends ServiceImpl\n   \n     implements IShopService {\n    @Resource\n    private StringRedisTemplate stringRedisTemplate;\n    @Override\n    public Result queryShopById(Long id) {\n        \/\/1.\u53bbredis\u4e2d\u67e5\u8be2\u5546\u54c1\u662f\u5426\u5b58\u5728\n        String key = CACHE_SHOP_KEY+id;\n        String shopJson = stringRedisTemplate.opsForValue().get(key);\n        if (StrUtil.isNotBlank(shopJson)){\n            \/\/2.\u5b58\u5728\uff0c\u76f4\u63a5\u8fd4\u56de\u7ed9\u7528\u6237\n            Shop shop = JSONUtil.toBean(shopJson, Shop.class);\n            return Result.ok(shop);\n        }\n        \/\/3.\u4e0d\u5b58\u5728\uff0c\u5e26\u7740id\u53bb\u6570\u636e\u5e93\u67e5\u8be2\u662f\u5426\u5b58\u5728\u5546\u54c1\n        Shop shop = getById(id);\n        if (shop == null){\n            \/\/4.\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\n            Result.fail(\"\u5546\u54c1\u4fe1\u606f\u4e0d\u5b58\u5728\uff01\");\n        }\n        \/\/5.\u5b58\u5728\uff0c\u5b58\u5165redis(\u5e76\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4)\n        stringRedisTemplate.opsForValue().set(key,JSONUtil.toJsonStr(shop),CACHE_SHOP_TTL, TimeUnit.MINUTES);\n        \/\/6.\u8fd4\u56de\u5546\u54c1\u4fe1\u606f\n        return Result.ok(shop);\n    }\n    @Override\n    @Transactional\n    public Result updateShop(Shop shop) {\n        \/\/1.\u5148\u66f4\u65b0\u6570\u636e\u5e93\n        updateById(shop);\n        \/\/2.\u5220\u9664redis\u7f13\u5b58\n        String key = CACHE_SHOP_KEY+shop.getId();\n        stringRedisTemplate.delete(key);\n        return null;\n    }\n}\n   <\/pre>\n<p>\u8fd9\u6837\u5c31\u80fd\u8fbe\u5230\u57fa\u672c\u7684\u4e3b\u52a8\u7f13\u5b58\u66f4\u65b0\u5566~<\/p>\n<h2>4 \u7f13\u5b58\u7a7f\u900f\u53ca\u5176\u89e3\u51b3\u65b9\u6848<\/h2>\n<h3>4.1 \u7f13\u5b58\u7a7f\u900f\u7684\u6982\u5ff5<\/h3>\n<p>\u7f13\u5b58\u7a7f\u900f\u662f\u6307\u5ba2\u6237\u7aef\u8bf7\u6c42\u7684\u6570\u636e\u5728\u7f13\u5b58\u4e2d\u548c\u6570\u636e\u5e93\u4e2d\u90fd\u4e0d\u5b58\u5728\uff0c\u8fd9\u6837\u7f13\u5b58\u6c38\u8fdc\u4e0d\u4f1a\u751f\u6548\uff0c\u8fd9\u4e9b\u8bf7\u6c42\u90fd\u4f1a\u6253\u5230\u6570\u636e\u5e93\u3002<\/p>\n<p>\u901a\u4fd7\u7684\u8bf4\uff0c\u5c31\u662f\u8bf7\u6c42\u7684\u6570\u636e\u5728\u6570\u636e\u5e93\u548c\u7f13\u5b58\u4e2d\u90fd\u6ca1\u6709\uff0c\u6700\u540e\u8bf7\u6c42\u90fd\u5230\u4e86\u6570\u636e\u5e93\u3002\u8fd9\u4e2a\u65f6\u5019\uff0c\u5982\u679c\u6709\u4e00\u4e2a\u6076\u610f\u7684\u7a0b\u5e8f\u5458\uff0c\u901a\u8fc7\u67d0\u79cd\u65b9\u5f0f\u4e0d\u65ad\u8bf7\u6c42\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684\u6570\u636e\uff0c\u8fd9\u6837\u5c31\u4f1a\u7ed9\u6570\u636e\u5e93\u5e26\u6765\u5de8\u5927\u7684\u538b\u529b\u3002\uff08\u5c31\u6015\u7528\u6237\u61c2\u4ee3\u7801\uff09<\/p>\n<h3>4.2 \u89e3\u51b3\u65b9\u6848\u53ca\u5b9e\u73b0<\/h3>\n<p>\u5e38\u89c1\u7684\u7f13\u5b58\u7a7f\u900f\u7684\u89e3\u51b3\u65b9\u6848\u6709\u4e24\u79cd\uff1a<\/p>\n<p>1.\u5c31\u662f\u7ed9redis\u7f13\u5b58\u4e00\u4e2a\u7a7a\u5bf9\u8c61\u5e76\u8bbe\u7f6eTTL\u5b58\u6d3b\u65f6\u95f4<\/p>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u4f18\u70b9\u5728\u4e8e\u5b9e\u73b0\u7b80\u5355\uff0c\u7ef4\u62a4\u65b9\u4fbf\uff0c\u4f46\u4e5f\u5e26\u6765\u4e86\u989d\u5916\u7684\u5185\u5b58\u6d88\u8017\u548c\u53ef\u80fd\u7684\u77ed\u671f\u7684\u6570\u636e\u4e0d\u4e00\u81f4\u3002<\/p>\n<p>\u5c0f\u77e5\u8bc6\uff1a\u8fd9\u91cc\u7684\u6570\u636e\u4e0d\u4e00\u81f4\u53d1\u751f\u5728\u7528\u6237\u521a\u4eceredis\u4e2d\u62ff\u5230null\u503c\u6070\u597d\u6570\u636e\u63d2\u5165\u4e86\u8fd9\u4e2a\u8bf7\u6c42\u9700\u8981\u7684\u503c\u800c\u5bfc\u81f4\u7684\u6570\u636e\u5e93Redis\u6570\u636e\u4e0d\u4e00\u81f4\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965263f968b4d11ef.png\" class=\"aligncenter\"><\/p>\n<p>2. \u5c31\u662f\u5229\u7528\u5e03\u9686\u8fc7\u6ee4<\/p>\n<p>\u901a\u4fd7\u7684\u8bf4\uff0c\u5c31\u662f\u4e2d\u95f4\u4ef6~<\/p>\n<p>\u8fd9\u79cd\u65b9\u5f0f \u4f18\u70b9\u5728\u4e8e\u5185\u5b58\u6d88\u8017\u8f83\u5c0f\uff0c\u6ca1\u6709\u591a\u4f59\u7684key\uff0c\u7f3a\u70b9\u5c31\u5728\u4e8e\u5b9e\u73b0\u590d\u6742\uff0c\u800c\u4e14\u5e03\u9686\u8fc7\u6ee4\u5668\u6709\u8bef\u5224\u7684\u53ef\u80fd&#8230;<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965363f968b542a7e.png\" class=\"aligncenter\"><\/p>\n<p>\u4ee3\u7801\u5b9e\u73b0\uff1a\u8fd9\u91cc\u5b9e\u73b0\u7b2c\u4e00\u79cd<\/p>\n<p>\u5c31\u62ff\u4e0a\u8ff0\u7684\u5199\u5165\u5546\u54c1\u4fe1\u606f\u4e3a\u4f8b\uff1a<\/p>\n<p>\u6211\u4eec\u53ea\u9700\u8981\u5728\u6570\u636e\u5e93\u83b7\u53d6\u6570\u636e\u65f6\uff0c\u5982\u679c\u53d6\u5230\u7a7a\u503c\uff0c\u4e0d\u76f4\u63a5\u8fd4\u56de404\uff0c\u800c\u662f\u5c06\u7a7a\u503c\u4e5f\u5b58\u5165redis\u4e2d\uff0c\u5e76\u4e14\u5728\u5224\u65ad\u7f13\u5b58\u662f\u5426\u547d\u4e2d\u65f6\uff0c\u5224\u65ad\u547d\u4e2d\u7684\u503c\u662f\u4e0d\u662f\u6211\u4eec\u4f20\u5165\u7684\u7a7a\u503c\u3002\u5982\u679c\u662f\uff0c\u76f4\u63a5\u7ed3\u675f\uff0c\u4e0d\u662f\u5c31\u8fd4\u56de\u5546\u94fa\u4fe1\u606f<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965363f968b5ada5f.png\" class=\"aligncenter\"><\/p>\n<pre>package com.hmdp.service.impl;\nimport cn.hutool.core.util.StrUtil;\nimport cn.hutool.json.JSONUtil;\nimport com.hmdp.dto.Result;\nimport com.hmdp.entity.Shop;\nimport com.hmdp.mapper.ShopMapper;\nimport com.hmdp.service.IShopService;\nimport com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;\nimport org.springframework.data.redis.core.StringRedisTemplate;\nimport org.springframework.stereotype.Service;\nimport org.springframework.transaction.annotation.Transactional;\nimport javax.annotation.Resource;\nimport java.util.concurrent.TimeUnit;\nimport static com.hmdp.utils.RedisConstants.*;\n\/**\n * <p>\n *  \u670d\u52a1\u5b9e\u73b0\u7c7b\n * <\/p>\n *\n * @author \u864e\u54e5\n * @since 2021-12-22\n *\/\n@Service\npublic class ShopServiceImpl extends ServiceImpl\n   \n     implements IShopService {\n    @Resource\n    private StringRedisTemplate stringRedisTemplate;\n    @Override\n    public Result queryShopById(Long id) {\n        \/\/1.\u53bbredis\u4e2d\u67e5\u8be2\u5546\u54c1\u662f\u5426\u5b58\u5728\n        String key = CACHE_SHOP_KEY+id;\n        String shopJson = stringRedisTemplate.opsForValue().get(key);\n        if (StrUtil.isNotBlank(shopJson)){\n            \/\/2.\u5b58\u5728\uff0c\u76f4\u63a5\u8fd4\u56de\u7ed9\u7528\u6237\n            Shop shop = JSONUtil.toBean(shopJson, Shop.class);\n            return Result.ok(shop);\n        }\n        \/\/\u5224\u65ad\u547d\u4e2d\u7684\u662f\u5426\u4e3a\u7a7a\u5b57\u7b26\u4e32\n        \/**\n         * (\u8fd9\u91cc\u91cd\u70b9\u8bb2\u4e00\u4e0b\u4e3a\u4ec0\u4e48\u662f\u4e0d\u7b49\u4e8e\uff1a\u56e0\u4e3a\u6211\u4eec\u83b7\u53d6\u5230\u7684shopJson\u4e3anull\u662f\uff0c\u4e0a\u9762\u7684isNotBlank\u65b9\u6cd5\u4f1a\u8fd4\u56defalse\uff0c\u5bfc\u81f4\u6210\u4e3a\u4e86\u4e0d\u547d\u4e2d\u7684\u6548\u679c)\n         *\/\n        if (shopJson != null){\n            return Result.fail(\"\u5546\u54c1\u4fe1\u606f\u4e0d\u5b58\u5728\uff01\");\n        }\n        \/\/3.\u4e0d\u5b58\u5728\uff0c\u5e26\u7740id\u53bb\u6570\u636e\u5e93\u67e5\u8be2\u662f\u5426\u5b58\u5728\u5546\u54c1\n        Shop shop = getById(id);\n        if (shop == null){\n            \/\/ 4.\u5c06\u7a7a\u503c\u5b58\u5165redis\n            stringRedisTemplate.opsForValue().set(key,\"\",CACHE_NULL_TTL,TimeUnit.MINUTES);\n            \/\/5.\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\n            Result.fail(\"\u5546\u54c1\u4fe1\u606f\u4e0d\u5b58\u5728\uff01\");\n        }\n        \/\/6.\u5b58\u5728\uff0c\u5b58\u5165redis(\u5e76\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4)\n        stringRedisTemplate.opsForValue().set(key,JSONUtil.toJsonStr(shop),CACHE_SHOP_TTL, TimeUnit.MINUTES);\n        \/\/7.\u8fd4\u56de\u5546\u54c1\u4fe1\u606f\n        return Result.ok(shop);\n    }\n}\n   <\/pre>\n<p>\u603b\u7ed3\uff1a<\/p>\n<p>\u7f13\u5b58\u7a7f\u900f\u4ea7\u751f\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f<\/p>\n<p>\u7528\u6237\u8bf7\u6c42\u7684\u6570\u636e\u5728\u7f13\u5b58\u4e2d\u548c\u6570\u636e\u5e93\u4e2d\u90fd\u4e0d\u5b58\u5728\uff0c\u4e0d\u65ad\u53d1\u8d77\u8fd9\u6837\u7684\u8bf7\u6c42\uff0c\u7ed9\u6570\u636e\u5e93\u5e26\u6765\u5de8\u5927\u538b\u529b\u3002<\/p>\n<p>\u7f13\u5b58\u7a7f\u900f\u7684\u89e3\u51b3\u65b9\u6848\u6709\u54ea\u4e9b\uff1f\uff083-6\u70b9\u4e3a\u6269\u5c55~\uff09<\/p>\n<p>1.\u7f13\u5b58null\u503c<\/p>\n<p>2.\u5e03\u9686\u8fc7\u6ee4<\/p>\n<p>3.\u589e\u5f3aid\u7684\u590d\u6742\u5ea6\uff0c\u907f\u514d\u88ab\u731c\u6d4bid\u89c4\u5f8b<\/p>\n<p>4.\u505a\u597d\u6570\u636e\u7684\u57fa\u7840\u683c\u5f0f\u6821\u9a8c<\/p>\n<p>5.\u52a0\u5f3a\u7528\u6237\u6743\u9650\u6821\u9a8c<\/p>\n<p>6.\u505a\u597d\u70ed\u70b9\u53c2\u6570\u7684\u9650\u6d41<\/p>\n<h2>5 \u7f13\u5b58\u96ea\u5d29\u7684\u6982\u5ff5\u53ca\u5176\u89e3\u51b3\u65b9\u6848<\/h2>\n<p>\u7f13\u5b58\u96ea\u5d29\u662f\u6307\u5728\u540c\u4e00\u65f6\u6bb5\u5927\u91cf\u7684\u7f13\u5b58key\u540c\u65f6\u5931\u6548\u6216\u8005Redis\u670d\u52a1\u5b95\u673a\uff0c\u5bfc\u81f4\u5927\u91cf\u8bf7\u6c42\u5230\u8fbe\u6570\u636e\u5e93\uff0c\u5e26\u6765\u5de8\u5927\u538b\u529b\u3002<\/p>\n<p>\u5c31\u662f\u8bf4\uff0c\u4e00\u7fa4\u8bbe\u7f6e\u4e86\u6709\u6548\u671f\u7684key\u540c\u65f6\u6d88\u5931\u4e86\uff0c\u6216\u8005\u8bf4redis\u7f62\u5de5\u4e86\uff0c\u5bfc\u81f4\u6240\u6709\u7684\u6216\u8005\u8bf4\u5927\u91cf\u7684\u8bf7\u6c42\u4f1a\u7ed9\u6570\u636e\u5e93\u5e26\u6765\u5de8\u5927\u538b\u529b\u53eb\u505a\u7f13\u5b58\u96ea\u5d29~<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965463f968b634d12.png\" class=\"aligncenter\"><\/p>\n<p>\u89e3\u51b3\u65b9\u5f0f\u4e5f\u6bd4\u8f83\u7684\u7b80\u5355~<\/p>\n<p>1. \u7ed9\u4e0d\u540c\u7684key\u6dfb\u52a0\u968f\u673a\u7684TTL\u5b58\u6d3b\u65f6\u95f4\uff08\u8fd9\u79cd\u5c31\u662f\u6700\u7b80\u5355\u7684\uff0c\u8bbe\u7f6e\u5b58\u8d27\u65f6\u95f4\u968f\u673a\u5404\u4e0d\u76f8\u540c\uff09<\/p>\n<p>2. \u5229\u7528Redis\u96c6\u7fa4\uff08\u8fd9\u79cd\u9488\u5bf9\u4e0eRedis\u51fa\u73b0\u5b95\u673a\u7684\u60c5\u51b5\uff09<\/p>\n<p>3. \u7ed9\u7f13\u5b58\u4e1a\u52a1\u6dfb\u52a0\u964d\u7ea7\u9650\u6d41\u7b56\u7565\uff08SpringCloud\u77e5\u8bc6\u70b9\uff09<\/p>\n<p>4. \u7ed9\u4e1a\u52a1\u6dfb\u52a0\u591a\u7ea7\u7f13\u5b58<\/p>\n<h2>6 \u7f13\u5b58\u51fb\u7a7f\u53ca\u89e3\u51b3\u65b9\u6848<\/h2>\n<h3>6.1 \u4ec0\u4e48\u662f\u7f13\u5b58\u51fb\u7a7f<\/h3>\n<p>\u7f13\u5b58\u51fb\u7a7f\u95ee\u9898\u4e5f\u53eb\u70ed\u70b9Key\u95ee\u9898\uff0c\u5c31\u662f\u4e00\u4e2a\u88ab\u9ad8\u5e76\u53d1\u8bbf\u95ee\u5e76\u4e14\u7f13\u5b58\u91cd\u5efa\u4e1a\u52a1\u8f83\u590d\u6742\u7684key\u7a81\u7136\u5931\u6548\u4e86\uff0c\u65e0\u6570\u7684\u8bf7\u6c42\u8bbf\u95ee\u4f1a\u5728\u77ac\u95f4\u7ed9\u6570\u636e\u5e93\u5e26\u6765\u5de8\u5927\u7684\u51b2\u51fb\u3002<\/p>\n<p>\u5927\u6982\u7684\u5954\u6e83\u6d41\u7a0b\u662f\u8fd9\u6837\u5b50\u7684\uff1a<\/p>\n<p>\u7b2c\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u67e5\u8be2redis\u53d1\u73b0\u672a\u547d\u4e2d\uff0c\u7136\u540e\u53bb\u6570\u636e\u5e93\u67e5\u8be2\u5e76\u91cd\u5efa\u7f13\u5b58\uff0c\u8fd9\u4e2a\u65f6\u5019\u56e0\u4e3a\u5728\u7f13\u5b58\u91cd\u5efa\u4e1a\u52a1\u8f83\u4e3a\u590d\u6742\u7684\u60c5\u51b5\u4e0b\uff0c\u91cd\u5efa\u65f6\u95f4\u8f83\u4e45\uff0c\u53c8\u56e0\u4e3a\u9ad8\u5e76\u53d1\u7684\u73af\u5883\u4e0b\uff0c\u5728\u7ebf\u7a0b1\u91cd\u5efa\u7f13\u5b58\u7684\u65f6\u95f4\u5185\uff0c\u4f1a\u6709\u5176\u4ed6\u7684\u5927\u91cf\u7684\u5176\u4ed6\u7ebf\u7a0b\u8fdb\u6765\uff0c\u53d1\u73b0\u67e5\u627e\u7f13\u5b58\u4ecd\u672a\u547d\u4e2d\uff0c\u5bfc\u81f4\u7ee7\u7eed\u91cd\u5efa\uff0c\u5982\u6b64\u6b7b\u5faa\u73af\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965463f968b692133.png\" class=\"aligncenter\"><\/p>\n<h3>6.2 \u7f13\u5b58\u51fb\u7a7f\u89e3\u51b3\u65b9\u6cd5<\/h3>\n<p>\u5e38\u89c1\u7684\u89e3\u51b3\u65b9\u6848\u6709\u4e24\u79cd\uff1a<\/p>\n<h4>6.2.1 \u4e92\u65a5\u9501<\/h4>\n<p>\u4e92\u65a5\u9501\u7684\u89e3\u51b3\u65b9\u6848\u5982\u4e0b\uff1a<\/p>\n<p>\u5c31\u662f\u5f53\u7ebf\u7a0b\u67e5\u8be2\u7f13\u5b58\u672a\u547d\u4e2d\u65f6\uff0c\u5c1d\u8bd5\u53bb\u83b7\u53d6\u4e92\u65a5\u9501\uff0c\u7136\u540e\u5728\u91cd\u5efa\u7f13\u5b58\u6570\u636e\uff0c\u5728\u8fd9\u6bb5\u65f6\u95f4\u91cc\uff0c\u5176\u4ed6\u7ebf\u7a0b\u4e5f\u4f1a\u53bb\u5c1d\u8bd5\u83b7\u53d6\u4e92\u65a5\u9501\uff0c\u5982\u679c\u5931\u8d25\u5c31\u4f11\u7720\u4e00\u6bb5\u65f6\u95f4\uff0c\u5e76\u7ee7\u7eed\uff0c\u4e0d\u65ad\u91cd\u8bd5\uff0c\u7b49\u5230\u6570\u636e\u91cd\u5efa\u6210\u529f\uff0c\u5176\u4ed6\u7ebf\u7a0b\u5c31\u53ef\u4ee5\u547d\u4e2d\u6570\u636e\u4e86\u3002\u8fd9\u6837\u5c31\u4e0d\u4f1a\u5bfc\u81f4\u7f13\u5b58\u51fb\u7a7f\u3002\u8fd9\u4e2a\u65b9\u6848\u6570\u636e\u4e00\u81f4\u6027\u662f\u7edd\u5bf9\u7684\uff0c\u4f46\u662f\u76f8\u5bf9\u6765\u8bf4\u4f1a\u727a\u7272\u6027\u80fd\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965463f968b6ebfab.png\" class=\"aligncenter\"><\/p>\n<p>\u5b9e\u73b0\u65b9\u6cd5\uff1a<\/p>\n<p>1.\u83b7\u53d6\u4e92\u65a5\u9501\u548c\u91ca\u653e\u9501\u7684\u5b9e\u73b0\uff1a<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u83b7\u53d6\u4e92\u65a5\u9501\u53ef\u4ee5\u4f7f\u7528redis\u4e2dstring\u7c7b\u578b\u4e2d\u7684setnx\u65b9\u6cd5 \uff0c\u56e0\u4e3asetnx\u65b9\u6cd5\u662f\u5728key\u4e0d\u5b58\u5728\u7684\u60c5\u51b5\u4e0b\u624d\u53ef\u4ee5\u521b\u5efa\u6210\u529f\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u91cd\u5efa\u7f13\u5b58\u65f6\uff0c\u4f7f\u7528setnx\u6765\u5c06\u9501\u7684\u6570\u636e\u52a0\u5165\u5230redis\u4e2d\uff0c\u5e76\u4e14\u901a\u8fc7\u5224\u65ad\u8fd9\u4e2a\u9501\u7684key\u662f\u5426\u5b58\u5728\uff0c\u5982\u679c\u5b58\u5728\u5c31\u662f\u83b7\u53d6\u9501\u6210\u529f\uff0c\u5931\u8d25\u5c31\u662f\u83b7\u53d6\u5931\u8d25\uff0c\u8fd9\u6837\u521a\u597d\u53ef\u4ee5\u5b9e\u73b0\u4e92\u65a5\u9501\u7684\u6548\u679c\u3002<\/p>\n<p>\u800c\u91ca\u653e\u9501\u5c31\u66f4\u7b80\u5355\u4e86\uff0c\u76f4\u63a5\u5220\u9664\u6211\u4eec\u5b58\u5165\u7684\u9501\u7684key\u6765\u91ca\u653e\u9501\u3002<\/p>\n<pre>    \/\/\u83b7\u53d6\u9501\n    public Boolean tryLock(String key){\n        Boolean flag = stringRedisTemplate.opsForValue().setIfAbsent(key, \"1\", 10, TimeUnit.SECONDS);\n        return BooleanUtil.isTrue(flag);\n    }\n    \/\/\u91ca\u653e\u9501\u65b9\u6cd5\n    public void unlock(String key){\n        stringRedisTemplate.delete(key);\n    }<\/pre>\n<p>2.\u5b9e\u73b0\u4ee3\u7801\uff1a<\/p>\n<p>\u5177\u4f53\u64cd\u4f5c\u6d41\u7a0b\u5982\u4e0b\u56fe\uff1a<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965563f968b74d124.png\" class=\"aligncenter\"><\/p>\n<p>\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>package com.hmdp.service.impl;\nimport cn.hutool.core.util.BooleanUtil;\nimport cn.hutool.core.util.StrUtil;\nimport cn.hutool.json.JSONObject;\nimport cn.hutool.json.JSONUtil;\nimport com.hmdp.dto.Result;\nimport com.hmdp.entity.Shop;\nimport com.hmdp.mapper.ShopMapper;\nimport com.hmdp.service.IShopService;\nimport com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;\nimport com.hmdp.utils.RedisData;\nimport org.springframework.data.redis.core.StringRedisTemplate;\nimport org.springframework.stereotype.Service;\nimport org.springframework.transaction.annotation.Transactional;\nimport javax.annotation.Resource;\nimport java.time.LocalDateTime;\nimport java.util.concurrent.Executor;\nimport java.util.concurrent.ExecutorService;\nimport java.util.concurrent.Executors;\nimport java.util.concurrent.TimeUnit;\nimport static com.hmdp.utils.RedisConstants.*;\n\/**\n * <p>\n *  \u670d\u52a1\u5b9e\u73b0\u7c7b\n * <\/p>\n *\/\n@Service\npublic class ShopServiceImpl extends ServiceImpl\n   \n     implements IShopService {\n    @Resource\n    private StringRedisTemplate stringRedisTemplate;\n    @Override\n    public Result queryShopById(Long id) {\n        \/\/\u4e92\u65a5\u9501\u7f13\u5b58\u51fb\u7a7f\n        Shop shop = queryWithMutex(id);\n        if (shop == null){\n            Result.fail(\"\u5546\u54c1\u4fe1\u606f\u4e0d\u5b58\u5728!\");\n        }\n        \/\/8.\u8fd4\u56de\u5546\u54c1\u4fe1\u606f\n        return Result.ok(shop);\n    }\n    \/\/ \u7f13\u5b58\u7a7f\u900f\u89e3\u51b3\u2014\u2014\u4e92\u65a5\u9501\n    public Shop queryWithMutex(Long id){\n        \/\/1.\u53bbredis\u4e2d\u67e5\u8be2\u5546\u54c1\u662f\u5426\u5b58\u5728\n        String key = CACHE_SHOP_KEY+id;\n        String shopJson = stringRedisTemplate.opsForValue().get(key);\n        if (StrUtil.isNotBlank(shopJson)){\n            \/\/2.\u5b58\u5728\uff0c\u76f4\u63a5\u8fd4\u56de\u7ed9\u7528\u6237\n            Shop shop = JSONUtil.toBean(shopJson, Shop.class);\n            return shop;\n        }\n        \/\/\u5224\u65ad\u547d\u4e2d\u7684\u662f\u5426\u4e3a\u7a7a\u5b57\u7b26\u4e32\n        if (shopJson != null){\n            return null;\n        }\n        Shop shop = null;\n        String lockKey = LOCK_SHOP_KEY+id;\n        try {\n            \/\/3.\u7f13\u5b58\u91cd\u5efa\n            \/\/3.1\u5c1d\u8bd5\u83b7\u53d6\u9501\n            Boolean isLock = tryLock(lockKey);\n            \/\/3.2\u5224\u65ad\u83b7\u53d6\u9501\u662f\u5426\u6210\u529f\uff0c\u5982\u679c\u4f11\u7720\u91cd\u8bd5\n            if (!isLock){\n                \/\/\u4f11\u7720\n                Thread.sleep(50);\n                \/\/\u91cd\u8bd5\u7528\u9012\u5f52\n                queryWithMutex(id);\n            }\n            \/\/3.3\u5982\u679c\u6210\u529f\uff0c\u53bb\u6570\u636e\u5e93\u67e5\u627e\u6570\u636e\n            shop = getById(id);\n            if (shop == null){\n                \/\/ 4.\u5c06\u7a7a\u503c\u5b58\u5165redis\n                stringRedisTemplate.opsForValue().set(key,\"\",CACHE_NULL_TTL,TimeUnit.MINUTES);\n                \/\/5.\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\n                Result.fail(\"\u5546\u54c1\u4fe1\u606f\u4e0d\u5b58\u5728\uff01\");\n            }\n            \/\/6.\u5b58\u5728\uff0c\u5b58\u5165redis(\u5e76\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4)\n            stringRedisTemplate.opsForValue().set(key,JSONUtil.toJsonStr(shop),CACHE_SHOP_TTL, TimeUnit.MINUTES);\n        } catch (InterruptedException e) {\n            throw new RuntimeException(e);\n        } finally {\n            \/\/7.\u91ca\u653e\u9501\n            unlock(lockKey);\n        }\n        \/\/8.\u8fd4\u56de\u5546\u54c1\u4fe1\u606f\n        return shop;\n    }\n    \/\/\u83b7\u53d6\u9501\n    public Boolean tryLock(String key){\n        Boolean flag = stringRedisTemplate.opsForValue().setIfAbsent(key, \"1\", 10, TimeUnit.SECONDS);\n        return BooleanUtil.isTrue(flag);\n    }\n    \/\/\u91ca\u653e\u9501\u65b9\u6cd5\n    public void unlock(String key){\n        stringRedisTemplate.delete(key);\n    }\n}\n   <\/pre>\n<h4>6.2.2 \u903b\u8f91\u8fc7\u671f<\/h4>\n<p>\u903b\u8f91\u8fc7\u671f\u7684\u5904\u7406\u65b9\u6cd5\u4e3b\u8981\u4e3a\uff1a<\/p>\n<p>\u7ed9redis\u7f13\u5b58\u5b57\u6bb5\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u8fc7\u671f\u65f6\u95f4\uff0c\u7136\u540e\u5f53\u7ebf\u7a0b\u67e5\u8be2\u6570\u636e\u5e93\u7684\u65f6\u5019\uff0c\u5148\u5224\u65ad\u662f\u5426\u5df2\u7ecf\u8fc7\u671f\uff0c\u5982\u679c\u8fc7\u671f\uff0c\u5c31\u83b7\u53d6\u83b7\u53d6\u4e92\u65a5\u9501\uff0c\u5e76\u5f00\u542f\u4e00\u4e2a\u5b50\u7ebf\u7a0b\u8fdb\u884c\u7f13\u5b58\u91cd\u5efa\u4efb\u52a1\uff0c\u76f4\u5230\u5b50\u7ebf\u7a0b\u5b8c\u6210\u4efb\u52a1\u540e\uff0c\u91ca\u653e\u9501\u3002\u5728\u8fd9\u6bb5\u65f6\u95f4\u5185\uff0c\u5176\u4ed6\u7ebf\u7a0b\u83b7\u53d6\u4e92\u65a5\u9501\u5931\u8d25\u540e\uff0c\u5e76\u4e0d\u662f\u7ee7\u7eed\u7b49\u5f85\u91cd\u8bd5\uff0c\u800c\u662f\u76f4\u63a5\u8fd4\u56de\u65e7\u6570\u636e\u3002\u8fd9\u4e2a\u65b9\u6cd5\u867d\u7136\u6027\u80fd\u8f83\u597d\uff0c\u4f46\u4e5f\u727a\u7272\u4e86\u6570\u636e\u4e00\u81f4\u6027\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965563f968b7b4f4b.png\" class=\"aligncenter\"><\/p>\n<p>\u5b9e\u73b0\u65b9\u6cd5\uff1a<\/p>\n<p>1.\u83b7\u53d6\u4e92\u65a5\u9501\u548c\u91ca\u653e\u9501\u5982\u4e0a<\/p>\n<p>2.\u7ed9redis\u6570\u636e\u6dfb\u52a0\u4e00\u4e2a\u8fc7\u671f\u65f6\u95f4\uff08\u521b\u5efa\u4e00\u4e2aRedisData\u7c7b\uff0c\u5e76\u5c01\u88c5\u6570\u636e\uff09<\/p>\n<p>RedisData\u7c7b\uff1a<\/p>\n<pre>package com.hmdp.utils;\nimport lombok.Data;\nimport java.time.LocalDateTime;\n@Data\npublic class RedisData {\n    private LocalDateTime expireTime;\n    private Object data;\n}<\/pre>\n<pre>\/\/\u7ed9\u5546\u54c1\u4fe1\u606f\u6dfb\u52a0\u4e00\u4e2a\u8fc7\u671f\u65f6\u95f4\u5b57\u6bb5\uff0c\u5e76\u5b58\u5165redis\u5f53\u4e2d\n    public void saveShop2Redis(Long id,Long expireSeconds){\n        Shop shop = getById(id);\n        RedisData redisData = new RedisData();\n        redisData.setData(shop);\n        redisData.setExpireTime(LocalDateTime.now().plusSeconds(expireSeconds));\n        stringRedisTemplate.opsForValue().set(CACHE_SHOP_KEY+id,JSONUtil.toJsonStr(redisData));\n    }<\/pre>\n<p>\u7136\u540e\u5c31\u662f\u4e1a\u52a1\u5b9e\u73b0\u4e86\uff1a<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167728965663f968b820fcd.png\" class=\"aligncenter\"><\/p>\n<p>\u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>package com.hmdp.service.impl;\nimport cn.hutool.core.util.BooleanUtil;\nimport cn.hutool.core.util.StrUtil;\nimport cn.hutool.json.JSONObject;\nimport cn.hutool.json.JSONUtil;\nimport com.hmdp.dto.Result;\nimport com.hmdp.entity.Shop;\nimport com.hmdp.mapper.ShopMapper;\nimport com.hmdp.service.IShopService;\nimport com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;\nimport com.hmdp.utils.RedisData;\nimport org.springframework.data.redis.core.StringRedisTemplate;\nimport org.springframework.stereotype.Service;\nimport org.springframework.transaction.annotation.Transactional;\nimport javax.annotation.Resource;\nimport java.time.LocalDateTime;\nimport java.util.concurrent.Executor;\nimport java.util.concurrent.ExecutorService;\nimport java.util.concurrent.Executors;\nimport java.util.concurrent.TimeUnit;\nimport static com.hmdp.utils.RedisConstants.*;\n\/**\n * <p>\n *  \u670d\u52a1\u5b9e\u73b0\u7c7b\n * <\/p>\n *\/\n@Service\npublic class ShopServiceImpl extends ServiceImpl\n   \n     implements IShopService {\n    @Resource\n    private StringRedisTemplate stringRedisTemplate;\n    @Override\n    public Result queryShopById(Long id) {\n        \/\/\u903b\u8f91\u8fc7\u671f\u89e3\u51b3\u7f13\u5b58\u51fb\u7a7f\u95ee\u9898\n\/\/        Shop shop = queryWithLogicalExpire(id);\n        if (shop == null){\n            Result.fail(\"\u5546\u54c1\u4fe1\u606f\u4e0d\u5b58\u5728!\");\n        }\n        \/\/8.\u8fd4\u56de\u5546\u54c1\u4fe1\u606f\n        return Result.ok(shop);\n    }\n    private static final ExecutorService CACHE_REBUILD_EXECUTOR = Executors.newFixedThreadPool(10);\n    public Shop queryWithLogicalExpire(Long id){\n        \/\/1.\u53bbredis\u4e2d\u67e5\u8be2\u5546\u54c1\u662f\u5426\u5b58\u5728\n        String key = CACHE_SHOP_KEY+id;\n        String shopJson = stringRedisTemplate.opsForValue().get(key);\n        \/\/2.\u5224\u65ad\u662f\u5426\u547d\u4e2d\n        \/\/3.\u672a\u547d\u4e2d\n        if (StrUtil.isBlank(shopJson)){\n            return null;\n        }\n        \/\/4.\u547d\u4e2d,\u5148\u628aredis\u4e2d\u7684\u6570\u636e\u53cd\u5e8f\u5217\u5316\u6210java\u5bf9\u8c61\n        RedisData redisData = JSONUtil.toBean(shopJson, RedisData.class);\n        \/\/4.1\u83b7\u53d6\u8fc7\u671f\u65f6\u95f4\n        LocalDateTime expireTime = redisData.getExpireTime();\n        \/\/4.2\u83b7\u53d6\u5546\u54c1\u5bf9\u8c61\n        JSONObject data = (JSONObject) redisData.getData();\n        Shop shop = JSONUtil.toBean(data, Shop.class);\n        \/\/5.\u5224\u65ad\u662f\u5426\u8fc7\u671f\n        if (expireTime.isAfter(LocalDateTime.now())){\n            \/\/\u672a\u8fc7\u671f,\u76f4\u63a5\u8fd4\u56deshop\n            return shop;\n        }\n        \/\/6.\u8fc7\u671f\uff0c\u91cd\u5efa\u7f13\u5b58\n        \/\/6.1\u5c1d\u8bd5\u83b7\u53d6\u9501\uff0c\u5e76\u5224\u65ad\n        String lockKey = LOCK_SHOP_KEY + id;\n        Boolean isLock = tryLock(lockKey);\n        if (isLock){\n            \/\/5.2 \u5982\u679c\u6210\u529f\uff0c\u5f00\u542f\u4e00\u4e2a\u72ec\u7acb\u7684\u7ebf\u7a0b,\u91cd\u5efa\u7f13\u5b58\n            CACHE_REBUILD_EXECUTOR.submit(()-&gt;{\n                try {\n                    \/\/\u91cd\u5efa\u7f13\u5b58\n                    this.saveShop2Redis(id,20L);\n                } catch (Exception e) {\n                    throw new RuntimeException(e);\n                } finally {\n                    \/\/\u91ca\u653e\u9501\n                    unlock(lockKey);\n                }\n            });\n        }\n        \/\/6.2\u8fd4\u56de\u65e7\u7684\u5546\u54c1\u4fe1\u606f\n        return shop;\n    }\n    \/\/\u83b7\u53d6\u9501\n    public Boolean tryLock(String key){\n        Boolean flag = stringRedisTemplate.opsForValue().setIfAbsent(key, \"1\", 10, TimeUnit.SECONDS);\n        return BooleanUtil.isTrue(flag);\n    }\n    \/\/\u91ca\u653e\u9501\u65b9\u6cd5\n    public void unlock(String key){\n        stringRedisTemplate.delete(key);\n    }\n    \/\/\u7ed9\u5546\u54c1\u4fe1\u606f\u6dfb\u52a0\u4e00\u4e2a\u8fc7\u671f\u65f6\u95f4\u5b57\u6bb5\uff0c\u5e76\u5b58\u5165redis\u5f53\u4e2d\n    public void saveShop2Redis(Long id,Long expireSeconds){\n        Shop shop = getById(id);\n        RedisData redisData = new RedisData();\n        redisData.setData(shop);\n        redisData.setExpireTime(LocalDateTime.now().plusSeconds(expireSeconds));\n        stringRedisTemplate.opsForValue().set(CACHE_SHOP_KEY+id,JSONUtil.toJsonStr(redisData));\n    }\n}\n   <\/pre>\n<p>\u7f13\u5b58\u77e5\u8bc6\u7ed3\u675f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis\u7f13\u5b58\u5b9e\u4f8b\u8d85\u8be6\u7ec6\u8bb2\u89e3 \u6536&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201596","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201596"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201596\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}