日期

private final SimpleDateFormat dateFormatDay = new SimpleDateFormat("yyyy-MM-dd");
public String currentDay() {  
    return dateFormatDay.format(new Date());  
}

“算出从现在起,距离 endDateTime 还有多少毫秒,然后再额外多加 1 天的宽限期。”

    long expireMillis = endDateTime.getTime()-System.currentTimeMillis()+ TimeUnit.DAYS.toMillis(1);
  • expireMillis (自动解锁时间):这就是你上一个问题里算出来的时间!它是这把锁的**“保命符”**。
  • TimeUnit.MILLISECONDS (时间单位):告诉 Redis,前面那个 expireMillis 的单位是毫秒。
    lock = redisService.setNx(lockKey,expireMillis,TimeUnit.MILLISECONDS);

单元测试

@RunWith(SpringRunner.class) 测试前,加载 spring 容器

map的api

childrenMap.computeIfAbsent(config.getParentPath(), k -> new ArrayList<>()).add(config);
  • 先看 childrenMap 里有没有 config.getParentPath()
  • 如果没有,就新建一个 ArrayList
  • 如果有,就把已有的那个 List 拿出来