From 9618243b127ca0ce8554937a5cc5ccb297ce243d Mon Sep 17 00:00:00 2001 From: waynaqua <1669738430@qq.com> Date: Tue, 27 Feb 2024 11:17:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(mall):=20=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/LoginController.java | 1 - .../base/controller/CommonFileController.java | 1 + .../wayn/data/redis/config/CacheConfig.java | 3 +- .../wayn/data/redis/manager/RedisCache.java | 29 ++++++++++++++++--- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/system/LoginController.java b/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/system/LoginController.java index 954c270..1fc2156 100644 --- a/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/system/LoginController.java +++ b/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/system/LoginController.java @@ -68,7 +68,6 @@ public class LoginController { return success; } - @GetMapping("/getRouters") public R getRouters(HttpServletRequest request) { R success = R.success(); diff --git a/waynboot-common/src/main/java/com/wayn/common/base/controller/CommonFileController.java b/waynboot-common/src/main/java/com/wayn/common/base/controller/CommonFileController.java index 205d868..84d4768 100644 --- a/waynboot-common/src/main/java/com/wayn/common/base/controller/CommonFileController.java +++ b/waynboot-common/src/main/java/com/wayn/common/base/controller/CommonFileController.java @@ -99,6 +99,7 @@ public class CommonFileController { try { // 1. 获取上传文件的保存路径 String filePath = WaynConfig.getUploadDir(); + log.info("file path is {}", filePath); // 2. 上传文件至服务器 String fileName = FileUploadUtil.uploadFile(file, filePath); // 3. 返回文件访问路径 diff --git a/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/config/CacheConfig.java b/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/config/CacheConfig.java index d32359b..a18452d 100644 --- a/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/config/CacheConfig.java +++ b/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/config/CacheConfig.java @@ -32,8 +32,7 @@ public class CacheConfig implements CachingConfigurer { redisTemplate.setConnectionFactory(connectionFactory); redisTemplate.setKeySerializer(keySerializer()); redisTemplate.setHashKeySerializer(keySerializer()); - redisTemplate.setValueSerializer(valueSerializer()); - redisTemplate.setHashValueSerializer(valueSerializer()); + redisTemplate.setDefaultSerializer(valueSerializer()); redisTemplate.afterPropertiesSet(); return redisTemplate; } diff --git a/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/manager/RedisCache.java b/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/manager/RedisCache.java index 4f1e386..6eb6e2d 100644 --- a/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/manager/RedisCache.java +++ b/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/manager/RedisCache.java @@ -2,14 +2,12 @@ package com.wayn.data.redis.manager; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.data.redis.core.HashOperations; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.ValueOperations; -import org.springframework.data.redis.core.ZSetOperations; +import org.springframework.data.redis.core.*; import org.springframework.data.redis.core.script.DefaultRedisScript; import org.springframework.data.redis.core.script.RedisScript; import org.springframework.stereotype.Component; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.TimeUnit; @@ -290,6 +288,29 @@ public class RedisCache { return (Long) redisTemplate.execute(redisScript, Collections.singletonList(key), orderSnIncrLimit); } + /** + * 获取匹配的所有key,使用scan避免阻塞 + * + * @param pattern 匹配keys的规则 + * @return 返回获取到的keys + */ + public Set scan(String pattern) { + return (Set) redisTemplate.execute((RedisCallback>) connection -> { + Set keysTmp = new HashSet<>(); + try (Cursor cursor = connection.keyCommands().scan(ScanOptions.scanOptions() + .match(pattern) + .count(1000).build())) { + while (cursor.hasNext()) { + keysTmp.add(new String(cursor.next(), StandardCharsets.UTF_8)); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new RuntimeException(e); + } + return keysTmp; + }); + } + /** * lua原子脚本 */