From cc9b39c5a7df8c5080a9f31292f8c03aed29fd24 Mon Sep 17 00:00:00 2001 From: chenjiahe <763432473@qq.com> Date: 星期五, 01 七月 2022 11:30:22 +0800 Subject: [PATCH] 更换redis --- src/main/java/com/hx/redisson/config/RedissonUtil.java | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/hx/redisson/config/RedissonUtil.java b/src/main/java/com/hx/redisson/config/RedissonUtil.java index 9f2adfa..95f98d6 100644 --- a/src/main/java/com/hx/redisson/config/RedissonUtil.java +++ b/src/main/java/com/hx/redisson/config/RedissonUtil.java @@ -407,6 +407,38 @@ return redisTemplate.opsForValue().increment(key, -delta); } + + /**濡傛灉鍊煎瓨鍦ㄥ氨涓嶅瓨鍏ワ紝濡傛灉涓嶅瓨鍦ㄥ氨瀛樺叆 + * @param key 閿� + * @param value 鍊� + * @param timeOut 鏃堕棿 + * @param unit 鏃堕棿鍗曚綅 + */ + public Boolean setIfAbsent(String key, Object value, long timeOut, TimeUnit unit) { + try { + return redisTemplate.opsForValue().setIfAbsent(key, value, timeOut, unit); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /**濡傛灉鍊煎瓨鍦ㄥ氨涓嶅瓨鍏ワ紝濡傛灉涓嶅瓨鍦ㄥ氨瀛樺叆 + * @param key 閿� + * @param value 鍊� + * @param timeOut 鏃堕棿 + * @param unit 鏃堕棿鍗曚綅 + */ + public Boolean setIfAbsent(String key, Object value, long timeOut, TimeUnit unit,int db) { + try { + RedisTemplate redisTemplate = redisManager.getRedisTemplate(db); + return redisTemplate.opsForValue().setIfAbsent(key, value, timeOut, unit); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + // ================================Map================================= /** -- Gitblit v1.8.0