refactor(接口测试): redis接口执行相关资源,设置过期时间

This commit is contained in:
AgAngle 2024-04-15 11:14:21 +08:00 committed by 刘瑞斌
parent 2b60e77817
commit 662a0b9050
3 changed files with 10 additions and 3 deletions

View File

@ -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配置信息避免前端获取

View File

@ -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<ExecutionQueueDetail> 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)));
}

View File

@ -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<String> 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);
});
}
/**