我的周内反思

32 篇文章 0 订阅
3 篇文章 0 订阅
  1. 在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}");
  1. 我们可以为redis中的所有key设置过期时间或者日期,如下所示.
//1,可以为所有的数据结构的key设置过期时间,比如下面的就是设置1个小时后过期
redisTemplate.expire("hash",60*60,TimeUnit.SECONDS);

//2,可以为所有的数据结构的key设置过期日期,比如下面的就是设置 2017-11-01 10:05:09 后过期
String dateStr="2017-11-01 10:05:09";
Date re1=simpleDateFormat.parse(dateStr);
redisTemplate.expireAt("hash",re1);

//3,可以为所有的数据结构的key设置过期日期,比如下面的就是设置n天后过期
int n=11;
long future=System.currentTimeMillis()+n*24*60*60*1000;//一天以后
Date date=new Date(future);
redisTemplate.expiredAt("hash",date);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值