diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/CacheApi.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/CacheApi.java new file mode 100644 index 00000000..7829fda1 --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/CacheApi.java @@ -0,0 +1,47 @@ +package com.nflg.product.bomnew.api.user; + +import com.nflg.product.base.core.api.BaseApi; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import nflg.product.common.vo.ResultVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.lang.NonNull; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +/** + * @author 曹鹏飞 + * @date 2024/4/9 09:22:09 + */ +@Api(tags = "缓存接口") +@RestController +@RequestMapping("bom/new/cache") +public class CacheApi extends BaseApi { + + private static final String PREFIX = "frontend:"; + + @Autowired + private RedisTemplate redisTemplate; + + @PostMapping("set") + @ApiOperation("设置缓存") + public ResultVO setCache(@Valid @RequestParam @NonNull String key, @Valid @RequestParam @NonNull String content) { + redisTemplate.boundValueOps(PREFIX + key).set(content); + return ResultVO.success(); + } + + @GetMapping("get") + @ApiOperation("获取缓存") + public ResultVO getCache(@Valid @RequestParam @NonNull String key) { + return ResultVO.success(redisTemplate.boundValueOps(PREFIX + key).get()); + } + + @PostMapping("del") + @ApiOperation("删除缓存") + public ResultVO delCache(@Valid @RequestParam @NonNull String key) { + redisTemplate.delete(PREFIX + key); + return ResultVO.success(); + } +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/bootstrap-prod.properties b/nflg_project_dev/nflg-bom-new/src/main/resources/bootstrap-prod.properties index bf784475..de276987 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/resources/bootstrap-prod.properties +++ b/nflg_project_dev/nflg-bom-new/src/main/resources/bootstrap-prod.properties @@ -1,12 +1,12 @@ nacos.server-addr=192.168.0.191:8848 - +spring.cache.type=redis spring.redis.database=0 spring.redis.host=192.168.0.191 spring.redis.password= spring.redis.port=6379 spring.redis.timeout=0 spring.redis.ssl=false -spring.redis.lettuce.pool.max-wait=1ms +spring.redis.lettuce.pool.max-wait=-1ms spring.redis.lettuce.pool.max-active=8 spring.redis.lettuce.pool.max-idle=8 spring.redis.lettuce.pool.min-idle=0 diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/bootstrap-sit.properties b/nflg_project_dev/nflg-bom-new/src/main/resources/bootstrap-sit.properties index 9137d34c..98ebd6f8 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/resources/bootstrap-sit.properties +++ b/nflg_project_dev/nflg-bom-new/src/main/resources/bootstrap-sit.properties @@ -1,14 +1,13 @@ #nacos.server-addr=114.132.64.230:8123 nacos.server-addr=192.168.0.194:8848 - - +spring.cache.type=redis spring.redis.database=0 spring.redis.host=192.168.0.194 spring.redis.password= spring.redis.port=6379 spring.redis.timeout=0 spring.redis.ssl=false -spring.redis.lettuce.pool.max-wait=1ms +spring.redis.lettuce.pool.max-wait=-1ms spring.redis.lettuce.pool.max-active=8 spring.redis.lettuce.pool.max-idle=8 spring.redis.lettuce.pool.min-idle=0