src/main/java/com/ruoyi/common/constant/CacheConstants.java
@@ -8,6 +8,25 @@ public class CacheConstants { /** * Redis key æä¸å±åç¼ï¼æé¡¹ç®é离ï¼å spring.profiles.active çå¼ï¼ * ç± com.ruoyi.framework.config.RedisKeyConfig å¨å¯å¨æ¶æ³¨å ¥ï¼ * åä¸å°æ¶ä¸ºç©ºä¸²ï¼çä»·äºä¸å åç¼ï¼è¡ä¸ºéååç¶ä½ä¸ºå åºã */ public static String PREFIX = ""; public static void setPrefix(String prefix) { if (prefix == null || prefix.isEmpty()) { PREFIX = ""; } else { PREFIX = prefix + ":"; } } /** * ç»å½ç¨æ· redis key */ public static final String LOGIN_TOKEN_KEY = "login_tokens:"; src/main/java/com/ruoyi/common/utils/DictUtils.java
@@ -222,7 +222,7 @@ */ public static void clearDictCache() { Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.SYS_DICT_KEY + "*"); Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.PREFIX + CacheConstants.SYS_DICT_KEY + "*"); SpringUtils.getBean(RedisCache.class).deleteObject(keys); } @@ -234,6 +234,6 @@ */ public static String getCacheKey(String configKey) { return CacheConstants.SYS_DICT_KEY + configKey; return CacheConstants.PREFIX + CacheConstants.SYS_DICT_KEY + configKey; } } src/main/java/com/ruoyi/framework/aspectj/RateLimiterAspect.java
@@ -13,6 +13,7 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.script.RedisScript; import org.springframework.stereotype.Component; import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.ip.IpUtils; @@ -75,7 +76,7 @@ public String getCombineKey(RateLimiter rateLimiter, JoinPoint point) { StringBuffer stringBuffer = new StringBuffer(rateLimiter.key()); StringBuffer stringBuffer = new StringBuffer(CacheConstants.PREFIX).append(rateLimiter.key()); if (rateLimiter.limitType() == LimitType.IP) { stringBuffer.append(IpUtils.getIpAddr()).append("-"); src/main/java/com/ruoyi/framework/config/RedisKeyConfig.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,19 @@ package com.ruoyi.framework.config; import com.ruoyi.common.constant.CacheConstants; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import javax.annotation.PostConstruct; @Configuration public class RedisKeyConfig { @Value("${ruoyi.redis.keyPrefix:}") private String keyPrefix; @PostConstruct public void init() { CacheConstants.setPrefix(keyPrefix == null ? "" : keyPrefix.trim()); } } src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java
@@ -63,7 +63,7 @@ String submitKey = StringUtils.trimToEmpty(request.getHeader(header)); // å¯ä¸æ è¯ï¼æå®key + url + æ¶æ¯å¤´ï¼ String cacheRepeatKey = CacheConstants.REPEAT_SUBMIT_KEY + url + submitKey; String cacheRepeatKey = CacheConstants.PREFIX + CacheConstants.REPEAT_SUBMIT_KEY + url + submitKey; Object sessionObj = redisCache.getCacheObject(cacheRepeatKey); if (sessionObj != null) src/main/java/com/ruoyi/framework/security/service/SysLoginService.java
@@ -121,7 +121,7 @@ boolean captchaEnabled = configService.selectCaptchaEnabled(); if (captchaEnabled) { String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); String verifyKey = CacheConstants.PREFIX + CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); String captcha = redisCache.getCacheObject(verifyKey); if (captcha == null) { src/main/java/com/ruoyi/framework/security/service/SysPasswordService.java
@@ -38,7 +38,7 @@ */ private String getCacheKey(String username) { return CacheConstants.PWD_ERR_CNT_KEY + username; return CacheConstants.PREFIX + CacheConstants.PWD_ERR_CNT_KEY + username; } public void validate(SysUser user) src/main/java/com/ruoyi/framework/security/service/SysRegisterService.java
@@ -100,7 +100,7 @@ */ public void validateCaptcha(String username, String code, String uuid) { String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); String verifyKey = CacheConstants.PREFIX + CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); String captcha = redisCache.getCacheObject(verifyKey); redisCache.deleteObject(verifyKey); if (captcha == null) src/main/java/com/ruoyi/framework/security/service/TokenService.java
@@ -249,6 +249,6 @@ private String getTokenKey(String uuid) { return CacheConstants.LOGIN_TOKEN_KEY + uuid; return CacheConstants.PREFIX + CacheConstants.LOGIN_TOKEN_KEY + uuid; } } src/main/java/com/ruoyi/project/common/CaptchaController.java
@@ -60,7 +60,7 @@ // ä¿åéªè¯ç ä¿¡æ¯ String uuid = IdUtils.simpleUUID(); String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid; String verifyKey = CacheConstants.PREFIX + CacheConstants.CAPTCHA_CODE_KEY + uuid; String capStr = null, code = null; BufferedImage image = null; src/main/java/com/ruoyi/project/monitor/controller/CacheController.java
@@ -36,13 +36,13 @@ private final static List<SysCache> caches = new ArrayList<SysCache>(); { caches.add(new SysCache(CacheConstants.LOGIN_TOKEN_KEY, "ç¨æ·ä¿¡æ¯")); caches.add(new SysCache(CacheConstants.SYS_CONFIG_KEY, "é 置信æ¯")); caches.add(new SysCache(CacheConstants.SYS_DICT_KEY, "æ°æ®åå ¸")); caches.add(new SysCache(CacheConstants.CAPTCHA_CODE_KEY, "éªè¯ç ")); caches.add(new SysCache(CacheConstants.REPEAT_SUBMIT_KEY, "é²éæäº¤")); caches.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "éæµå¤ç")); caches.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "å¯ç é误次æ°")); caches.add(new SysCache(CacheConstants.PREFIX + CacheConstants.LOGIN_TOKEN_KEY, "ç¨æ·ä¿¡æ¯")); caches.add(new SysCache(CacheConstants.PREFIX + CacheConstants.SYS_CONFIG_KEY, "é 置信æ¯")); caches.add(new SysCache(CacheConstants.PREFIX + CacheConstants.SYS_DICT_KEY, "æ°æ®åå ¸")); caches.add(new SysCache(CacheConstants.PREFIX + CacheConstants.CAPTCHA_CODE_KEY, "éªè¯ç ")); caches.add(new SysCache(CacheConstants.PREFIX + CacheConstants.REPEAT_SUBMIT_KEY, "é²éæäº¤")); caches.add(new SysCache(CacheConstants.PREFIX + CacheConstants.RATE_LIMIT_KEY, "éæµå¤ç")); caches.add(new SysCache(CacheConstants.PREFIX + CacheConstants.PWD_ERR_CNT_KEY, "å¯ç é误次æ°")); } @PreAuthorize("@ss.hasPermi('monitor:cache:list')") src/main/java/com/ruoyi/project/monitor/controller/SysUserOnlineController.java
@@ -42,7 +42,7 @@ @GetMapping("/list") public TableDataInfo list(String ipaddr, String userName) { Collection<String> keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*"); Collection<String> keys = redisCache.keys(CacheConstants.PREFIX + CacheConstants.LOGIN_TOKEN_KEY + "*"); List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>(); for (String key : keys) { @@ -77,7 +77,7 @@ @DeleteMapping("/{tokenId}") public AjaxResult forceLogout(@PathVariable String tokenId) { redisCache.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + tokenId); redisCache.deleteObject(CacheConstants.PREFIX + CacheConstants.LOGIN_TOKEN_KEY + tokenId); return success(); } } src/main/java/com/ruoyi/project/system/service/impl/SysConfigServiceImpl.java
@@ -184,7 +184,7 @@ @Override public void clearConfigCache() { Collection<String> keys = redisCache.keys(CacheConstants.SYS_CONFIG_KEY + "*"); Collection<String> keys = redisCache.keys(CacheConstants.PREFIX + CacheConstants.SYS_CONFIG_KEY + "*"); redisCache.deleteObject(keys); } @@ -224,6 +224,6 @@ */ private String getCacheKey(String configKey) { return CacheConstants.SYS_CONFIG_KEY + configKey; return CacheConstants.PREFIX + CacheConstants.SYS_CONFIG_KEY + configKey; } } src/main/resources/application.yml
@@ -2,3 +2,6 @@ spring: profiles: active: xyyj ruoyi: redis: keyPrefix: ${spring.profiles.active}