chore: redisson init
This commit is contained in:
parent
4894976eee
commit
eb72d0d0e2
|
@ -4,6 +4,7 @@ import com.fit2cloud.quartz.anno.QuartzScheduled;
|
|||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.ApplicationNumScope;
|
||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.redisson.Redisson;
|
||||
|
@ -22,8 +23,7 @@ public class NumGenerator {
|
|||
private static StringRedisTemplate stringRedisTemplate;
|
||||
private static ProjectMapper projectMapper;
|
||||
|
||||
public NumGenerator(Redisson redisson, StringRedisTemplate stringRedisTemplate, ProjectMapper projectMapper) {
|
||||
NumGenerator.redisson = redisson;
|
||||
public NumGenerator(StringRedisTemplate stringRedisTemplate, ProjectMapper projectMapper) {
|
||||
NumGenerator.stringRedisTemplate = stringRedisTemplate;
|
||||
NumGenerator.projectMapper = projectMapper;
|
||||
}
|
||||
|
@ -33,6 +33,10 @@ public class NumGenerator {
|
|||
* @param scope 用例类型
|
||||
*/
|
||||
public static long nextNum(String prefix, ApplicationNumScope scope) {
|
||||
// 初始化
|
||||
if (redisson == null) {
|
||||
redisson = CommonBeanFactory.getBean(Redisson.class);
|
||||
}
|
||||
RIdGenerator idGenerator = redisson.getIdGenerator(prefix + "_" + scope.name());
|
||||
// 每次都尝试初始化,容量为1,只有一个线程可以初始化成功
|
||||
if (scope.equals(ApplicationNumScope.API_TEST_CASE)) {
|
||||
|
|
Loading…
Reference in New Issue