重redis中获取缓存参数。reids没有查询数据库。查到在放入redis中,当修改参数时,以及删除redis中缓存

来源:互联网 发布:中国核心期刊数据库 编辑:程序博客网 时间:2024/06/05 11:11

@Overridepublic String queryParamValueByKey(String paramKey) {String paramValue = null; // 系统参数配置值WithdrawParamConf config = null;/* * 先从redis缓存中获取提现开/关标志 */Object redisValue = redisTemplate.opsForValue().get(paramKey);if (redisValue != null) {paramValue = String.valueOf(redisValue);return paramValue; // 返回缓存中的结果}/* * 若缓存中不存在,则从数据库中获取 */config = withdrawParamConfDao.selectByParamName(paramKey);if (config != null) {// 将结果放入缓存中redisTemplate.opsForValue().set(paramKey, config.getParamValue(), 1, TimeUnit.DAYS);}return config.getParamValue();}

当修改系统参数时,要删除redis缓存。

修改业务参数配置(清空redis缓存)

@Overridepublic void modify(WithdrawParamConfDto systemParamConfDto) throws PaycoreException {// 1、系统参数配置必输项校验paramCheck(systemParamConfDto);//参数名称唯一性校验WithdrawParamConf confDto=withdrawParamConfDao.selectByParamName(systemParamConfDto.getParamKey());if(confDto != null){if(confDto.getId() !=systemParamConfDto.getId() ){throw new PaycoreException("参数名称不能重复");}}/* * 3、转换对象:DTO转Entity,修改系统参数配置信息 */WithdrawParamConf entity = getModifyEntity(systemParamConfDto);int result=withdrawParamConfDao.updateByPrimaryKeySelective(entity);if(result==1){WithdrawParamConf ConfDto=withdrawParamConfDao.selectByPrimaryKey(systemParamConfDto.getId());//清除redis缓存redisTemplate.delete(ConfDto.getParamKey());}}



阅读全文
0 0