feat(mall): 代码优化

master
waynaqua 9 months ago
parent de6b7b32ad
commit 9618243b12

@ -68,7 +68,6 @@ public class LoginController {
return success; return success;
} }
@GetMapping("/getRouters") @GetMapping("/getRouters")
public R getRouters(HttpServletRequest request) { public R getRouters(HttpServletRequest request) {
R success = R.success(); R success = R.success();

@ -99,6 +99,7 @@ public class CommonFileController {
try { try {
// 1. 获取上传文件的保存路径 // 1. 获取上传文件的保存路径
String filePath = WaynConfig.getUploadDir(); String filePath = WaynConfig.getUploadDir();
log.info("file path is {}", filePath);
// 2. 上传文件至服务器 // 2. 上传文件至服务器
String fileName = FileUploadUtil.uploadFile(file, filePath); String fileName = FileUploadUtil.uploadFile(file, filePath);
// 3. 返回文件访问路径 // 3. 返回文件访问路径

@ -32,8 +32,7 @@ public class CacheConfig implements CachingConfigurer {
redisTemplate.setConnectionFactory(connectionFactory); redisTemplate.setConnectionFactory(connectionFactory);
redisTemplate.setKeySerializer(keySerializer()); redisTemplate.setKeySerializer(keySerializer());
redisTemplate.setHashKeySerializer(keySerializer()); redisTemplate.setHashKeySerializer(keySerializer());
redisTemplate.setValueSerializer(valueSerializer()); redisTemplate.setDefaultSerializer(valueSerializer());
redisTemplate.setHashValueSerializer(valueSerializer());
redisTemplate.afterPropertiesSet(); redisTemplate.afterPropertiesSet();
return redisTemplate; return redisTemplate;
} }

@ -2,14 +2,12 @@ package com.wayn.data.redis.manager;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.HashOperations; import org.springframework.data.redis.core.*;
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.script.DefaultRedisScript; import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.data.redis.core.script.RedisScript; import org.springframework.data.redis.core.script.RedisScript;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -290,6 +288,29 @@ public class RedisCache {
return (Long) redisTemplate.execute(redisScript, Collections.singletonList(key), orderSnIncrLimit); return (Long) redisTemplate.execute(redisScript, Collections.singletonList(key), orderSnIncrLimit);
} }
/**
* key使scan
*
* @param pattern keys
* @return keys
*/
public Set<String> scan(String pattern) {
return (Set<String>) redisTemplate.execute((RedisCallback<Set<String>>) connection -> {
Set<String> keysTmp = new HashSet<>();
try (Cursor<byte[]> 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 * lua
*/ */

Loading…
Cancel
Save