弊端:不能给每一个元素设置过期时间
参考:
redisTemplate.opsForHash用法_stringredistemplate.opsforhash_打工人很惨的博客-CSDN博客
简单使用:
String jobNum = (String)params.get("jobNum");
stringRedisTemplate.opsForHash().put(RedisUtil.REDIS_EHR_DAILY,"CW666-"+ RandomUtil.randomInt(1,5), JSON.toJSONString(DelayUpdateDailyRecord.builder().hrId("CW888").build()));
List<Object> sets = stringRedisTemplate.opsForHash().values(RedisUtil.REDIS_EHR_DAILY);
List<DelayUpdateDailyRecord> list = null;
if(CollectionUtil.isEmpty(sets)){
list = new ArrayList();
}else{
list = new ArrayList<>(sets.size());
for(int i=0;i< sets.size();i++){
DelayUpdateDailyRecord entity = JSON.parseObject(sets.get(i).toString(),DelayUpdateDailyRecord.class);
list.add(entity);
}
}
System.out.println("-------所有1-------");
for (DelayUpdateDailyRecord delayUpdateDailyRecord : list) {
System.out.println(JSON.toJSONString(delayUpdateDailyRecord));
}
if(StringUtils.isNotBlank(jobNum)){
// 删
stringRedisTemplate.opsForHash().delete(RedisUtil.REDIS_EHR_DAILY,jobNum);
}