diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java index 7617df63d..3dbef2de5 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -1295,15 +1295,6 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco return convertAndReturn(delegate.zIncrBy(key, increment, value), identityConverter); } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, int[], byte[][]) - */ - @Override - public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - return convertAndReturn(delegate.zInterStore(destKey, aggregate, weights, sets), identityConverter); - } - /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][]) @@ -1565,14 +1556,6 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco return convertAndReturn(delegate.zScore(key, value), identityConverter); } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, int[], byte[][]) - */ - public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - return convertAndReturn(delegate.zUnionStore(destKey, aggregate, weights, sets), identityConverter); - } - /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][]) diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveZSetCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveZSetCommands.java index 70d4a2ebb..b3e2b60ff 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReactiveZSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/ReactiveZSetCommands.java @@ -1375,7 +1375,7 @@ public interface ReactiveZSetCommands { * @since 2.1 */ public ZUnionStoreCommand applyWeights(Weights weights) { - return new ZUnionStoreCommand(getKey(), sourceKeys, weights.toList(), aggregateFunction); + return applyWeights(weights.toList()); } /** @@ -1575,7 +1575,7 @@ public interface ReactiveZSetCommands { * @since 2.1 */ public ZInterStoreCommand applyWeights(Weights weights) { - return new ZInterStoreCommand(getKey(), sourceKeys, weights.toList(), aggregateFunction); + return applyWeights(weights.toList()); } /** diff --git a/src/main/java/org/springframework/data/redis/connection/RedisZSetCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisZSetCommands.java index 3b6655197..f50025070 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisZSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisZSetCommands.java @@ -16,9 +16,11 @@ package org.springframework.data.redis.connection; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Set; import java.util.function.DoubleUnaryOperator; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.DoubleStream; import java.util.stream.IntStream; @@ -51,13 +53,14 @@ public interface RedisZSetCommands { * element in every input sorted set is multiplied by this factor before being passed to the aggregation function. * * @author Mark Paluch + * @author Christoph Strobl * @since 2.1 */ class Weights { - private final double[] weights; + private final List weights; - Weights(double[] weights) { + private Weights(List weights) { this.weights = weights; } @@ -70,7 +73,7 @@ public interface RedisZSetCommands { public static Weights of(int... weights) { Assert.notNull(weights, "Weights must not be null!"); - return new Weights(Arrays.stream(weights).mapToDouble(value -> value).toArray()); + return new Weights(Arrays.stream(weights).mapToDouble(value -> value).boxed().collect(Collectors.toList())); } /** @@ -83,7 +86,7 @@ public interface RedisZSetCommands { Assert.notNull(weights, "Weights must not be null!"); - return new Weights(Arrays.copyOf(weights, weights.length)); + return new Weights(DoubleStream.of(weights).boxed().collect(Collectors.toList())); } /** @@ -96,7 +99,7 @@ public interface RedisZSetCommands { Assert.isTrue(count >= 0, "Count of input sorted sets must be greater or equal to zero!"); - return new Weights(IntStream.range(0, count).mapToDouble(value -> 1).toArray()); + return new Weights(IntStream.range(0, count).mapToDouble(value -> 1).boxed().collect(Collectors.toList())); } /** @@ -120,13 +123,13 @@ public interface RedisZSetCommands { } /** - * Creates a new {@link Weights} object that contains all weights with {@link DoubleUnaryOperator} applied. + * Creates a new {@link Weights} object that contains all weights with {@link Function} applied. * * @param operator operator function. * @return the new {@link Weights} with {@link DoubleUnaryOperator} applied. */ - public Weights apply(DoubleUnaryOperator operator) { - return new Weights(DoubleStream.of(weights).map(operator).toArray()); + public Weights apply(Function operator) { + return new Weights(weights.stream().map(operator).collect(Collectors.toList())); } /** @@ -137,26 +140,21 @@ public interface RedisZSetCommands { * @throws IndexOutOfBoundsException if the index is out of range */ public double getWeight(int index) { - - if (index > size() || index < 0) { - throw new IndexOutOfBoundsException("No such weight"); - } - - return weights[index]; + return weights.get(index); } /** * @return number of weights. */ public int size() { - return weights.length; + return weights.size(); } /** * @return an array containing all of the weights in this list in proper sequence (from first to last element). */ public double[] toArray() { - return Arrays.copyOf(weights, weights.length); + return weights.stream().mapToDouble(Double::doubleValue).toArray(); } /** @@ -164,7 +162,7 @@ public interface RedisZSetCommands { * element). */ public List toList() { - return Arrays.stream(weights).boxed().collect(Collectors.toList()); + return Collections.unmodifiableList(weights); } } @@ -821,7 +819,9 @@ public interface RedisZSetCommands { * @see Redis Documentation: ZUNIONSTORE */ @Nullable - Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets); + default Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + return zUnionStore(destKey, aggregate, Weights.of(weights), sets); + } /** * Union sorted {@code sets} and store result in destination {@code key}. @@ -859,7 +859,9 @@ public interface RedisZSetCommands { * @see Redis Documentation: ZINTERSTORE */ @Nullable - Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets); + default Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + return zInterStore(destKey, aggregate, Weights.of(weights), sets); + } /** * Intersect sorted {@code sets} and store result in destination {@code key}. diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterZSetCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterZSetCommands.java index 47488958a..a0ec30ad3 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterZSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterZSetCommands.java @@ -625,15 +625,6 @@ class JedisClusterZSetCommands implements RedisZSetCommands { throw new InvalidDataAccessApiUsageException("ZUNIONSTORE can only be executed when all keys map to the same slot"); } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, int[], byte[][]) - */ - @Override - public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - return zUnionStore(destKey, aggregate, Weights.of(weights), sets); - } - /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][]) @@ -689,14 +680,6 @@ class JedisClusterZSetCommands implements RedisZSetCommands { throw new InvalidDataAccessApiUsageException("ZINTERSTORE can only be executed when all keys map to the same slot"); } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, int[], byte[][]) - */ - @Override - public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - return zInterStore(destKey, aggregate, Weights.of(weights), sets); - } /* * (non-Javadoc) diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisZSetCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisZSetCommands.java index 7d36a1647..3207025ce 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisZSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisZSetCommands.java @@ -579,15 +579,6 @@ class JedisZSetCommands implements RedisZSetCommands { } } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, int[], byte[][]) - */ - @Override - public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - return zUnionStore(destKey, aggregate, Weights.of(weights), sets); - } - /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][]) @@ -646,15 +637,6 @@ class JedisZSetCommands implements RedisZSetCommands { } } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, int[], byte[][]) - */ - @Override - public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - return zInterStore(destKey, aggregate, Weights.of(weights), sets); - } - /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][]) diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceZSetCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceZSetCommands.java index d2da37e75..e036e622c 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceZSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceZSetCommands.java @@ -569,15 +569,6 @@ class LettuceZSetCommands implements RedisZSetCommands { } } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, int[], byte[][]) - */ - @Override - public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - return zUnionStore(destKey, aggregate, Weights.of(weights), sets); - } - /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][]) @@ -634,15 +625,6 @@ class LettuceZSetCommands implements RedisZSetCommands { } } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, int[], byte[][]) - */ - @Override - public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - return zInterStore(destKey, aggregate, Weights.of(weights), sets); - } - /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][]) diff --git a/src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java b/src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java index 2e59a8372..9101933a6 100644 --- a/src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java @@ -32,7 +32,7 @@ import org.springframework.lang.Nullable; * @author Costin Leau * @author Christoph Strobl * @author Mark Paluch - * @author Wongoo + * @author Wongoo (望哥) */ public interface BoundZSetOperations extends BoundKeyOperations { diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java index 2244d382b..a97f456d2 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java @@ -32,7 +32,7 @@ import org.springframework.data.redis.core.ZSetOperations.TypedTuple; * @author Costin Leau * @author Christoph Strobl * @author Mark Paluch - * @author wongoo + * @author Wongoo (望哥) */ class DefaultBoundZSetOperations extends DefaultBoundKeyOperations implements BoundZSetOperations { diff --git a/src/main/java/org/springframework/data/redis/core/DefaultReactiveZSetOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultReactiveZSetOperations.java index ef97deed4..6c9c46f84 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultReactiveZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultReactiveZSetOperations.java @@ -373,18 +373,6 @@ class DefaultReactiveZSetOperations implements ReactiveZSetOperations connection.zUnionStore(rawKey(destKey), serialized))); } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveZSetOperations#unionAndStore(java.lang.Object, java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate) - */ - @Override - public Mono unionAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate) { - - Assert.notNull(otherKeys, "Other keys must not be null!"); - - return unionAndStore(key, otherKeys, destKey, aggregate, Weights.fromSetCount(1 + otherKeys.size())); - } - /* * (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#unionAndStore(java.lang.Object, java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights) @@ -435,18 +423,6 @@ class DefaultReactiveZSetOperations implements ReactiveZSetOperations connection.zInterStore(rawKey(destKey), serialized))); } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveZSetOperations#intersectAndStore(java.lang.Object, java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate) - */ - @Override - public Mono intersectAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate) { - - Assert.notNull(otherKeys, "Other keys must not be null!"); - - return intersectAndStore(key, otherKeys, destKey, aggregate, Weights.fromSetCount(1 + otherKeys.size())); - } - /* * (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#intersectAndStore(java.lang.Object, java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights) diff --git a/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java index f1fb1e565..67efb3b4d 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java @@ -33,7 +33,7 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Weights; * @author Thomas Darimont * @author David Liu * @author Mark Paluch - * @author wongoo + * @author Wongoo (望哥) */ class DefaultZSetOperations extends AbstractOperations implements ZSetOperations { @@ -99,15 +99,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return execute(connection -> connection.zInterStore(rawDestKey, rawKeys), true); } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.core.ZSetOperations#intersectAndStore(java.lang.Object, java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate) - */ - @Override - public Long intersectAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate) { - return intersectAndStore(key, otherKeys, destKey, aggregate, Weights.fromSetCount(1 + otherKeys.size())); - } - /* * (non-Javadoc) * @see org.springframework.data.redis.core.ZSetOperations#intersectAndStore(java.lang.Object, java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights) @@ -433,15 +424,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return execute(connection -> connection.zUnionStore(rawDestKey, rawKeys), true); } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.core.ZSetOperations#unionAndStore(java.lang.Object, java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate) - */ - @Override - public Long unionAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate) { - return unionAndStore(key, otherKeys, destKey, aggregate, Weights.fromSetCount(1 + otherKeys.size())); - } - /* * (non-Javadoc) * @see org.springframework.data.redis.core.ZSetOperations#unionAndStore(java.lang.Object, java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights) diff --git a/src/main/java/org/springframework/data/redis/core/ReactiveZSetOperations.java b/src/main/java/org/springframework/data/redis/core/ReactiveZSetOperations.java index 3468118ac..f1262c96f 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveZSetOperations.java @@ -310,7 +310,9 @@ public interface ReactiveZSetOperations { * @since 2.1 * @see Redis Documentation: ZUNIONSTORE */ - Mono unionAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate); + default Mono unionAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate) { + return unionAndStore(key, otherKeys, destKey, aggregate, Weights.fromSetCount(1 + otherKeys.size())); + } /** * Union sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}. @@ -359,7 +361,9 @@ public interface ReactiveZSetOperations { * @since 2.1 * @see Redis Documentation: ZINTERSTORE */ - Mono intersectAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate); + default Mono intersectAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate) { + return intersectAndStore(key, otherKeys, destKey, aggregate, Weights.fromSetCount(1 + otherKeys.size())); + } /** * Intersect sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}. diff --git a/src/main/java/org/springframework/data/redis/core/ZSetOperations.java b/src/main/java/org/springframework/data/redis/core/ZSetOperations.java index 94a1c3640..78d34fad2 100644 --- a/src/main/java/org/springframework/data/redis/core/ZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ZSetOperations.java @@ -32,7 +32,7 @@ import org.springframework.lang.Nullable; * @author Christoph Strobl * @author Mark Paluch * @author Rosty Kerei - * @author wongoo + * @author Wongoo (望哥) */ public interface ZSetOperations { @@ -378,7 +378,9 @@ public interface ZSetOperations { * @see Redis Documentation: ZUNIONSTORE */ @Nullable - Long unionAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate); + default Long unionAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate) { + return unionAndStore(key, otherKeys, destKey, aggregate, Weights.fromSetCount(1 + otherKeys.size())); + } /** * Union sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}. @@ -431,7 +433,9 @@ public interface ZSetOperations { * @see Redis Documentation: ZINTERSTORE */ @Nullable - Long intersectAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate); + default Long intersectAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate) { + return intersectAndStore(key, otherKeys, destKey, aggregate, Weights.fromSetCount(1 + otherKeys.size())); + } /** * Intersect sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}. diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java index a693e7351..9618876bd 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java @@ -18,7 +18,16 @@ package org.springframework.data.redis.connection; import static org.junit.Assert.*; import static org.mockito.Mockito.*; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; import java.util.concurrent.TimeUnit; import org.junit.Before; @@ -38,6 +47,7 @@ import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOpt import org.springframework.data.redis.connection.RedisStringCommands.BitOperation; import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; import org.springframework.data.redis.connection.RedisZSetCommands.Tuple; +import org.springframework.data.redis.connection.RedisZSetCommands.Weights; import org.springframework.data.redis.connection.StringRedisConnection.StringTuple; import org.springframework.data.redis.connection.convert.Converters; import org.springframework.data.redis.serializer.StringRedisSerializer; @@ -1286,14 +1296,14 @@ public class DefaultStringRedisConnectionTests { @Test public void testZInterStoreAggWeightsBytes() { - doReturn(5l).when(nativeConnection).zInterStore(fooBytes, Aggregate.MAX, new int[0], fooBytes); + doReturn(5l).when(nativeConnection).zInterStore(eq(fooBytes), eq(Aggregate.MAX), any(Weights.class), eq(fooBytes)); actual.add(connection.zInterStore(fooBytes, Aggregate.MAX, new int[0], fooBytes)); verifyResults(Arrays.asList(new Object[] { 5l })); } @Test public void testZInterStoreAggWeights() { - doReturn(5l).when(nativeConnection).zInterStore(fooBytes, Aggregate.MAX, new int[0], fooBytes); + doReturn(5l).when(nativeConnection).zInterStore(eq(fooBytes), eq(Aggregate.MAX), any(Weights.class), eq(fooBytes)); actual.add(connection.zInterStore(foo, Aggregate.MAX, new int[0], foo)); verifyResults(Arrays.asList(new Object[] { 5l })); } @@ -1566,14 +1576,14 @@ public class DefaultStringRedisConnectionTests { @Test public void testZUnionStoreAggWeightsBytes() { - doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, Aggregate.MAX, new int[0], fooBytes); + doReturn(5l).when(nativeConnection).zUnionStore(eq(fooBytes), eq(Aggregate.MAX), any(Weights.class), eq(fooBytes)); actual.add(connection.zUnionStore(fooBytes, Aggregate.MAX, new int[0], fooBytes)); verifyResults(Arrays.asList(new Object[] { 5l })); } @Test public void testZUnionStoreAggWeights() { - doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, Aggregate.MAX, new int[0], fooBytes); + doReturn(5l).when(nativeConnection).zUnionStore(eq(fooBytes), eq(Aggregate.MAX), any(Weights.class), eq(fooBytes)); actual.add(connection.zUnionStore(foo, Aggregate.MAX, new int[0], foo)); verifyResults(Arrays.asList(new Object[] { 5l })); } @@ -1785,8 +1795,7 @@ public class DefaultStringRedisConnectionTests { @Test // DATAREDIS-438 public void testGeoAddWithGeoLocationBytes() { - doReturn(1l).when(nativeConnection).geoAdd(fooBytes, - new GeoLocation<>(barBytes, new Point(1.23232, 34.2342434))); + doReturn(1l).when(nativeConnection).geoAdd(fooBytes, new GeoLocation<>(barBytes, new Point(1.23232, 34.2342434))); actual.add(connection.geoAdd(fooBytes, new GeoLocation<>(barBytes, new Point(1.23232, 34.2342434)))); verifyResults(Collections.singletonList(1L)); diff --git a/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java b/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java index dd2960530..c2a9c2ff6 100644 --- a/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java @@ -840,10 +840,6 @@ public class RedisConnectionUnitTests { return delegate.zUnionStore(destKey, sets); } - public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - return delegate.zUnionStore(destKey, aggregate, weights, sets); - } - public Long zUnionStore(byte[] destKey, Aggregate aggregate, Weights weights, byte[]... sets) { return delegate.zUnionStore(destKey, aggregate, weights, sets); } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java index a61944241..f27c6c2ae 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java @@ -53,7 +53,7 @@ import org.springframework.test.annotation.IfProfileValue; * @author Jennifer Hickey * @author Christoph Strobl * @author Mark Paluch - * @author wongoo + * @author Wongoo (望哥) * @param Key type * @param Value type */ @@ -379,7 +379,6 @@ public class DefaultZSetOperationsTests { zSetOps.add(key1, value2, 2.0); zSetOps.add(key2, value2, 3.0); - zSetOps.unionAndStore(key1, Collections.singletonList(key2), key1, RedisZSetCommands.Aggregate.MIN); assertThat(zSetOps.score(key1, value2), closeTo(2.0, 0.1));