mirror of
				https://github.com/continew-org/continew-starter.git
				synced 2025-10-31 10:57:15 +08:00 
			
		
		
		
	feat(cache/redisson): 添加条件性缓存设置方法 setIfAbsent、setIfExists
This commit is contained in:
		| @@ -62,6 +62,62 @@ public class RedisUtils { | ||||
|         CLIENT.getBucket(key).set(value, duration); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 设置缓存 | ||||
|      * | ||||
|      * <p>如果键已存在,则不设置</p> | ||||
|      * | ||||
|      * @param key   键 | ||||
|      * @param value 值 | ||||
|      * @return true:设置成功;false:设置失败 | ||||
|      * @since 2.10.0 | ||||
|      */ | ||||
|     public static <T> boolean setIfAbsent(String key, T value) { | ||||
|         return CLIENT.getBucket(key).setIfAbsent(value); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 设置缓存 | ||||
|      * | ||||
|      * <p>如果键已存在,则不设置</p> | ||||
|      * | ||||
|      * @param key      键 | ||||
|      * @param value    值 | ||||
|      * @param duration 过期时间 | ||||
|      * @return true:设置成功;false:设置失败 | ||||
|      * @since 2.10.0 | ||||
|      */ | ||||
|     public static <T> boolean setIfAbsent(String key, T value, Duration duration) { | ||||
|         return CLIENT.getBucket(key).setIfAbsent(value, duration); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 设置缓存 | ||||
|      * <p>如果键不存在,则不设置</p> | ||||
|      *  | ||||
|      * @param key   键 | ||||
|      * @param value 值 | ||||
|      * @return true:设置成功;false:设置失败 | ||||
|      * @since 2.10.0 | ||||
|      */ | ||||
|     public static <T> boolean setIfExists(String key, T value) { | ||||
|         return CLIENT.getBucket(key).setIfExists(value); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 设置缓存 | ||||
|      * <p>如果键不存在,则不设置</p> | ||||
|      *  | ||||
|      * @param key      键 | ||||
|      * @param value    值 | ||||
|      * @param duration 过期时间 | ||||
|      * @return true:设置成功;false:设置失败 | ||||
|      * @since 2.10.0 | ||||
|      */ | ||||
|     public static <T> boolean setIfExists(String key, T value, Duration duration) { | ||||
|         return CLIENT.getBucket(key).setIfExists(value, duration); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询指定缓存 | ||||
|      * | ||||
|   | ||||
		Reference in New Issue
	
	Block a user