mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 08:13:44 +08:00 
			
		
		
		
	!592 替换RedisUtils中的过时方法
* update:替换RedisUtils中的废弃方法getKeysStreamByPattern及trySetRate
This commit is contained in:
		@@ -4,6 +4,7 @@ import lombok.AccessLevel;
 | 
			
		||||
import lombok.NoArgsConstructor;
 | 
			
		||||
import org.dromara.common.core.utils.SpringUtils;
 | 
			
		||||
import org.redisson.api.*;
 | 
			
		||||
import org.redisson.api.options.KeysScanOptions;
 | 
			
		||||
 | 
			
		||||
import java.time.Duration;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
@@ -37,7 +38,7 @@ public class RedisUtils {
 | 
			
		||||
     */
 | 
			
		||||
    public static long rateLimiter(String key, RateType rateType, int rate, int rateInterval) {
 | 
			
		||||
        RRateLimiter rateLimiter = CLIENT.getRateLimiter(key);
 | 
			
		||||
        rateLimiter.trySetRate(rateType, rate, rateInterval, RateIntervalUnit.SECONDS);
 | 
			
		||||
        rateLimiter.trySetRate(rateType, rate, Duration.ofSeconds(rateInterval));
 | 
			
		||||
        if (rateLimiter.tryAcquire()) {
 | 
			
		||||
            return rateLimiter.availablePermits();
 | 
			
		||||
        } else {
 | 
			
		||||
@@ -518,13 +519,34 @@ public class RedisUtils {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获得缓存的基本对象列表(全局匹配忽略租户 自行拼接租户id)
 | 
			
		||||
     *
 | 
			
		||||
     * <P>
 | 
			
		||||
     * limit-设置扫描的限制数量(默认为0,查询全部)
 | 
			
		||||
     * pattern-设置键的匹配模式(默认为null)
 | 
			
		||||
     * chunkSize-设置每次扫描的块大小(默认为0,本方法设置为1000)
 | 
			
		||||
     * type-设置键的类型(默认为null,查询全部类型)
 | 
			
		||||
     * </P>
 | 
			
		||||
     * @see KeysScanOptions
 | 
			
		||||
     * @param pattern 字符串前缀
 | 
			
		||||
     * @return 对象列表
 | 
			
		||||
     */
 | 
			
		||||
    public static Collection<String> keys(final String pattern) {
 | 
			
		||||
        Stream<String> stream = CLIENT.getKeys().getKeysStreamByPattern(pattern);
 | 
			
		||||
        return stream.collect(Collectors.toList());
 | 
			
		||||
        return  keys(KeysScanOptions.defaults().pattern(pattern).chunkSize(1000));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 通过扫描参数获取缓存的基本对象列表
 | 
			
		||||
     * @param keysScanOptions 扫描参数
 | 
			
		||||
     * <P>
 | 
			
		||||
     * limit-设置扫描的限制数量(默认为0,查询全部)
 | 
			
		||||
     * pattern-设置键的匹配模式(默认为null)
 | 
			
		||||
     * chunkSize-设置每次扫描的块大小(默认为0)
 | 
			
		||||
     * type-设置键的类型(默认为null,查询全部类型)
 | 
			
		||||
     * </P>
 | 
			
		||||
     * @see KeysScanOptions
 | 
			
		||||
     */
 | 
			
		||||
    public static Collection<String> keys(final KeysScanOptions keysScanOptions) {
 | 
			
		||||
        Stream<String> keysStream = CLIENT.getKeys().getKeysStream(keysScanOptions);
 | 
			
		||||
        return keysStream.collect(Collectors.toList());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user