1.流程图
2.实现逻辑
service层
public result querybyid(long id) { // 1.从redis中查询店铺缓存 string shopjson = stringredistemplate.opsforvalue().get("cache:shop:"+id); // 2.判断缓存是否存在 if (strutil.isnotblank(shopjson)) { shop shop = jsonutil.tobean(shopjson, shop.class); return result.ok(shop); } // 3.不存在,根据id查询数据库 shop shop = getbyid(id); // mybatisplus功能 // 4.不存在,返回错误 if (shop == null) { return result.fail("店铺数据不存在"); } // 存在,写入redis stringredistemplate.opsforvalue().set("cache:shop:"+id, jsonutil.tojsonstr(shop)); return result.ok(shop); }
到此这篇关于redis添加商铺查询缓存功能实现的文章就介绍到这了,更多相关redis商铺查询缓存内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论