mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-13 05:12:07 +08:00
sonarqube质量修复
This commit is contained in:
+2
-2
@@ -82,7 +82,7 @@ public class ChenfengCacheAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisLockUtil lockUtil(RedisTemplate<String, Object> redisTemplate, RedissonClient client) {
|
||||
return new RedisLockUtil(redisTemplate, client);
|
||||
public RedisLockUtil lockUtil(RedisTemplate<String, Object> redisTemplate) {
|
||||
return new RedisLockUtil(redisTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
-38
@@ -3,8 +3,6 @@ package com.cf.imes.framework.redis.util;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -21,42 +19,6 @@ public class RedisLockUtil {
|
||||
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
/**
|
||||
* 加锁
|
||||
*
|
||||
* @param key rediskey
|
||||
* @param timeout 锁的超时时间,传空则按照默认配置
|
||||
* @param waitTime 等待获取锁的时间,传空则按照默认配置
|
||||
* @return true拿到锁,反之没有做对应的业务提醒
|
||||
*/
|
||||
public boolean redissonLock(String key, Integer waitTime, Integer timeout) {
|
||||
boolean getLock = false;
|
||||
try {
|
||||
RLock rLock = redissonClient.getLock(key);
|
||||
return rLock.tryLock(waitTime, timeout, TimeUnit.MILLISECONDS);
|
||||
} catch (Exception e) {
|
||||
log.error("[RedisLockUtil][lock]加锁失败", e);
|
||||
return getLock;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解锁
|
||||
* 使用注意:配合以上redisson的lock只能在当前线程中unlock,否则失败!!!
|
||||
*
|
||||
* @param key rediskey
|
||||
*/
|
||||
public void redissonReleaseLock(String key) {
|
||||
try {
|
||||
RLock rLock = redissonClient.getLock(key);
|
||||
rLock.unlock();
|
||||
} catch (Exception e) {
|
||||
log.error("[RedisLockUtil][unlock]解锁失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动set nx ex加锁
|
||||
* 使用注意:可用于跨服务
|
||||
|
||||
Reference in New Issue
Block a user