From b6be6d55998824cb89fe15f5015076302a78b3f2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Sep 2024 04:46:25 +0000 Subject: [PATCH 1/3] Bump org.apache.maven.plugins:maven-pmd-plugin from 3.22.0 to 3.25.0 Bumps [org.apache.maven.plugins:maven-pmd-plugin](https://github.com/apache/maven-pmd-plugin) from 3.22.0 to 3.25.0. - [Release notes](https://github.com/apache/maven-pmd-plugin/releases) - [Commits](https://github.com/apache/maven-pmd-plugin/compare/maven-pmd-plugin-3.22.0...maven-pmd-plugin-3.25.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-pmd-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- redisson/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redisson/pom.xml b/redisson/pom.xml index 52f87b87c..284ca5561 100644 --- a/redisson/pom.xml +++ b/redisson/pom.xml @@ -487,7 +487,7 @@ org.apache.maven.plugins maven-pmd-plugin - 3.22.0 + 3.25.0 verify From 9211ef1923c5669d2ed29bfbc6460a7a5bcd7bab Mon Sep 17 00:00:00 2001 From: lyrric Date: Thu, 5 Sep 2024 18:36:06 +0800 Subject: [PATCH 2/3] Feature - add addIfAbsent(Map objects) method to RSetCache,RSetCacheRx,RSetCacheReactive Signed-off-by: lyrric --- .../java/org/redisson/RedissonSetCache.java | 31 +++++++++++++++++++ .../main/java/org/redisson/api/RSetCache.java | 11 ++++++- .../java/org/redisson/api/RSetCacheAsync.java | 11 ++++++- .../org/redisson/api/RSetCacheReactive.java | 13 ++++++++ .../java/org/redisson/api/RSetCacheRx.java | 11 ++++++- .../RedissonSetCacheReactiveTest.java | 26 +++++++++++++--- .../org/redisson/RedissonSetCacheTest.java | 18 +++++++++++ .../redisson/rx/RedissonSetCacheRxTest.java | 26 +++++++++++++--- 8 files changed, 134 insertions(+), 13 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonSetCache.java b/redisson/src/main/java/org/redisson/RedissonSetCache.java index 2cbb60545..289d23af8 100644 --- a/redisson/src/main/java/org/redisson/RedissonSetCache.java +++ b/redisson/src/main/java/org/redisson/RedissonSetCache.java @@ -1273,6 +1273,11 @@ public class RedissonSetCache extends RedissonExpirable implements RSetCache< return get(addAllIfAbsentAsync(objects)); } + @Override + public boolean addIfAbsent(Map objects) { + return get(addIfAbsentAsync(objects)); + } + @Override public int addAllIfExist(Map objects) { return get(addAllIfExistAsync(objects)); @@ -1314,7 +1319,33 @@ public class RedissonSetCache extends RedissonExpirable implements RSetCache< "return result; ", Arrays.asList(getRawName()), params.toArray()); } + @Override + public RFuture addIfAbsentAsync(Map objects) { + List params = new ArrayList<>(); + long currentTime = System.currentTimeMillis(); + params.add(currentTime); + for (Map.Entry entry : objects.entrySet()) { + long timeoutDate = currentTime + entry.getValue().toMillis(); + if (entry.getValue().isZero()) { + timeoutDate = 92233720368547758L - currentTime; + } + params.add(timeoutDate); + encode(params, entry.getKey()); + } + return commandExecutor.evalWriteAsync(getRawName(), codec, RedisCommands.EVAL_BOOLEAN, + "for i=2, #ARGV, 2 do " + + "local expireDateScore = redis.call('zscore', KEYS[1], ARGV[i+1]); " + + "if expireDateScore ~= false and tonumber(expireDateScore) > tonumber(ARGV[1]) then " + + "return 0; " + + "end; " + + "end; " + + "for i=2, #ARGV, 2 do " + + "redis.call('zadd', KEYS[1], ARGV[i], ARGV[i+1]); " + + "end; " + + "return 1; ", + Collections.singletonList(getRawName()), params.toArray()); + } @Override public RFuture addAllIfExistAsync(Map objects) { List params = new ArrayList<>(); diff --git a/redisson/src/main/java/org/redisson/api/RSetCache.java b/redisson/src/main/java/org/redisson/api/RSetCache.java index af796f4dc..c371fc842 100644 --- a/redisson/src/main/java/org/redisson/api/RSetCache.java +++ b/redisson/src/main/java/org/redisson/api/RSetCache.java @@ -62,7 +62,7 @@ public interface RSetCache extends RSet, RExpirable, RSetCacheAsync, RD int size(); /** - * Use {@link #addIfAbsent(Duration, Object)} instead + * Use {@link #addIfAbsent(Map)} instead * * @param values - values to add * @param ttl - time to live for value. @@ -136,6 +136,15 @@ public interface RSetCache extends RSet, RExpirable, RSetCacheAsync, RD * @return amount of added elements */ int addAllIfAbsent(Map objects); + /** + * Adds elements to this set only if all of them haven't been added before. + *

+ * Requires Redis 3.0.2 and higher. + * + * @param objects map of elements to add + * @return true if elements added and false if not. + */ + boolean addIfAbsent(Map objects); /** * Adds elements to this set only if they already exist. diff --git a/redisson/src/main/java/org/redisson/api/RSetCacheAsync.java b/redisson/src/main/java/org/redisson/api/RSetCacheAsync.java index cd582cdbb..63a2ccf2b 100644 --- a/redisson/src/main/java/org/redisson/api/RSetCacheAsync.java +++ b/redisson/src/main/java/org/redisson/api/RSetCacheAsync.java @@ -52,7 +52,7 @@ public interface RSetCacheAsync extends RSetAsync { RFuture sizeAsync(); /** - * Use {@link #addIfAbsentAsync(Duration, Object)} instead + * Use {@link #addIfAbsentAsync(Map)} instead * * @param values - values to add * @param ttl - time to live for value. @@ -126,6 +126,15 @@ public interface RSetCacheAsync extends RSetAsync { * @return amount of added elements */ RFuture addAllIfAbsentAsync(Map objects); + /** + * Adds elements to this set only if all of them haven't been added before. + *

+ * Requires Redis 3.0.2 and higher. + * + * @param objects map of elements to add + * @return amount of added elements + */ + RFuture addIfAbsentAsync(Map objects); /** * Adds elements to this set only if they already exist. diff --git a/redisson/src/main/java/org/redisson/api/RSetCacheReactive.java b/redisson/src/main/java/org/redisson/api/RSetCacheReactive.java index ddb1d0520..8640181e3 100644 --- a/redisson/src/main/java/org/redisson/api/RSetCacheReactive.java +++ b/redisson/src/main/java/org/redisson/api/RSetCacheReactive.java @@ -110,6 +110,8 @@ public interface RSetCacheReactive extends RCollectionReactive, RDestroyab Mono tryAdd(V... values); /** + * Use {@link #addIfAbsent(Map)} instead + * * Tries to add elements only if none of them in set. * * @param values - values to add @@ -119,6 +121,7 @@ public interface RSetCacheReactive extends RCollectionReactive, RDestroyab * @return true if elements successfully added, * otherwise false. */ + @Deprecated Mono tryAdd(long ttl, TimeUnit unit, V... values); /** @@ -132,6 +135,16 @@ public interface RSetCacheReactive extends RCollectionReactive, RDestroyab */ Mono addIfAbsent(Duration ttl, V object); + /** + * Adds elements to this set only if all of them haven't been added before. + *

+ * Requires Redis 3.0.2 and higher. + * + * @param objects map of elements to add + * @return true if elements added and false if not. + */ + Mono addIfAbsent(Map objects); + /** * Adds element to this set only if it's already exists. *

diff --git a/redisson/src/main/java/org/redisson/api/RSetCacheRx.java b/redisson/src/main/java/org/redisson/api/RSetCacheRx.java index 050474891..70cabf2ae 100644 --- a/redisson/src/main/java/org/redisson/api/RSetCacheRx.java +++ b/redisson/src/main/java/org/redisson/api/RSetCacheRx.java @@ -110,7 +110,7 @@ public interface RSetCacheRx extends RCollectionRx, RDestroyable { Single tryAdd(V... values); /** - * Use {@link #addIfAbsent(Duration, Object)} instead + * Use {@link #addIfAbsent(Map)} instead * * @param values - values to add * @param ttl - time to live for value. @@ -121,6 +121,15 @@ public interface RSetCacheRx extends RCollectionRx, RDestroyable { */ @Deprecated Single tryAdd(long ttl, TimeUnit unit, V... values); + /** + * Adds elements to this set only if all of them haven't been added before. + *

+ * Requires Redis 3.0.2 and higher. + * + * @param objects map of elements to add + * @return true if elements added and false if not. + */ + Single addIfAbsent(Map objects); /** * Adds element to this set only if has not been added before. diff --git a/redisson/src/test/java/org/redisson/RedissonSetCacheReactiveTest.java b/redisson/src/test/java/org/redisson/RedissonSetCacheReactiveTest.java index 33eb597be..af5a31d70 100644 --- a/redisson/src/test/java/org/redisson/RedissonSetCacheReactiveTest.java +++ b/redisson/src/test/java/org/redisson/RedissonSetCacheReactiveTest.java @@ -3,11 +3,8 @@ package org.redisson; import static org.assertj.core.api.Assertions.assertThat; import java.io.Serializable; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; +import java.time.Duration; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -321,4 +318,23 @@ public class RedissonSetCacheReactiveTest extends BaseReactiveTest { } + @Test + public void testAddIfAbsentWithMapParam() throws InterruptedException { + sync(redisson.getKeys().flushall()); + RSetCacheReactive cache = redisson.getSetCache("cache"); + Map map = new HashMap<>(); + map.put("key1", Duration.ofMinutes(1)); + map.put("key2", Duration.ofMinutes(1)); + assertThat(sync(cache.addIfAbsent(map))).isTrue(); + map = new HashMap<>(); + map.put("key1", Duration.ofMinutes(1)); + assertThat(sync(cache.addIfAbsent(map))).isFalse(); + map = new HashMap<>(); + map.put("key3", Duration.ofSeconds(1)); + assertThat(sync(cache.addIfAbsent(map))).isTrue(); + Thread.sleep(1200); + assertThat(sync(cache.addIfAbsent(map))).isTrue(); + sync((redisson.getKeys().flushall())); + } + } diff --git a/redisson/src/test/java/org/redisson/RedissonSetCacheTest.java b/redisson/src/test/java/org/redisson/RedissonSetCacheTest.java index 8940be75a..b96342e4d 100644 --- a/redisson/src/test/java/org/redisson/RedissonSetCacheTest.java +++ b/redisson/src/test/java/org/redisson/RedissonSetCacheTest.java @@ -697,4 +697,22 @@ public class RedissonSetCacheTest extends RedisDockerTest { }, NOTIFY_KEYSPACE_EVENTS, "Ez"); } + @Test + public void testAddIfAbsentWithMapParam() throws InterruptedException { + redisson.getKeys().flushall(); + RSetCache cache = redisson.getSetCache("cache"); + Map map = new HashMap<>(); + map.put("key1", Duration.ofMinutes(1)); + map.put("key2", Duration.ofMinutes(1)); + assertThat(cache.addIfAbsent(map)).isTrue(); + map = new HashMap<>(); + map.put("key1", Duration.ofMinutes(1)); + assertThat(cache.addIfAbsent(map)).isFalse(); + map = new HashMap<>(); + map.put("key3", Duration.ofSeconds(1)); + assertThat(cache.addIfAbsent(map)).isTrue(); + Thread.sleep(1200); + assertThat(cache.addIfAbsent(map)).isTrue(); + redisson.getKeys().flushall(); + } } diff --git a/redisson/src/test/java/org/redisson/rx/RedissonSetCacheRxTest.java b/redisson/src/test/java/org/redisson/rx/RedissonSetCacheRxTest.java index 715fb8140..29e35da0d 100644 --- a/redisson/src/test/java/org/redisson/rx/RedissonSetCacheRxTest.java +++ b/redisson/src/test/java/org/redisson/rx/RedissonSetCacheRxTest.java @@ -3,17 +3,15 @@ package org.redisson.rx; import static org.assertj.core.api.Assertions.assertThat; import java.io.Serializable; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; +import java.time.Duration; +import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.redisson.TestObject; +import org.redisson.api.RSetCacheReactive; import org.redisson.api.RSetCacheRx; public class RedissonSetCacheRxTest extends BaseRxTest { @@ -290,5 +288,23 @@ public class RedissonSetCacheRxTest extends BaseRxTest { Assertions.assertEquals(0, sync(cache.size()).intValue()); } + @Test + public void testAddIfAbsentWithMapParam() throws InterruptedException { + sync(redisson.getKeys().flushall()); + RSetCacheRx cache = redisson.getSetCache("cache"); + Map map = new HashMap<>(); + map.put("key1", Duration.ofMinutes(1)); + map.put("key2", Duration.ofMinutes(1)); + assertThat(sync(cache.addIfAbsent(map))).isTrue(); + map = new HashMap<>(); + map.put("key1", Duration.ofMinutes(1)); + assertThat(sync(cache.addIfAbsent(map))).isFalse(); + map = new HashMap<>(); + map.put("key3", Duration.ofSeconds(1)); + assertThat(sync(cache.addIfAbsent(map))).isTrue(); + Thread.sleep(1200); + assertThat(sync(cache.addIfAbsent(map))).isTrue(); + sync((redisson.getKeys().flushall())); + } } From b2a24c77aa495725f048752b51736a2f93a07a70 Mon Sep 17 00:00:00 2001 From: lyrric Date: Fri, 6 Sep 2024 15:09:52 +0800 Subject: [PATCH 3/3] Fixed - Keep the jmockit version in the plugin consistent with that in the dependencies. Signed-off-by: lyrric --- redisson-spring-data/redisson-spring-data-32/pom.xml | 2 +- redisson-spring-data/redisson-spring-data-33/pom.xml | 2 +- redisson/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/redisson-spring-data/redisson-spring-data-32/pom.xml b/redisson-spring-data/redisson-spring-data-32/pom.xml index a1221db16..297d6371e 100644 --- a/redisson-spring-data/redisson-spring-data-32/pom.xml +++ b/redisson-spring-data/redisson-spring-data-32/pom.xml @@ -48,7 +48,7 @@ 4 true - ${argLine} -javaagent:"${settings.localRepository}"/com/github/hazendaz/jmockit/jmockit/1.52.0/jmockit-1.52.0.jar + ${argLine} -javaagent:"${settings.localRepository}"/com/github/hazendaz/jmockit/jmockit/1.54.0/jmockit-1.54.0.jar diff --git a/redisson-spring-data/redisson-spring-data-33/pom.xml b/redisson-spring-data/redisson-spring-data-33/pom.xml index 8935ced3f..dec0100d1 100644 --- a/redisson-spring-data/redisson-spring-data-33/pom.xml +++ b/redisson-spring-data/redisson-spring-data-33/pom.xml @@ -48,7 +48,7 @@ 4 true - ${argLine} -javaagent:"${settings.localRepository}"/com/github/hazendaz/jmockit/jmockit/1.52.0/jmockit-1.52.0.jar + ${argLine} -javaagent:"${settings.localRepository}"/com/github/hazendaz/jmockit/jmockit/1.54.0/jmockit-1.54.0.jar diff --git a/redisson/pom.xml b/redisson/pom.xml index 284ca5561..4130937f7 100644 --- a/redisson/pom.xml +++ b/redisson/pom.xml @@ -527,7 +527,7 @@ 4 false - ${argLine} -javaagent:"${settings.localRepository}"/com/github/hazendaz/jmockit/jmockit/1.52.0/jmockit-1.52.0.jar + ${argLine} -javaagent:"${settings.localRepository}"/com/github/hazendaz/jmockit/jmockit/1.54.0/jmockit-1.54.0.jar