redisTemplate缓存方法template code
代码语言:javascript代码运行次数:0运行复制import com.alibaba.fastjson.JSONObject;
@Autowired private RedisTemplate redisTemplate; String PREFIX = "项目名称:模块名称:方法名称:唯一条件key:"; Integer EX = 15; //分钟 //从redis缓存中获取,没有则查询数据库中的数据 String jsonStr = (String)redisTemplate.opsForValue().get(PREFIX+reqVo.getMemNo()+":"+reqVo.getOrderNo); if(StringUtils.isNotBlank(jsonStr)){ resVo = JSONObject.parseObject(jsonStr, ResVo.class); return resVo; }
//查询数据库 TODO
//数据重新存入redis, 设置过期时间 15分钟 String jsonStr = JSONObject.toJSONString(resVo); redisTemplate.opsForValue().set(PREFIX+reqVo.getMemNo()+":"+reqVo.getOrderNo,jsonStr,EX, TimeUnit.MINUTES);
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2022-05-09,如有侵权请联系 cloudcommunity@tencent 删除string数据缓存codeprefix发布者:admin,转转请注明出处:http://www.yc00.com/web/1754987616a5224362.html
评论列表(0条)