处理一些合并冲突

This commit is contained in:
super
2026-05-05 14:11:35 +08:00
parent 710b953120
commit 203937335d
19 changed files with 1075 additions and 198 deletions
@@ -20,6 +20,12 @@ public class DistributedJobLockService {
+ "else return 0 end",
Long.class
);
private static final DefaultRedisScript<Long> RENEW_SCRIPT = new DefaultRedisScript<>(
"if redis.call('get', KEYS[1]) == ARGV[1] then "
+ "return redis.call('pexpire', KEYS[1], ARGV[2]) "
+ "else return 0 end",
Long.class
);
private final StringRedisTemplate stringRedisTemplate;
private final String ownerPrefix;
@@ -74,6 +80,25 @@ public class DistributedJobLockService {
log.warn("[job-lock] release failed jobName={} key={} msg={}", jobName, key, ex.getMessage());
}
}
public boolean renew(Duration ttl) {
if (released) {
return false;
}
Duration actualTtl = (ttl == null || ttl.isNegative() || ttl.isZero()) ? Duration.ofMinutes(10) : ttl;
try {
Long renewed = stringRedisTemplate.execute(
RENEW_SCRIPT,
Collections.singletonList(key),
token,
String.valueOf(actualTtl.toMillis())
);
return Long.valueOf(1L).equals(renewed);
} catch (Exception ex) {
log.warn("[job-lock] renew failed jobName={} key={} msg={}", jobName, key, ex.getMessage());
return false;
}
}
}
private String buildLockKey(String jobName) {