redis 杂记
1、存取对象方法
@Override public QueryResult<CmthpbankDto> queryCacheBankList(CmthpbankQuery query) { QueryResult<CmthpbankDto> result = new QueryResult<CmthpbankDto>(false, ErrorCodeConstant.ERROR_UNKNOWN, "error", null); try { List<CmthpbankDto> listDto = JSON.parseArray(jedisCluster.get(BANK_NAME), CmthpbankDto.class); if (listDto == null || listDto.size() == 0) { listDto = cmthpbankDao.queryCmthpbankList(query); if (!StringUtils.isEmpty(listDto)) { jedisCluster.set(BANK_NAME, JSON.toJSONString((listDto))); // 去数据库取 jedisCluster.expire(BANK_NAME, RedisConstant.EXPIRE_TIME_MONTH); } } result.setSuccess(true); result.setResults(listDto); } catch (Exception e) { e.printStackTrace(); result.setSuccess(false); } return result; }
注释:
BANK_NAME:存入取出的key
RedisConstant.EXPIRE_TIME_MONTH:缓存有效时间
相关推荐
王道革 2020-11-25
wangdonghello 2020-11-03
Langeldep 2020-11-16
chenhualong0 2020-11-16
聚合室 2020-11-16
koushr 2020-11-12
MRFENGG 2020-11-11
guoyanga 2020-11-10
fackyou00 2020-11-10
Orangesss 2020-11-03
dongCSDN 2020-10-31
rainandtear 2020-10-30
Quietboy 2020-10-30
liuyulong 2020-10-29
fansili 2020-10-29
温攀峰 2020-10-23
jackbon 2020-10-19
kaixinfelix 2020-10-04