diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteService.java index 88faeb48eb..3bd3ae997f 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteService.java @@ -56,6 +56,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import static io.metersphere.api.controller.result.ApiResultCode.RESOURCE_POOL_EXECUTE_ERROR; @@ -151,7 +152,7 @@ public class ApiExecuteService { // 将测试脚本缓存到 redis String scriptRedisKey = getScriptRedisKey(taskRequest.getReportId(), taskRequest.getResourceId()); - stringRedisTemplate.opsForValue().set(scriptRedisKey, executeScript); + stringRedisTemplate.opsForValue().set(scriptRedisKey, executeScript, 1, TimeUnit.DAYS); if (StringUtils.equals(taskRequest.getRunMode(), ApiExecuteRunMode.FRONTEND_DEBUG.name())) { // 清空mino和kafka配置信息,避免前端获取 diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/queue/ApiExecutionQueueService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/queue/ApiExecutionQueueService.java index 2c22e47bfc..9099cdb61e 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/queue/ApiExecutionQueueService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/queue/ApiExecutionQueueService.java @@ -13,6 +13,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.LinkedList; import java.util.List; +import java.util.concurrent.TimeUnit; @Service public class ApiExecutionQueueService { @@ -26,7 +27,7 @@ public class ApiExecutionQueueService { @Transactional(propagation = Propagation.REQUIRES_NEW) public void insertQueue(ExecutionQueue queue, List queues) { // 保存队列信息 - redisTemplate.opsForValue().setIfAbsent(QUEUE_PREFIX + queue.getQueueId(), JSON.toJSONString(queue)); + redisTemplate.opsForValue().setIfAbsent(QUEUE_PREFIX + queue.getQueueId(), JSON.toJSONString(queue), 1, TimeUnit.DAYS); // 保存队列详情信息 queues.forEach(n -> redisTemplate.opsForList().rightPush(QUEUE_DETAIL_PREFIX + queue.getQueueId(), JSON.toJSONString(n))); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/queue/ApiExecutionSetService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/queue/ApiExecutionSetService.java index 590be14e3e..05ed852867 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/queue/ApiExecutionSetService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/queue/ApiExecutionSetService.java @@ -5,6 +5,7 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.util.List; +import java.util.concurrent.TimeUnit; @Service public class ApiExecutionSetService { @@ -21,7 +22,11 @@ public class ApiExecutionSetService { * @param resourceIds */ public void initSet(String setId, List resourceIds) { - resourceIds.forEach(resourceId -> redisTemplate.opsForSet().add(SET_PREFIX + setId, resourceId)); + resourceIds.forEach(resourceId -> { + String key = SET_PREFIX + setId; + redisTemplate.opsForSet().add(key, resourceId); + redisTemplate.expire(key, 1, TimeUnit.DAYS); + }); } /**