diff --git a/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/controller/RedisTestController.java b/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/controller/RedisTestController.java new file mode 100644 index 0000000..a4ccbb5 --- /dev/null +++ b/ai-analytic-center-biz/src/main/java/com/volvo/ai/analytic/center/controller/RedisTestController.java @@ -0,0 +1,105 @@ +package com.volvo.ai.analytic.center.controller; + + +import com.volvo.ai.analytic.center.dto.req.AnalysisQueryReq; +import com.volvo.ai.analytic.center.dto.req.AnalysisReq; +import com.volvo.ai.analytic.center.dto.resp.AnalysisResp; +import com.volvo.ai.analytic.center.service.AiAnalysisDifyService; +import com.volvo.ai.analytic.center.utils.ConstantStr; +import com.volvo.common.core.util.ResultMsg; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.rocketmq.spring.core.RocketMQTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ZSetOperations; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Set; +import java.util.concurrent.TimeUnit; + + +@RestController() +@Api(tags = "分析中心接口") +@Slf4j +@RefreshScope +@RequestMapping("redis") +public class RedisTestController { + + @Autowired + private RocketMQTemplate rocketMQTemplate; + + @Autowired + private AiAnalysisDifyService aiAnalysisDifyService; + + + @Autowired + private RedisTemplate redisTemplate; + + + + @PostMapping("/testRedis") + @ApiOperation(value = "Ai解析结果查询") + public AnalysisResp testRedis(@RequestBody String key) { + log.info("aiAnalyze queryRedis : {}",key); + + for (int i = 0; i < 10; i++){ + ZSetOperations zSetOperations = redisTemplate.opsForZSet(); + long currentMs = System.currentTimeMillis(); + zSetOperations.add(key, key+i, currentMs); + + // set the expiration time for the code user + //redisTemplate.expire(key, 60, TimeUnit.SECONDS); + + // remove the value that out of current window + zSetOperations.removeRangeByScore(key, 0, currentMs - 5 * 1000); + + // check all available count + Long count = zSetOperations.zCard(key); + System.out.println("count:" + count); + + Set getredisSet = redisTemplate.opsForZSet().range(key, 0, -1); + System.out.println("getredisSet:" + getredisSet); + try { + TimeUnit.SECONDS.sleep(5); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + Long count2 = zSetOperations.zCard(key); + System.out.println("count2:" + count2); + + Set getredisSet2 = redisTemplate.opsForZSet().range(key, 0, -1); + System.out.println("getredisSet2:" + getredisSet2); + } + + return AnalysisResp.success("ok"); + } + @PostMapping("/queryRedis") + @ApiOperation(value = "queryRedis") + public ResultMsg queryRedis(@RequestBody String key) { + log.info("aiAnalyze queryRedis : {}",key); + Set getredisSet = redisTemplate.opsForZSet().range(key, 0, -1); + log.info("queryRedis:{}", getredisSet); + return ResultMsg.ok(getredisSet); + } + @PostMapping("/del") + @ApiOperation(value = "del") + public ResultMsg del(@RequestBody String key) { + log.info("aiAnalyze queryRedis : {}",key); + redisTemplate.opsForZSet().removeRange(key, 0, -1); + Set getRedisSet = redisTemplate.opsForZSet().range(key, 0, -1); + log.info("removeRange:{}" , getRedisSet); + redisTemplate.delete(key); + Set getredisSet2 = redisTemplate.opsForZSet().range(key, 0, -1); + log.info("delete:{}", getredisSet2); + return ResultMsg.ok(getredisSet2); + } + +} +