- 在SpringBoot中,我会使用到JpaRepository这个接口,那么完全可以在自定义的AppRepository中规定数据库表对应的类为其泛型,如:public interface AppRepository extends JpaRepository
private final AppService appService;
List<AppDTO> appDTOList= appService.findAll();
Map<String,Object> serializedApps=new HashMap<>();
for (AppDTO appDTO:appDTOList) {
if (Objects.isNull(appDTO)){
continue;
}
serializedApps.put(appDTO.getId(),appDTO);
}
redisTemplate.opsForHash().putAll("apps",serializedApps);
hset("apps","ab473eb9cc21000","{id:ab473eb9cc21000,user_id:ab473fb91021000,name:SideView,code:994Q7g4Hw0ypMX8JdK43,category:0110}");
- 我们可以为redis中的所有key设置过期时间或者日期,如下所示.
redisTemplate.expire("hash",60*60,TimeUnit.SECONDS);
String dateStr="2017-11-01 10:05:09";
Date re1=simpleDateFormat.parse(dateStr);
redisTemplate.expireAt("hash",re1);
int n=11;
long future=System.currentTimeMillis()+n*24*60*60*1000;
Date date=new Date(future);
redisTemplate.expiredAt("hash",date);