【MapSheep】
[好记性不如烂笔头]

2、 Redis锁使用

@Async
@Scheduled(cron = "${outside_cron:0 0 23 * * ?}")
public void showTimer() throws ParseException {
    String reqId = StringUtil.getShortUuid();
    String objectId = IdUtil.objectId();
    boolean getLock = redisTemplateUtil.setIfAbsent(objectId, reqId);
    redisTemplateUtil.expireKey(objectId, 3000L, TimeUnit.SECONDS);

    if (getLock) {
        performTimingTask();
    }
}
posted on 2025-07-10 11:34  (Play)  阅读(4)  评论(0)    收藏  举报