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 5976e1ed6..25cbb33df 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -25,7 +25,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.core.convert.converter.Converter; -import org.springframework.data.domain.Range; import org.springframework.data.geo.Circle; import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResults; @@ -49,6 +48,7 @@ import org.springframework.data.redis.connection.stream.StreamInfo.XInfoStream; import org.springframework.data.redis.connection.stream.StreamOffset; import org.springframework.data.redis.connection.stream.StreamReadOptions; import org.springframework.data.redis.connection.stream.StringRecord; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.DefaultTuple; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.Weights; diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java index 1968d5ea7..cc7d4288e 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java @@ -23,7 +23,6 @@ import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.springframework.data.domain.Range; import org.springframework.data.geo.Circle; import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResults; @@ -41,6 +40,7 @@ import org.springframework.data.redis.connection.stream.StreamInfo.XInfoGroups; import org.springframework.data.redis.connection.stream.StreamInfo.XInfoStream; import org.springframework.data.redis.connection.stream.StreamOffset; import org.springframework.data.redis.connection.stream.StreamReadOptions; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.Weights; import org.springframework.data.redis.core.Cursor; 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 0b7de03e1..bc0607d70 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReactiveZSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/ReactiveZSetCommands.java @@ -33,7 +33,7 @@ import java.util.function.Function; import org.reactivestreams.Publisher; import org.springframework.data.domain.Range; import org.springframework.data.domain.Sort.Direction; -import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.DefaultTuple; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.Weights; 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 346fd13a2..3ca6e47b4 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisZSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisZSetCommands.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.Weights; import org.springframework.data.redis.core.Cursor; @@ -41,14 +42,8 @@ import org.springframework.util.ObjectUtils; public interface RedisZSetCommands { /** - * Sort aggregation operations. - */ - enum Aggregate { - SUM, MIN, MAX; - } - - /** - * {@link Range} defines {@literal min} and {@literal max} values to retrieve from a {@literal ZSET}. + * {@link org.springframework.data.domain.Range} defines {@literal min} and {@literal max} values to retrieve from a + * {@literal ZSET}. * * @author Christoph Strobl * @since 1.6 @@ -61,14 +56,15 @@ public interface RedisZSetCommands { @Nullable Boundary max; /** - * @return new {@link Range} + * @return new {@link org.springframework.data.domain.Range} */ public static Range range() { return new Range(); } /** - * @return new {@link Range} with {@literal min} and {@literal max} set to {@link Boundary#infinite()}. + * @return new {@link org.springframework.data.domain.Range} with {@literal min} and {@literal max} set to + * {@link Boundary#infinite()}. */ public static Range unbounded() { @@ -963,7 +959,7 @@ public interface RedisZSetCommands { Long zRemRange(byte[] key, long start, long end); /** - * Remove all elements between the lexicographical {@link Range}. + * Remove all elements between the lexicographical {@link org.springframework.data.domain.Range}. * * @param key must not be {@literal null}. * @param range must not be {@literal null}. @@ -1299,7 +1295,8 @@ public interface RedisZSetCommands { } /** - * Get all the elements in {@link Range} from the sorted set at {@literal key} in lexicographical ordering. + * Get all the elements in {@link org.springframework.data.domain.Range} from the sorted set at {@literal key} in + * lexicographical ordering. * * @param key must not be {@literal null}. * @param range must not be {@literal null}. @@ -1313,8 +1310,8 @@ public interface RedisZSetCommands { } /** - * Get all the elements in {@link Range} from the sorted set at {@literal key} in lexicographical ordering. Result is - * limited via {@link Limit}. + * Get all the elements in {@link org.springframework.data.domain.Range} from the sorted set at {@literal key} in + * lexicographical ordering. Result is limited via {@link Limit}. * * @param key must not be {@literal null}. * @param range must not be {@literal null}. @@ -1341,7 +1338,8 @@ public interface RedisZSetCommands { } /** - * Get all the elements in {@link Range} from the sorted set at {@literal key} in reversed lexicographical ordering. + * Get all the elements in {@link org.springframework.data.domain.Range} from the sorted set at {@literal key} in + * reversed lexicographical ordering. * * @param key must not be {@literal null}. * @param range must not be {@literal null}. @@ -1355,8 +1353,8 @@ public interface RedisZSetCommands { } /** - * Get all the elements in {@link Range} from the sorted set at {@literal key} in reversed lexicographical ordering. - * Result is limited via {@link Limit}. + * Get all the elements in {@link org.springframework.data.domain.Range} from the sorted set at {@literal key} in + * reversed lexicographical ordering. Result is limited via {@link Limit}. * * @param key must not be {@literal null}. * @param range must not be {@literal null}. diff --git a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java index a217fc282..c3f464274 100644 --- a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java @@ -41,6 +41,7 @@ import org.springframework.data.redis.connection.stream.StreamOffset; import org.springframework.data.redis.connection.stream.StreamReadOptions; import org.springframework.data.redis.connection.stream.StreamRecords; import org.springframework.data.redis.connection.stream.StringRecord; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.Weights; import org.springframework.data.redis.core.Cursor; 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 c44416670..ba69c3e13 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 @@ -31,6 +31,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.redis.connection.ClusterSlotHashUtil; import org.springframework.data.redis.connection.RedisZSetCommands; import org.springframework.data.redis.connection.convert.SetConverter; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.DefaultTuple; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.Weights; 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 5a2749483..1ea87fbc6 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 @@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.redis.connection.RedisZSetCommands; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.DefaultTuple; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.Weights; diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java index bdb9387a6..1a9afb12d 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java @@ -48,7 +48,6 @@ import org.springframework.data.redis.connection.RedisListCommands.Direction; import org.springframework.data.redis.connection.RedisListCommands.Position; import org.springframework.data.redis.connection.RedisNode.NodeType; import org.springframework.data.redis.connection.RedisStringCommands.SetOption; -import org.springframework.data.redis.connection.RedisZSetCommands.Range.Boundary; import org.springframework.data.redis.connection.SortParameters.Order; import org.springframework.data.redis.connection.convert.Converters; import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter; @@ -257,19 +256,6 @@ public abstract class LettuceConverters extends Converters { return StringToRedisClientInfoConverter.INSTANCE.convert(clientList.split("\\r?\\n")); } - private static String boundaryToString(Boundary boundary, String inclPrefix, String exclPrefix) { - - String prefix = boundary.isIncluding() ? inclPrefix : exclPrefix; - String value = null; - if (boundary.getValue() instanceof byte[]) { - value = toString((byte[]) boundary.getValue()); - } else { - value = boundary.getValue().toString(); - } - - return prefix + value; - } - /** * Convert a {@link Limit} to a Lettuce {@link io.lettuce.core.Limit}. * @@ -290,81 +276,44 @@ public abstract class LettuceConverters extends Converters { * @since 2.0 */ public static Range toRange(org.springframework.data.domain.Range range) { - return Range.from(lowerBoundaryOf(range, false), upperBoundaryOf(range, false)); + return toRange(range, false); } /** - * Convert a {@link org.springframework.data.redis.connection.RedisZSetCommands.Range} to a lettuce {@link Range}. + * Convert a {@link org.springframework.data.domain.Range} to a lettuce {@link Range}. * * @param range * @param convertNumberToBytes * @return * @since 2.2 */ - public static Range toRange(org.springframework.data.domain.Range range, - boolean convertNumberToBytes) { - return Range.from(lowerBoundaryOf(range, convertNumberToBytes), upperBoundaryOf(range, convertNumberToBytes)); + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static Range toRange(org.springframework.data.domain.Range range, boolean convertNumberToBytes) { + + Range.Boundary upper = RangeConverter.convertBound(range.getUpperBound(), convertNumberToBytes, null, + it -> it.getBytes(StandardCharsets.UTF_8)); + Range.Boundary lower = RangeConverter.convertBound(range.getLowerBound(), convertNumberToBytes, null, + it -> it.getBytes(StandardCharsets.UTF_8)); + + return Range.from(lower, upper); } /** - * Convert a {@link org.springframework.data.redis.connection.RedisZSetCommands.Range} to a lettuce {@link Range} and - * reverse boundaries. + * Convert a {@link org.springframework.data.domain.Range} to a lettuce {@link Range} and reverse boundaries. * * @param range * @return * @since 2.0 */ + @SuppressWarnings({ "rawtypes", "unchecked" }) public static Range toRevRange(org.springframework.data.domain.Range range) { - return Range.from(upperBoundaryOf(range, false), lowerBoundaryOf(range, false)); - } - @SuppressWarnings("unchecked") - private static Range.Boundary lowerBoundaryOf( - org.springframework.data.domain.Range range, boolean convertNumberToBytes) { - return (Range.Boundary) rangeToBoundaryArgumentConverter(false, convertNumberToBytes).convert(range); - } + Range.Boundary upper = RangeConverter.convertBound(range.getUpperBound(), false, null, + it -> it.getBytes(StandardCharsets.UTF_8)); + Range.Boundary lower = RangeConverter.convertBound(range.getLowerBound(), false, null, + it -> it.getBytes(StandardCharsets.UTF_8)); - @SuppressWarnings("unchecked") - private static Range.Boundary upperBoundaryOf( - org.springframework.data.domain.Range range, boolean convertNumberToBytes) { - return (Range.Boundary) rangeToBoundaryArgumentConverter(true, convertNumberToBytes).convert(range); - } - - private static Converter, Range.Boundary> rangeToBoundaryArgumentConverter( - boolean upper, boolean convertNumberToBytes) { - - return (source) -> { - - org.springframework.data.domain.Range.Bound sourceBoundary = upper ? source.getUpperBound() - : source.getLowerBound(); - if (sourceBoundary == null || !sourceBoundary.isBounded()) { - return Range.Boundary.unbounded(); - } - - boolean inclusive = sourceBoundary.isInclusive(); - Object value = sourceBoundary.getValue().get(); - - if (value instanceof Number) { - - if (convertNumberToBytes) { - value = value.toString(); - } else { - return inclusive ? Range.Boundary.including((Number) value) : Range.Boundary.excluding((Number) value); - } - } - - if (value instanceof String) { - - if (!StringUtils.hasText((String) value) || ObjectUtils.nullSafeEquals(value, "+") - || ObjectUtils.nullSafeEquals(value, "-")) { - return Range.Boundary.unbounded(); - } - return inclusive ? Range.Boundary.including(value.toString().getBytes(StandardCharsets.UTF_8)) - : Range.Boundary.excluding(value.toString().getBytes(StandardCharsets.UTF_8)); - } - - return inclusive ? Range.Boundary.including((byte[]) value) : Range.Boundary.excluding((byte[]) value); - }; + return Range.from(upper, lower); } /** diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveZSetCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveZSetCommands.java index 3bf31487f..4c215d36d 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveZSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveZSetCommands.java @@ -37,7 +37,7 @@ import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyScan import org.springframework.data.redis.connection.ReactiveRedisConnection.MultiValueResponse; import org.springframework.data.redis.connection.ReactiveRedisConnection.NumericResponse; import org.springframework.data.redis.connection.ReactiveZSetCommands; -import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.DefaultTuple; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.core.TimeoutUtils; 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 bf8694c77..372924036 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 @@ -31,6 +31,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.redis.connection.RedisZSetCommands; import org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs.Flag; import org.springframework.data.redis.connection.convert.Converters; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.Weights; import org.springframework.data.redis.core.Cursor; diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/RangeConverter.java b/src/main/java/org/springframework/data/redis/connection/lettuce/RangeConverter.java index f2c61550d..71c216381 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/RangeConverter.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/RangeConverter.java @@ -19,8 +19,6 @@ import io.lettuce.core.Range; import io.lettuce.core.Range.Boundary; import io.lettuce.core.codec.StringCodec; -import java.nio.ByteBuffer; -import java.util.function.BiFunction; import java.util.function.Function; import org.springframework.data.domain.Range.Bound; @@ -79,45 +77,50 @@ class RangeConverter { @SuppressWarnings("unchecked") private static Boundary lowerBoundArgOf(org.springframework.data.domain.Range range, @Nullable T lowerDefault, Function stringEncoder) { - return (Boundary) rangeToBoundArgumentConverter(false, stringEncoder).apply(range, lowerDefault); + return (Boundary) convertBound(range.getLowerBound(), false, lowerDefault, stringEncoder); } @SuppressWarnings("unchecked") private static Boundary upperBoundArgOf(org.springframework.data.domain.Range range, @Nullable T upperDefault, Function stringEncoder) { - return (Boundary) rangeToBoundArgumentConverter(true, stringEncoder).apply(range, upperDefault); + return (Boundary) convertBound(range.getUpperBound(), false, upperDefault, stringEncoder); } - private static BiFunction> rangeToBoundArgumentConverter( - boolean upper, Function stringEncoder) { + static Boundary convertBound(org.springframework.data.domain.Range.Bound source, boolean convertNumberToBytes, + Object defaultValue, Function stringEncoder) { - return (source, defaultValue) -> { + if (!source.isBounded()) { + return Boundary.unbounded(); + } - Boolean inclusive = upper ? source.getUpperBound().isInclusive() : source.getLowerBound().isInclusive(); - Object value = upper ? source.getUpperBound().getValue().orElse(defaultValue) - : source.getLowerBound().getValue().orElse(defaultValue); + Boolean inclusive = source.isInclusive(); + Object value = source.getValue().orElse(defaultValue); - if (value instanceof Number) { + if (value instanceof Number) { + + if (convertNumberToBytes) { + value = value.toString(); + } else { return inclusive ? Boundary.including((Number) value) : Boundary.excluding((Number) value); } + } - if (value instanceof String) { + if (value instanceof String) { - if (!StringUtils.hasText((String) value) || ObjectUtils.nullSafeEquals(value, "+") - || ObjectUtils.nullSafeEquals(value, "-")) { - return Boundary.unbounded(); - } - - Object encoded = stringEncoder.apply((String) value); - return inclusive ? Boundary.including(encoded) : Boundary.excluding(encoded); - - } - - if (value == null) { + if (!StringUtils.hasText((String) value) || ObjectUtils.nullSafeEquals(value, "+") + || ObjectUtils.nullSafeEquals(value, "-")) { return Boundary.unbounded(); } - return inclusive ? Boundary.including((ByteBuffer) value) : Boundary.excluding((ByteBuffer) value); - }; + Object encoded = stringEncoder.apply((String) value); + return inclusive ? Boundary.including(encoded) : Boundary.excluding(encoded); + + } + + if (value == null) { + return Boundary.unbounded(); + } + + return inclusive ? Boundary.including(value) : Boundary.excluding(value); } } diff --git a/src/main/java/org/springframework/data/redis/connection/zset/Aggregate.java b/src/main/java/org/springframework/data/redis/connection/zset/Aggregate.java new file mode 100644 index 000000000..559e7e4d4 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/connection/zset/Aggregate.java @@ -0,0 +1,26 @@ +/* + * Copyright 2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.connection.zset; + +/** + * Sort aggregation operations. + * + * @author Mark Paluch + * @since 3.0 + */ +public enum Aggregate { + SUM, MIN, MAX; +} 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 ee33b17f7..28c802eb7 100644 --- a/src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java @@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit; import org.springframework.data.domain.Range; import org.springframework.data.redis.connection.Limit; -import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.Weights; import org.springframework.data.redis.core.ZSetOperations.TypedTuple; 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 c2e041321..4d5b98cfb 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultReactiveZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultReactiveZSetOperations.java @@ -31,7 +31,7 @@ import org.reactivestreams.Publisher; import org.springframework.data.domain.Range; import org.springframework.data.redis.connection.Limit; import org.springframework.data.redis.connection.ReactiveZSetCommands; -import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.DefaultTuple; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.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 b9d99efd3..f0b4157a5 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java @@ -24,8 +24,8 @@ import java.util.concurrent.TimeUnit; import org.springframework.data.domain.Range; import org.springframework.data.redis.connection.Limit; -import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; import org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.Weights; import org.springframework.lang.Nullable; 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 168e8ee26..f46a19f00 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveZSetOperations.java @@ -25,7 +25,7 @@ import java.util.List; import org.springframework.data.domain.Range; import org.springframework.data.redis.connection.Limit; -import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.Weights; import org.springframework.data.redis.core.ZSetOperations.TypedTuple; 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 fd5e72d10..4ad626238 100644 --- a/src/main/java/org/springframework/data/redis/core/ZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ZSetOperations.java @@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit; import org.springframework.data.domain.Range; import org.springframework.data.redis.connection.Limit; -import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.Weights; import org.springframework.lang.Nullable; diff --git a/src/main/kotlin/org/springframework/data/redis/core/ReactiveZSetOperationsExtensions.kt b/src/main/kotlin/org/springframework/data/redis/core/ReactiveZSetOperationsExtensions.kt index 03ead1eb6..5c0ad2f15 100644 --- a/src/main/kotlin/org/springframework/data/redis/core/ReactiveZSetOperationsExtensions.kt +++ b/src/main/kotlin/org/springframework/data/redis/core/ReactiveZSetOperationsExtensions.kt @@ -21,7 +21,7 @@ import kotlinx.coroutines.reactive.awaitFirstOrNull import kotlinx.coroutines.reactive.awaitSingle import org.springframework.data.domain.Range import org.springframework.data.redis.connection.Limit -import org.springframework.data.redis.connection.RedisZSetCommands +import org.springframework.data.redis.connection.zset.Aggregate import org.springframework.data.redis.connection.zset.Weights import org.springframework.data.redis.core.ZSetOperations.TypedTuple @@ -229,8 +229,13 @@ suspend fun ReactiveZSetOperations.unionAndStoreAndAwai * @author Mark Paluch * @since 2.2 */ -suspend fun ReactiveZSetOperations.unionAndStoreAndAwait(key: K, otherKeys: Collection, destKey: K, aggregate: RedisZSetCommands.Aggregate): Long = - unionAndStore(key, otherKeys, destKey, aggregate).awaitSingle() +suspend fun ReactiveZSetOperations.unionAndStoreAndAwait( + key: K, + otherKeys: Collection, + destKey: K, + aggregate: Aggregate +): Long = + unionAndStore(key, otherKeys, destKey, aggregate).awaitSingle() /** * Coroutines variant of [ReactiveZSetOperations.unionAndStore]. @@ -242,7 +247,7 @@ suspend fun ReactiveZSetOperations.unionAndStoreAndAwai key: K, otherKeys: Collection, destKey: K, - aggregate: RedisZSetCommands.Aggregate, + aggregate: Aggregate, weights: Weights ): Long = unionAndStore(key, otherKeys, destKey, aggregate, weights).awaitSingle() @@ -271,8 +276,13 @@ suspend fun ReactiveZSetOperations.intersectAndStoreAnd * @author Mark Paluch * @since 2.2 */ -suspend fun ReactiveZSetOperations.intersectAndStoreAndAwait(key: K, otherKeys: Collection, destKey: K, aggregate: RedisZSetCommands.Aggregate): Long = - intersectAndStore(key, otherKeys, destKey, aggregate).awaitSingle() +suspend fun ReactiveZSetOperations.intersectAndStoreAndAwait( + key: K, + otherKeys: Collection, + destKey: K, + aggregate: Aggregate +): Long = + intersectAndStore(key, otherKeys, destKey, aggregate).awaitSingle() /** * Coroutines variant of [ReactiveZSetOperations.intersectAndStore]. @@ -284,7 +294,7 @@ suspend fun ReactiveZSetOperations.intersectAndStoreAnd key: K, otherKeys: Collection, destKey: K, - aggregate: RedisZSetCommands.Aggregate, + aggregate: Aggregate, weights: Weights ): Long = intersectAndStore(key, otherKeys, destKey, aggregate, weights).awaitSingle() diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java index a290028f4..c82c03d09 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java @@ -59,7 +59,6 @@ import org.springframework.data.redis.connection.RedisListCommands.Position; import org.springframework.data.redis.connection.RedisStreamCommands.XClaimOptions; import org.springframework.data.redis.connection.RedisStringCommands.BitOperation; import org.springframework.data.redis.connection.RedisStringCommands.SetOption; -import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; import org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs; import org.springframework.data.redis.connection.SortParameters.Order; import org.springframework.data.redis.connection.StringRedisConnection.StringTuple; @@ -75,6 +74,7 @@ import org.springframework.data.redis.connection.stream.StreamInfo.XInfoGroups; import org.springframework.data.redis.connection.stream.StreamInfo.XInfoStream; import org.springframework.data.redis.connection.stream.StreamOffset; import org.springframework.data.redis.connection.stream.StringRecord; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.DefaultTuple; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.core.Cursor; 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 8d8261693..7191f8d80 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java @@ -49,7 +49,6 @@ import org.springframework.data.redis.connection.RedisListCommands.Position; import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption; import org.springframework.data.redis.connection.RedisStreamCommands.XAddOptions; import org.springframework.data.redis.connection.RedisStringCommands.BitOperation; -import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; import org.springframework.data.redis.connection.StringRedisConnection.StringTuple; import org.springframework.data.redis.connection.convert.Converters; import org.springframework.data.redis.connection.stream.Consumer; @@ -58,6 +57,7 @@ import org.springframework.data.redis.connection.stream.RecordId; import org.springframework.data.redis.connection.stream.StreamOffset; import org.springframework.data.redis.connection.stream.StreamReadOptions; import org.springframework.data.redis.connection.stream.StreamRecords; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.DefaultTuple; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.Weights; 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 40ed0190c..9482de3dc 100644 --- a/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java @@ -35,6 +35,7 @@ import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Metric; import org.springframework.data.geo.Point; import org.springframework.data.redis.connection.RedisNode.RedisNodeBuilder; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.Tuple; import org.springframework.data.redis.connection.zset.Weights; import org.springframework.data.redis.core.Cursor; diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveZSetOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveZSetOperationsIntegrationTests.java index 654f8d83b..451ff8e76 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveZSetOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveZSetOperationsIntegrationTests.java @@ -35,7 +35,7 @@ import org.springframework.data.redis.ObjectFactory; import org.springframework.data.redis.connection.Limit; import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.Weights; import org.springframework.data.redis.core.ReactiveOperationsTestParams.Fixture; import org.springframework.data.redis.serializer.RedisSerializer; diff --git a/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsIntegrationTests.java index 221afbc74..bbc2988c2 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsIntegrationTests.java @@ -37,7 +37,7 @@ import org.springframework.data.redis.LongObjectFactory; import org.springframework.data.redis.ObjectFactory; import org.springframework.data.redis.RawObjectFactory; import org.springframework.data.redis.connection.Limit; -import org.springframework.data.redis.connection.RedisZSetCommands; +import org.springframework.data.redis.connection.zset.Aggregate; import org.springframework.data.redis.connection.zset.Weights; import org.springframework.data.redis.core.ZSetOperations.TypedTuple; import org.springframework.data.redis.test.condition.EnabledOnCommand; @@ -576,10 +576,10 @@ public class DefaultZSetOperationsIntegrationTests { zSetOps.add(key1, value2, 2.0); zSetOps.add(key2, value2, 3.0); - assertThat(zSetOps.intersectWithScores(key1, Collections.singletonList(key2), RedisZSetCommands.Aggregate.MIN)) + assertThat(zSetOps.intersectWithScores(key1, Collections.singletonList(key2), Aggregate.MIN)) .contains(new DefaultTypedTuple<>(value2, 2d)); - zSetOps.intersectAndStore(key1, Collections.singletonList(key2), key1, RedisZSetCommands.Aggregate.MIN); + zSetOps.intersectAndStore(key1, Collections.singletonList(key2), key1, Aggregate.MIN); assertThat(zSetOps.score(key1, value2)).isCloseTo(2.0, offset(0.1)); } @@ -593,7 +593,7 @@ public class DefaultZSetOperationsIntegrationTests { zSetOps.add(key1, value1, 4.0); zSetOps.add(key2, value1, 3.0); - zSetOps.intersectAndStore(key1, Collections.singletonList(key2), key1, RedisZSetCommands.Aggregate.MAX, + zSetOps.intersectAndStore(key1, Collections.singletonList(key2), key1, Aggregate.MAX, Weights.of(1, 2)); assertThat(zSetOps.score(key1, value1)).isCloseTo(6.0, offset(0.1)); @@ -633,7 +633,7 @@ public class DefaultZSetOperationsIntegrationTests { assertThat(zSetOps.unionWithScores(key1, Collections.singletonList(key2))) .containsOnly(new DefaultTypedTuple<>(value1, 1d), new DefaultTypedTuple<>(value2, 5d)); - zSetOps.unionAndStore(key1, Collections.singletonList(key2), key1, RedisZSetCommands.Aggregate.MIN); + zSetOps.unionAndStore(key1, Collections.singletonList(key2), key1, Aggregate.MIN); assertThat(zSetOps.score(key1, value2)).isCloseTo(2.0, offset(0.1)); } @@ -648,7 +648,7 @@ public class DefaultZSetOperationsIntegrationTests { zSetOps.add(key1, value1, 4.0); zSetOps.add(key2, value1, 3.0); - zSetOps.unionAndStore(key1, Collections.singletonList(key2), key1, RedisZSetCommands.Aggregate.MAX, + zSetOps.unionAndStore(key1, Collections.singletonList(key2), key1, Aggregate.MAX, Weights.of(1, 2)); assertThat(zSetOps.score(key1, value1)).isCloseTo(6.0, offset(0.1)); diff --git a/src/test/kotlin/org/springframework/data/redis/core/ReactiveZSetOperationsExtensionsUnitTests.kt b/src/test/kotlin/org/springframework/data/redis/core/ReactiveZSetOperationsExtensionsUnitTests.kt index 36821190b..aa91d1cc2 100644 --- a/src/test/kotlin/org/springframework/data/redis/core/ReactiveZSetOperationsExtensionsUnitTests.kt +++ b/src/test/kotlin/org/springframework/data/redis/core/ReactiveZSetOperationsExtensionsUnitTests.kt @@ -24,7 +24,7 @@ import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.springframework.data.domain.Range import org.springframework.data.redis.connection.Limit -import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate +import org.springframework.data.redis.connection.zset.Aggregate import org.springframework.data.redis.connection.zset.Weights import org.springframework.data.redis.core.ZSetOperations.TypedTuple import reactor.core.publisher.Flux