mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
新增生产单导入异步处理
This commit is contained in:
+2
-2
@@ -82,7 +82,7 @@ public class ChenfengCacheAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisLockUtil lockUtil(ChenfengCacheProperties chenfengCacheProperties, RedissonClient client) {
|
||||
return new RedisLockUtil(chenfengCacheProperties, client);
|
||||
public RedisLockUtil lockUtil(ChenfengCacheProperties chenfengCacheProperties, RedissonClient client, RedisTemplate redisTemplate) {
|
||||
return new RedisLockUtil(chenfengCacheProperties, client, redisTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -34,5 +34,5 @@ public class ChenfengCacheProperties {
|
||||
* 等待获取锁的时间,单位:毫秒(ms)
|
||||
* 默认0.5秒
|
||||
*/
|
||||
private int lockWaitTime = 500;
|
||||
private int lockWaitTime = 5000;
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.cf.imes.framework.redis.constants;
|
||||
|
||||
/**
|
||||
* 多模块公用redis key常量
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/14 15:22
|
||||
*/
|
||||
public class RedisKeyConstants {
|
||||
/**
|
||||
* 生产单导入
|
||||
*/
|
||||
public static final String ORDER_IMPORT_LOCK_KEY = "order_import:%s";
|
||||
}
|
||||
+37
@@ -6,6 +6,7 @@ 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;
|
||||
|
||||
@@ -23,6 +24,8 @@ public class RedisLockUtil {
|
||||
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 加锁
|
||||
*
|
||||
@@ -63,6 +66,7 @@ public class RedisLockUtil {
|
||||
|
||||
/**
|
||||
* 解锁
|
||||
* 使用注意:配合以上两个redisson的lock只能在当前线程中unlock,否则失败!!!
|
||||
*
|
||||
* @param key rediskey
|
||||
*/
|
||||
@@ -74,4 +78,37 @@ public class RedisLockUtil {
|
||||
log.error("[RedisLockUtil][unlock]解锁失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动set nx ex加锁
|
||||
* 使用注意:可用于跨服务
|
||||
*
|
||||
* @param key
|
||||
* @param uniqeKey 解锁的时候校验,避免其他任务误解
|
||||
* @param timeout
|
||||
* @return
|
||||
*/
|
||||
public boolean lock(String key, String uniqeKey, Integer timeout) {
|
||||
return redisTemplate.opsForValue().setIfAbsent(key, uniqeKey, timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解锁
|
||||
* 校验唯一值后删除key
|
||||
* 使用注意:可用于跨服务
|
||||
*
|
||||
* @param key
|
||||
* @param uniqeKey 解锁时校验,避免同key下其他任务解锁到
|
||||
*/
|
||||
public void unlock(String key, String uniqeKey) {
|
||||
Object object = redisTemplate.opsForValue().get(key);
|
||||
if (ObjectUtil.equal(object, uniqeKey)) {
|
||||
Boolean delete = redisTemplate.delete(key);
|
||||
if (delete) {
|
||||
log.info(String.format("[RedisLockUtil][unlock][%s]解锁", key));
|
||||
} else {
|
||||
log.error(String.format("[RedisLockUtil][unlock][%s]解锁失败", key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user