fix:需求代码

上级 a0b786ac
......@@ -41,7 +41,7 @@ public class RedisLockAspect {
if (locked) {
if (StringUtils.hasText(lockKey)) {
redisTemplate.opsForValue().set(lockKey, "locked", redisLock.expire(), TimeUnit.MILLISECONDS);
redisLockRenewal.scheduleRenewal(lock, lockKey, 20000, redisLock.expire());
redisLockRenewal.scheduleRenewal(lock, redisLock, 20000);
}
return joinPoint.proceed();
} else {
......
package com.kwan.springbootkwan.schedule;
import com.kwan.springbootkwan.annotation.RedisLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
......@@ -22,13 +23,13 @@ public class RedisLockRenewal {
this.redisTemplate = redisTemplate;
}
public void scheduleRenewal(Lock lock, String lockKey, long renewalIntervalMillis, long lockExpireMillis) {
public void scheduleRenewal(Lock lock, RedisLock redisLock, long renewalIntervalMillis) {
scheduler.scheduleAtFixedRate(() -> {
try {
boolean locked = lock.tryLock(lockExpireMillis, TimeUnit.MILLISECONDS);
boolean locked = lock.tryLock(redisLock.timeout(), TimeUnit.MILLISECONDS);
if (locked) {
// 续期操作:设置新的过期时间
redisTemplate.expire(lockKey, lockExpireMillis, TimeUnit.MILLISECONDS);
redisTemplate.expire(redisLock.key(), redisLock.expire(), TimeUnit.MILLISECONDS);
}
} catch (Exception e) {
// 处理续期失败的情况,可以记录日志或采取其他操作
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册