diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/ReactiveRedisConnection.java index ac596c7ee..fb6d656a4 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReactiveRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/ReactiveRedisConnection.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 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. @@ -15,16 +15,16 @@ */ package org.springframework.data.redis.connection; +import lombok.Data; + import java.io.Closeable; -import java.io.IOException; import java.nio.ByteBuffer; import java.util.List; import org.springframework.data.domain.Range; +import org.springframework.data.domain.Range.Bound; import org.springframework.util.Assert; -import lombok.Data; - /** * Redis connection using reactive infrastructure declaring entry points for reactive command execution. *

@@ -212,7 +212,7 @@ public interface ReactiveRedisConnection extends Closeable { * @return a new {@link RangeCommand} with the lower bound applied. */ public RangeCommand fromIndex(long start) { - return new RangeCommand(getKey(), new Range<>(start, range.getUpperBound())); + return new RangeCommand(getKey(), Range.of(Bound.inclusive(start), range.getUpperBound())); } /** @@ -223,7 +223,7 @@ public interface ReactiveRedisConnection extends Closeable { * @return a new {@link RangeCommand} with the upper bound applied. */ public RangeCommand toIndex(long end) { - return new RangeCommand(getKey(), new Range<>(range.getLowerBound(), end)); + return new RangeCommand(getKey(), Range.of(range.getLowerBound(), Bound.inclusive(end))); } /** diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommands.java index 8b79cac52..549e788d4 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 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. @@ -15,6 +15,9 @@ */ package org.springframework.data.redis.connection.lettuce; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + import java.nio.ByteBuffer; import java.time.temporal.ChronoUnit; import java.util.Arrays; @@ -26,16 +29,12 @@ import org.springframework.data.redis.connection.ReactiveRedisConnection.Boolean import org.springframework.data.redis.connection.ReactiveRedisConnection.ByteBufferResponse; import org.springframework.data.redis.connection.ReactiveRedisConnection.CommandResponse; import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyCommand; -import org.springframework.data.redis.connection.ReactiveRedisConnection.MultiValueResponse; import org.springframework.data.redis.connection.ReactiveRedisConnection.NumericResponse; import org.springframework.data.redis.connection.ReactiveRedisConnection.RangeCommand; import org.springframework.data.redis.connection.RedisListCommands.Position; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - /** * @author Christoph Strobl * @author Mark Paluch @@ -117,7 +116,8 @@ public class LettuceReactiveListCommands implements ReactiveListCommands { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getRange(), "Range must not be null!"); - Flux result = cmd.lrange(command.getKey(), command.getRange().getLowerBound(), command.getRange().getUpperBound()); + Flux result = cmd.lrange(command.getKey(), command.getRange().getLowerBound().getValue().orElse(null), + command.getRange().getUpperBound().getValue().orElse(null)); return Mono.just(new CommandResponse<>(command, result)); })); } @@ -134,7 +134,9 @@ public class LettuceReactiveListCommands implements ReactiveListCommands { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getRange(), "Range must not be null!"); - return cmd.ltrim(command.getKey(), command.getRange().getLowerBound(), command.getRange().getUpperBound()) + return cmd + .ltrim(command.getKey(), command.getRange().getLowerBound().getValue().orElse(null), + command.getRange().getUpperBound().getValue().orElse(null)) .map(LettuceConverters::stringToBoolean).map(value -> new BooleanResponse<>(command, value)); })); } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommands.java index 9b49013ae..6211dc44d 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommands.java @@ -246,8 +246,8 @@ public class LettuceReactiveStringCommands implements ReactiveStringCommands { Range range = command.getRange(); - return cmd.getrange(command.getKey(), range.getLowerBound(), range.getUpperBound()) - .map((value) -> new ByteBufferResponse<>(command, value)); + return cmd.getrange(command.getKey(), range.getLowerBound().getValue().orElse(null), + range.getUpperBound().getValue().orElse(null)).map((value) -> new ByteBufferResponse<>(command, value)); })); } @@ -316,8 +316,9 @@ public class LettuceReactiveStringCommands implements ReactiveStringCommands { Assert.notNull(command.getKey(), "Key must not be null!"); Range range = command.getRange(); - return (range != null ? cmd.bitcount(command.getKey(), range.getLowerBound(), range.getUpperBound()) - : cmd.bitcount(command.getKey())).map(responseValue -> new NumericResponse<>(command, responseValue)); + return (range != null ? cmd.bitcount(command.getKey(), range.getLowerBound().getValue().orElse(null), + range.getUpperBound().getValue().orElse(null)) : cmd.bitcount(command.getKey())) + .map(responseValue -> new NumericResponse<>(command, responseValue)); })); } 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 5bc003369..979a61a89 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 @@ -39,7 +39,6 @@ import org.springframework.data.redis.connection.ReactiveZSetCommands; import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; import org.springframework.data.redis.connection.RedisZSetCommands.Tuple; import org.springframework.data.redis.util.ByteUtils; -import org.springframework.data.util.DirectFieldAccessFallbackBeanWrapper; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -186,22 +185,29 @@ public class LettuceReactiveZSetCommands implements ReactiveZSetCommands { if (ObjectUtils.nullSafeEquals(command.getDirection(), Direction.ASC)) { if (command.isWithScores()) { - result = cmd.zrangeWithScores(command.getKey(), command.getRange().getLowerBound(), - command.getRange().getUpperBound()).map(sc -> (Tuple) new DefaultTuple(getBytes(sc), sc.getScore())); + result = cmd + .zrangeWithScores(command.getKey(), command.getRange().getLowerBound().getValue().orElse(null), + command.getRange().getUpperBound().getValue().orElse(null)) + .map(sc -> (Tuple) new DefaultTuple(getBytes(sc), sc.getScore())); } else { - result = cmd.zrange(command.getKey(), command.getRange().getLowerBound(), command.getRange().getUpperBound()) + result = cmd + .zrange(command.getKey(), command.getRange().getLowerBound().getValue().orElse(null), + command.getRange().getUpperBound().getValue().orElse(null)) .map(value -> (Tuple) new DefaultTuple(ByteUtils.getBytes(value), Double.NaN)); } } else { if (command.isWithScores()) { - result = cmd.zrevrangeWithScores(command.getKey(), command.getRange().getLowerBound(), - command.getRange().getUpperBound()).map(sc -> (Tuple) new DefaultTuple(getBytes(sc), sc.getScore())); + result = cmd + .zrevrangeWithScores(command.getKey(), command.getRange().getLowerBound().getValue().orElse(null), + command.getRange().getUpperBound().getValue().orElse(null)) + .map(sc -> (Tuple) new DefaultTuple(getBytes(sc), sc.getScore())); } else { result = cmd - .zrevrange(command.getKey(), command.getRange().getLowerBound(), command.getRange().getUpperBound()) + .zrevrange(command.getKey(), command.getRange().getLowerBound().getValue().orElse(null), + command.getRange().getUpperBound().getValue().orElse(null)) .map(value -> (Tuple) new DefaultTuple(ByteUtils.getBytes(value), Double.NaN)); } } @@ -349,7 +355,8 @@ public class LettuceReactiveZSetCommands implements ReactiveZSetCommands { Assert.notNull(command.getRange(), "Range must not be null!"); return cmd - .zremrangebyrank(command.getKey(), command.getRange().getLowerBound(), command.getRange().getUpperBound()) + .zremrangebyrank(command.getKey(), command.getRange().getLowerBound().getValue().orElse(null), + command.getRange().getUpperBound().getValue().orElse(null)) .map(value -> new NumericResponse<>(command, value)); })); } @@ -519,12 +526,9 @@ public class LettuceReactiveZSetCommands implements ReactiveZSetCommands { return (source) -> { - // TODO: fix range exclusion pattern when DATACMNS-920 is resolved - DirectFieldAccessFallbackBeanWrapper bw = new DirectFieldAccessFallbackBeanWrapper(source); - - Boolean inclusive = upper ? Boolean.valueOf(bw.getPropertyValue("upperInclusive").toString()) - : Boolean.valueOf(bw.getPropertyValue("lowerInclusive").toString()); - Object value = upper ? source.getUpperBound() : source.getLowerBound(); + Boolean inclusive = upper ? source.getUpperBound().isInclusive() : source.getLowerBound().isInclusive(); + Object value = upper ? source.getUpperBound().getValue().orElse(null) + : source.getLowerBound().getValue().orElse(null); if (value instanceof Number) { return inclusive ? Boundary.including((Number) value) : Boundary.excluding((Number) value);