mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	update 优化 setCacheObject 简化写法
This commit is contained in:
		@@ -129,9 +129,9 @@ public class RedisUtils {
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                long timeToLive = bucket.remainTimeToLive();
 | 
			
		||||
                if (timeToLive == -1) {
 | 
			
		||||
                    setCacheObject(key, value);
 | 
			
		||||
                    bucket.set(value);
 | 
			
		||||
                } else {
 | 
			
		||||
                    setCacheObject(key, value, Duration.ofMillis(timeToLive));
 | 
			
		||||
                    bucket.set(value, Duration.ofMillis(timeToLive));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
@@ -147,11 +147,8 @@ public class RedisUtils {
 | 
			
		||||
     * @param duration 时间
 | 
			
		||||
     */
 | 
			
		||||
    public static <T> void setCacheObject(final String key, final T value, final Duration duration) {
 | 
			
		||||
        RBatch batch = CLIENT.createBatch();
 | 
			
		||||
        RBucketAsync<T> bucket = batch.getBucket(key);
 | 
			
		||||
        bucket.setAsync(value);
 | 
			
		||||
        bucket.expireAsync(duration);
 | 
			
		||||
        batch.execute();
 | 
			
		||||
        RBucket<T> bucket = CLIENT.getBucket(key);
 | 
			
		||||
        bucket.set(value, duration);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user