diff --git a/.travis.yml b/.travis.yml index 05fd5da95..7d7dc90ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,6 @@ jdk: env: matrix: - - PROFILE=spring42 - - PROFILE=spring42-next - - PROFILE=spring43-next - PROFILE=spring5-next addons: diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveGeoCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveGeoCommands.java index b2510c8b7..62cebeed6 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReactiveGeoCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/ReactiveGeoCommands.java @@ -25,14 +25,12 @@ import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; import org.reactivestreams.Publisher; import org.springframework.data.domain.Sort.Direction; import org.springframework.data.geo.Circle; import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResult; -import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Metric; import org.springframework.data.geo.Point; import org.springframework.data.redis.connection.ReactiveRedisConnection.CommandResponse; @@ -859,9 +857,8 @@ public interface ReactiveGeoCommands { * @return * @see Redis Documentation: GEORADIUS */ - default Mono>> geoRadius(ByteBuffer key, Circle circle) { - return geoRadius(key, circle, null) - .map(res -> res.getContent().stream().map(GeoResult::getContent).collect(Collectors.toList())); + default Flux>> geoRadius(ByteBuffer key, Circle circle) { + return geoRadius(key, circle, null); } /** @@ -873,14 +870,14 @@ public interface ReactiveGeoCommands { * @return * @see Redis Documentation: GEORADIUS */ - default Mono>> geoRadius(ByteBuffer key, Circle circle, + default Flux>> geoRadius(ByteBuffer key, Circle circle, GeoRadiusCommandArgs geoRadiusArgs) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(circle, "Circle must not be null!"); return geoRadius(Mono.just(GeoRadiusCommand.within(circle).withArgs(geoRadiusArgs).forKey(key))).next() - .map(CommandResponse::getOutput); + .flatMapMany(CommandResponse::getOutput); } /** @@ -890,7 +887,7 @@ public interface ReactiveGeoCommands { * @return * @see Redis Documentation: GEORADIUS */ - Flux>>> geoRadius( + Flux>>>> geoRadius( Publisher commands); /** @@ -1184,9 +1181,9 @@ public interface ReactiveGeoCommands { * @return * @see Redis Documentation: GEORADIUSBYMEMBER */ - default Mono>> geoRadiusByMember(ByteBuffer key, ByteBuffer member, Distance distance) { - return geoRadiusByMember(key, member, distance, null) - .map(res -> res.getContent().stream().map(GeoResult::getContent).collect(Collectors.toList())); + default Flux>> geoRadiusByMember(ByteBuffer key, ByteBuffer member, + Distance distance) { + return geoRadiusByMember(key, member, distance, null); } /** @@ -1198,7 +1195,7 @@ public interface ReactiveGeoCommands { * @return * @see Redis Documentation: GEORADIUSBYMEMBER */ - default Mono>> geoRadiusByMember(ByteBuffer key, ByteBuffer member, + default Flux>> geoRadiusByMember(ByteBuffer key, ByteBuffer member, Distance distance, GeoRadiusCommandArgs geoRadiusArgs) { Assert.notNull(key, "Key must not be null!"); @@ -1207,7 +1204,7 @@ public interface ReactiveGeoCommands { return geoRadiusByMember( Mono.just(GeoRadiusByMemberCommand.within(distance).from(member).forKey(key).withArgs(geoRadiusArgs))).next() - .map(CommandResponse::getOutput); + .flatMapMany(CommandResponse::getOutput); } /** @@ -1217,6 +1214,6 @@ public interface ReactiveGeoCommands { * @return * @see Redis Documentation: GEORADIUSBYMEMBER */ - Flux>>> geoRadiusByMember( + Flux>>>> geoRadiusByMember( Publisher commands); } diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveHashCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveHashCommands.java index df64c100b..a0d3ee094 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReactiveHashCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/ReactiveHashCommands.java @@ -516,11 +516,11 @@ public interface ReactiveHashCommands { * @return * @see Redis Documentation: HKEYS */ - default Mono> hKeys(ByteBuffer key) { + default Flux hKeys(ByteBuffer key) { Assert.notNull(key, "Key must not be null!"); - return hKeys(Mono.just(new KeyCommand(key))).next().map(MultiValueResponse::getOutput); + return hKeys(Mono.just(new KeyCommand(key))).next().flatMapMany(CommandResponse::getOutput); } /** @@ -530,7 +530,7 @@ public interface ReactiveHashCommands { * @return * @see Redis Documentation: HKEYS */ - Flux> hKeys(Publisher commands); + Flux>> hKeys(Publisher commands); /** * Get entry set (values) of hash at {@literal key}. @@ -539,11 +539,11 @@ public interface ReactiveHashCommands { * @return * @see Redis Documentation: HVALS */ - default Mono> hVals(ByteBuffer key) { + default Flux hVals(ByteBuffer key) { Assert.notNull(key, "Key must not be null!"); - return hVals(Mono.just(new KeyCommand(key))).next().map(MultiValueResponse::getOutput); + return hVals(Mono.just(new KeyCommand(key))).next().flatMapMany(CommandResponse::getOutput); } /** @@ -553,7 +553,7 @@ public interface ReactiveHashCommands { * @return * @see Redis Documentation: HVALS */ - Flux> hVals(Publisher commands); + Flux>> hVals(Publisher commands); /** * Get entire hash stored at {@literal key}. @@ -562,11 +562,11 @@ public interface ReactiveHashCommands { * @return * @see Redis Documentation: HGETALL */ - default Mono> hGetAll(ByteBuffer key) { + default Flux> hGetAll(ByteBuffer key) { Assert.notNull(key, "Key must not be null!"); - return hGetAll(Mono.just(new KeyCommand(key))).next().map(CommandResponse::getOutput); + return hGetAll(Mono.just(new KeyCommand(key))).next().flatMapMany(CommandResponse::getOutput); } /** @@ -576,5 +576,5 @@ public interface ReactiveHashCommands { * @return * @see Redis Documentation: HGETALL */ - Flux>> hGetAll(Publisher commands); + Flux>>> hGetAll(Publisher commands); } diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveListCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveListCommands.java index e013c38ef..fa283c830 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReactiveListCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/ReactiveListCommands.java @@ -30,7 +30,6 @@ import org.springframework.data.redis.connection.ReactiveRedisConnection.ByteBuf import org.springframework.data.redis.connection.ReactiveRedisConnection.Command; 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; @@ -269,12 +268,12 @@ public interface ReactiveListCommands { * @return * @see Redis Documentation: LRANGE */ - default Mono> lRange(ByteBuffer key, long start, long end) { + default Flux lRange(ByteBuffer key, long start, long end) { Assert.notNull(key, "Key must not be null!"); return lRange(Mono.just(RangeCommand.key(key).fromIndex(start).toIndex(end))).next() - .map(MultiValueResponse::getOutput); + .flatMapMany(CommandResponse::getOutput); } /** @@ -284,7 +283,7 @@ public interface ReactiveListCommands { * @return * @see Redis Documentation: LRANGE */ - Flux> lRange(Publisher commands); + Flux>> lRange(Publisher commands); /** * Trim list at {@literal key} to elements between {@literal begin} and {@literal end}. diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveSetCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveSetCommands.java index 1b0220704..117cb6548 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReactiveSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/ReactiveSetCommands.java @@ -29,8 +29,8 @@ import org.reactivestreams.Publisher; import org.springframework.data.redis.connection.ReactiveRedisConnection.BooleanResponse; import org.springframework.data.redis.connection.ReactiveRedisConnection.ByteBufferResponse; import org.springframework.data.redis.connection.ReactiveRedisConnection.Command; +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.util.Assert; @@ -524,11 +524,11 @@ public interface ReactiveSetCommands { * @return * @see Redis Documentation: SINTER */ - default Mono> sInter(Collection keys) { + default Flux sInter(Collection keys) { Assert.notNull(keys, "Keys must not be null!"); - return sInter(Mono.just(SInterCommand.keys(keys))).next().map(MultiValueResponse::getOutput); + return sInter(Mono.just(SInterCommand.keys(keys))).next().flatMapMany(CommandResponse::getOutput); } /** @@ -538,7 +538,7 @@ public interface ReactiveSetCommands { * @return * @see Redis Documentation: SINTER */ - Flux> sInter(Publisher commands); + Flux>> sInter(Publisher commands); /** * {@code SINTERSTORE} command parameters. @@ -668,11 +668,11 @@ public interface ReactiveSetCommands { * @return * @see Redis Documentation: SUNION */ - default Mono> sUnion(Collection keys) { + default Flux sUnion(Collection keys) { Assert.notNull(keys, "Keys must not be null!"); - return sUnion(Mono.just(SUnionCommand.keys(keys))).next().map(MultiValueResponse::getOutput); + return sUnion(Mono.just(SUnionCommand.keys(keys))).next().flatMapMany(CommandResponse::getOutput); } /** @@ -682,7 +682,7 @@ public interface ReactiveSetCommands { * @return * @see Redis Documentation: SUNION */ - Flux> sUnion(Publisher commands); + Flux>> sUnion(Publisher commands); /** * {@code SUNIONSTORE} command parameters. @@ -812,11 +812,11 @@ public interface ReactiveSetCommands { * @return * @see Redis Documentation: SDIFF */ - default Mono> sDiff(Collection keys) { + default Flux sDiff(Collection keys) { Assert.notNull(keys, "Keys must not be null!"); - return sDiff(Mono.just(SDiffCommand.keys(keys))).next().map(MultiValueResponse::getOutput); + return sDiff(Mono.just(SDiffCommand.keys(keys))).next().flatMapMany(CommandResponse::getOutput); } /** @@ -826,7 +826,7 @@ public interface ReactiveSetCommands { * @return * @see Redis Documentation: SDIFF */ - Flux> sDiff(Publisher commands); + Flux>> sDiff(Publisher commands); /** * {@code SDIFFSTORE} command parameters. @@ -913,11 +913,11 @@ public interface ReactiveSetCommands { * @return * @see Redis Documentation: SMEMBERS */ - default Mono> sMembers(ByteBuffer key) { + default Flux sMembers(ByteBuffer key) { Assert.notNull(key, "Key must not be null!"); - return sMembers(Mono.just(new KeyCommand(key))).next().map(MultiValueResponse::getOutput); + return sMembers(Mono.just(new KeyCommand(key))).next().flatMapMany(CommandResponse::getOutput); } /** @@ -927,7 +927,7 @@ public interface ReactiveSetCommands { * @return * @see Redis Documentation: SMEMBERS */ - Flux> sMembers(Publisher commands); + Flux>> sMembers(Publisher commands); /** * {@code SRANDMEMBER} command parameters. @@ -993,7 +993,7 @@ public interface ReactiveSetCommands { * @see Redis Documentation: SRANDMEMBER */ default Mono sRandMember(ByteBuffer key) { - return sRandMember(key, 1L).map(vals -> vals.isEmpty() ? null : vals.iterator().next()); + return sRandMember(key, 1L).singleOrEmpty(); } /** @@ -1004,13 +1004,13 @@ public interface ReactiveSetCommands { * @return * @see Redis Documentation: SRANDMEMBER */ - default Mono> sRandMember(ByteBuffer key, Long count) { + default Flux sRandMember(ByteBuffer key, Long count) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(count, "Count must not be null!"); return sRandMember(Mono.just(SRandMembersCommand.valueCount(count).from(key))).next() - .map(MultiValueResponse::getOutput); + .flatMapMany(CommandResponse::getOutput); } /** @@ -1020,5 +1020,5 @@ public interface ReactiveSetCommands { * @return * @see Redis Documentation: SRANDMEMBER */ - Flux> sRandMember(Publisher commands); + Flux>> sRandMember(Publisher commands); } 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 8b350f95a..7254d3168 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReactiveZSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/ReactiveZSetCommands.java @@ -24,13 +24,12 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import org.reactivestreams.Publisher; import org.springframework.data.domain.Range; import org.springframework.data.domain.Sort.Direction; +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.RedisZSetCommands.Aggregate; import org.springframework.data.redis.connection.RedisZSetCommands.Limit; @@ -652,17 +651,14 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZRANGE */ - default Mono> zRange(ByteBuffer key, Range range) { + default Flux zRange(ByteBuffer key, Range range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return zRange(Mono.just(ZRangeCommand.valuesWithin(range).from(key))) // .next() // - .map(resp -> resp.getOutput() // - .stream() // - .map(tuple -> ByteBuffer.wrap(tuple.getValue())) // - .collect(Collectors.toList())); + .flatMapMany(CommandResponse::getOutput).map(tuple -> ByteBuffer.wrap(tuple.getValue())); } /** @@ -673,12 +669,12 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZRANGE */ - default Mono> zRangeWithScores(ByteBuffer key, Range range) { + default Flux zRangeWithScores(ByteBuffer key, Range range) { Assert.notNull(key, "Key must not be null!"); return zRange(Mono.just(ZRangeCommand.valuesWithin(range).withScores().from(key))).next() - .map(MultiValueResponse::getOutput); + .flatMapMany(CommandResponse::getOutput); } /** @@ -689,12 +685,12 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZREVRANGE */ - default Mono> zRevRange(ByteBuffer key, Range range) { + default Flux zRevRange(ByteBuffer key, Range range) { Assert.notNull(key, "Key must not be null!"); - return zRange(Mono.just(ZRangeCommand.reverseValuesWithin(range).from(key))).next().map( - resp -> resp.getOutput().stream().map(tuple -> ByteBuffer.wrap(tuple.getValue())).collect(Collectors.toList())); + return zRange(Mono.just(ZRangeCommand.reverseValuesWithin(range).from(key))).next() + .flatMapMany(CommandResponse::getOutput).map(tuple -> ByteBuffer.wrap(tuple.getValue())); } /** @@ -705,12 +701,12 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZREVRANGE */ - default Mono> zRevRangeWithScores(ByteBuffer key, Range range) { + default Flux zRevRangeWithScores(ByteBuffer key, Range range) { Assert.notNull(key, "Key must not be null!"); return zRange(Mono.just(ZRangeCommand.reverseValuesWithin(range).withScores().from(key))).next() - .map(MultiValueResponse::getOutput); + .flatMapMany(CommandResponse::getOutput); } /** @@ -721,7 +717,7 @@ public interface ReactiveZSetCommands { * @see Redis Documentation: ZRANGE * @see Redis Documentation: ZREVRANGE */ - Flux> zRange(Publisher commands); + Flux>> zRange(Publisher commands); /** * {@literal ZRANGEBYSCORE}/{@literal ZREVRANGEBYSCORE}. @@ -846,17 +842,15 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZRANGEBYSCORE */ - default Mono> zRangeByScore(ByteBuffer key, Range range) { + default Flux zRangeByScore(ByteBuffer key, Range range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return zRangeByScore(Mono.just(ZRangeByScoreCommand.scoresWithin(range).from(key))) // .next() // - .map(resp -> resp.getOutput() // - .stream() // - .map(tuple -> ByteBuffer.wrap(tuple.getValue())) // - .collect(Collectors.toList())); + .flatMapMany(CommandResponse::getOutput) // + .map(tuple -> ByteBuffer.wrap(tuple.getValue())); } /** @@ -868,17 +862,15 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZRANGEBYSCORE */ - default Mono> zRangeByScore(ByteBuffer key, Range range, Limit limit) { + default Flux zRangeByScore(ByteBuffer key, Range range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return zRangeByScore(Mono.just(ZRangeByScoreCommand.scoresWithin(range).from(key).limitTo(limit))) // .next() // - .map(resp -> resp.getOutput() // - .stream() // - .map(tuple -> ByteBuffer.wrap(tuple.getValue())) // - .collect(Collectors.toList())); + .flatMapMany(CommandResponse::getOutput) // + .map(tuple -> ByteBuffer.wrap(tuple.getValue())); } /** @@ -889,13 +881,13 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZRANGEBYSCORE */ - default Mono> zRangeByScoreWithScores(ByteBuffer key, Range range) { + default Flux zRangeByScoreWithScores(ByteBuffer key, Range range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return zRangeByScore(Mono.just(ZRangeByScoreCommand.scoresWithin(range).withScores().from(key))).next() - .map(MultiValueResponse::getOutput); + .flatMapMany(CommandResponse::getOutput); } /** @@ -907,13 +899,13 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZRANGEBYSCORE */ - default Mono> zRangeByScoreWithScores(ByteBuffer key, Range range, Limit limit) { + default Flux zRangeByScoreWithScores(ByteBuffer key, Range range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return zRangeByScore(Mono.just(ZRangeByScoreCommand.scoresWithin(range).withScores().from(key).limitTo(limit))) - .next().map(MultiValueResponse::getOutput); + .next().flatMapMany(CommandResponse::getOutput); } /** @@ -924,16 +916,14 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZREVRANGEBYSCORE */ - default Mono> zRevRangeByScore(ByteBuffer key, Range range) { + default Flux zRevRangeByScore(ByteBuffer key, Range range) { Assert.notNull(key, "Key must not be null!"); return zRangeByScore(Mono.just(ZRangeByScoreCommand.reverseScoresWithin(range).from(key))) // .next() // - .map(resp -> resp.getOutput() // - .stream() // - .map(tuple -> ByteBuffer.wrap(tuple.getValue())) // - .collect(Collectors.toList())); + .flatMapMany(CommandResponse::getOutput) // + .map(tuple -> ByteBuffer.wrap(tuple.getValue())); } /** @@ -945,15 +935,15 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZREVRANGEBYSCORE */ - default Mono> zRevRangeByScore(ByteBuffer key, Range range, Limit limit) { + default Flux zRevRangeByScore(ByteBuffer key, Range range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return zRangeByScore(Mono.just(ZRangeByScoreCommand.reverseScoresWithin(range).from(key).limitTo(limit))) // .next() // - .map(resp -> resp.getOutput() // - .stream().map(tuple -> ByteBuffer.wrap(tuple.getValue())).collect(Collectors.toList())); + .flatMapMany(CommandResponse::getOutput) // + .map(tuple -> ByteBuffer.wrap(tuple.getValue())); } /** @@ -964,13 +954,13 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZREVRANGEBYSCORE */ - default Mono> zRevRangeByScoreWithScores(ByteBuffer key, Range range) { + default Flux zRevRangeByScoreWithScores(ByteBuffer key, Range range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return zRangeByScore(Mono.just(ZRangeByScoreCommand.reverseScoresWithin(range).withScores().from(key))).next() - .map(MultiValueResponse::getOutput); + .flatMapMany(CommandResponse::getOutput); } /** @@ -982,14 +972,14 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZREVRANGEBYSCORE */ - default Mono> zRevRangeByScoreWithScores(ByteBuffer key, Range range, Limit limit) { + default Flux zRevRangeByScoreWithScores(ByteBuffer key, Range range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return zRangeByScore( Mono.just(ZRangeByScoreCommand.reverseScoresWithin(range).withScores().from(key).limitTo(limit))).next() - .map(MultiValueResponse::getOutput); + .flatMapMany(CommandResponse::getOutput); } /** @@ -1000,7 +990,7 @@ public interface ReactiveZSetCommands { * @see Redis Documentation: ZRANGEBYSCORE * @see Redis Documentation: ZREVRANGEBYSCORE */ - Flux> zRangeByScore(Publisher commands); + Flux>> zRangeByScore(Publisher commands); /** * {@code ZCOUNT} command parameters. @@ -1727,7 +1717,7 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZRANGEBYLEX */ - default Mono> zRangeByLex(ByteBuffer key, Range range) { + default Flux zRangeByLex(ByteBuffer key, Range range) { return zRangeByLex(key, range, null); } @@ -1741,13 +1731,13 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZRANGEBYLEX */ - default Mono> zRangeByLex(ByteBuffer key, Range range, Limit limit) { + default Flux zRangeByLex(ByteBuffer key, Range range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return zRangeByLex(Mono.just(ZRangeByLexCommand.stringsWithin(range).from(key).limitTo(limit))).next() - .map(MultiValueResponse::getOutput); + .flatMapMany(CommandResponse::getOutput); } /** @@ -1758,7 +1748,7 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZREVRANGEBYLEX */ - default Mono> zRevRangeByLex(ByteBuffer key, Range range) { + default Flux zRevRangeByLex(ByteBuffer key, Range range) { return zRevRangeByLex(key, range, null); } @@ -1772,13 +1762,13 @@ public interface ReactiveZSetCommands { * @return * @see Redis Documentation: ZREVRANGEBYLEX */ - default Mono> zRevRangeByLex(ByteBuffer key, Range range, Limit limit) { + default Flux zRevRangeByLex(ByteBuffer key, Range range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return zRangeByLex(Mono.just(ZRangeByLexCommand.reverseStringsWithin(range).from(key).limitTo(limit))).next() - .map(MultiValueResponse::getOutput); + .flatMapMany(CommandResponse::getOutput); } /** @@ -1790,5 +1780,5 @@ public interface ReactiveZSetCommands { * @see Redis Documentation: ZRANGEBYLEX * @see Redis Documentation: ZREVRANGEBYLEX */ - Flux> zRangeByLex(Publisher commands); + Flux>> zRangeByLex(Publisher commands); } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterSetCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterSetCommands.java index a74b78eaa..09699f962 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterSetCommands.java @@ -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.util.ArrayList; import java.util.List; @@ -24,13 +27,10 @@ import org.reactivestreams.Publisher; import org.springframework.data.redis.connection.ClusterSlotHashUtil; import org.springframework.data.redis.connection.ReactiveClusterSetCommands; import org.springframework.data.redis.connection.ReactiveRedisConnection.BooleanResponse; -import org.springframework.data.redis.connection.ReactiveRedisConnection.MultiValueResponse; +import org.springframework.data.redis.connection.ReactiveRedisConnection.CommandResponse; import org.springframework.data.redis.connection.ReactiveRedisConnection.NumericResponse; import org.springframework.util.Assert; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - /** * @author Christoph Strobl * @author Mark Paluch @@ -52,7 +52,7 @@ public class LettuceReactiveClusterSetCommands extends LettuceReactiveSetCommand * @see org.springframework.data.redis.connection.lettuce.LettuceReactiveSetCommands#sUnion(org.reactivestreams.Publisher) */ @Override - public Flux> sUnion(Publisher commands) { + public Flux>> sUnion(Publisher commands) { return getConnection().execute(cmd -> Flux.from(commands).flatMap(command -> { @@ -62,10 +62,10 @@ public class LettuceReactiveClusterSetCommands extends LettuceReactiveSetCommand return super.sUnion(Mono.just(command)); } - Mono> result = Flux - .merge(command.getKeys().stream().map(cmd::smembers).collect(Collectors.toList())).distinct().collectList(); + Flux result = Flux.merge(command.getKeys().stream().map(cmd::smembers).collect(Collectors.toList())) + .distinct(); - return result.map(value -> new MultiValueResponse<>(command, value)); + return Mono.just(new CommandResponse<>(command, result)); })); } @@ -88,7 +88,7 @@ public class LettuceReactiveClusterSetCommands extends LettuceReactiveSetCommand } return sUnion(Mono.just(SUnionCommand.keys(command.getKeys()))).next().flatMap(values -> { - Mono result = cmd.sadd(command.getKey(), values.getOutput().stream().toArray(ByteBuffer[]::new)); + Mono result = cmd.sadd(command.getKey(), values.getOutput().toStream().toArray(ByteBuffer[]::new)); return result.map(value -> new NumericResponse<>(command, value)); }); })); @@ -98,7 +98,7 @@ public class LettuceReactiveClusterSetCommands extends LettuceReactiveSetCommand * @see org.springframework.data.redis.connection.lettuce.LettuceReactiveSetCommands#sInter(org.reactivestreams.Publisher) */ @Override - public Flux> sInter(Publisher commands) { + public Flux>> sInter(Publisher commands) { return getConnection().execute(cmd -> Flux.from(commands).flatMap(command -> { @@ -122,7 +122,7 @@ public class LettuceReactiveClusterSetCommands extends LettuceReactiveSetCommand return source; }); - return result.map(value -> new MultiValueResponse<>(command, value)); + return Mono.just(new CommandResponse<>(command, result.flatMap(v -> Flux.fromStream(v.stream())))); })); } @@ -145,7 +145,7 @@ public class LettuceReactiveClusterSetCommands extends LettuceReactiveSetCommand } return sInter(Mono.just(SInterCommand.keys(command.getKeys()))).next().flatMap(values -> { - Mono result = cmd.sadd(command.getKey(), values.getOutput().stream().toArray(ByteBuffer[]::new)); + Mono result = cmd.sadd(command.getKey(), values.getOutput().toStream().toArray(ByteBuffer[]::new)); return result.map(value -> new NumericResponse<>(command, value)); }); })); @@ -155,7 +155,7 @@ public class LettuceReactiveClusterSetCommands extends LettuceReactiveSetCommand * @see org.springframework.data.redis.connection.lettuce.LettuceReactiveSetCommands#sDiff(org.reactivestreams.Publisher) */ @Override - public Flux> sDiff(Publisher commands) { + public Flux>> sDiff(Publisher commands) { return getConnection().execute(cmd -> Flux.from(commands).flatMap(command -> { @@ -179,7 +179,7 @@ public class LettuceReactiveClusterSetCommands extends LettuceReactiveSetCommand return source; }); - return result.map(value -> new MultiValueResponse<>(command, value)); + return Mono.just(new CommandResponse<>(command, result.flatMap(v -> Flux.fromStream(v.stream())))); })); } @@ -203,7 +203,7 @@ public class LettuceReactiveClusterSetCommands extends LettuceReactiveSetCommand } return sDiff(Mono.just(SDiffCommand.keys(command.getKeys()))).next().flatMap(values -> { - Mono result = cmd.sadd(command.getKey(), values.getOutput().stream().toArray(ByteBuffer[]::new)); + Mono result = cmd.sadd(command.getKey(), values.getOutput().toStream().toArray(ByteBuffer[]::new)); return result.map(value -> new NumericResponse<>(command, value)); }); })); diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommands.java index cf4df5589..9f0dc37d6 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommands.java @@ -31,7 +31,6 @@ import org.reactivestreams.Publisher; import org.springframework.core.convert.converter.Converter; import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResult; -import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Metric; import org.springframework.data.geo.Point; import org.springframework.data.redis.connection.ReactiveGeoCommands; @@ -157,7 +156,7 @@ public class LettuceReactiveGeoCommands implements ReactiveGeoCommands { * @see org.springframework.data.redis.connection.ReactiveGeoCommands#geoRadius(org.reactivestreams.Publisher) */ @Override - public Flux>>> geoRadius( + public Flux>>>> geoRadius( Publisher commands) { return connection.execute(cmd -> Flux.from(commands).flatMap(command -> { @@ -169,12 +168,13 @@ public class LettuceReactiveGeoCommands implements ReactiveGeoCommands { GeoArgs geoArgs = command.getArgs().isPresent() ? LettuceConverters.toGeoArgs(command.getArgs().get()) : new GeoArgs(); - Mono>> result = cmd.georadius(command.getKey(), command.getPoint().getX(), - command.getPoint().getY(), command.getDistance().getValue(), - LettuceConverters.toGeoArgsUnit(command.getDistance().getMetric()), geoArgs) - .map(converter(command.getDistance().getMetric())::convert).collectList().map(GeoResults::new); + Flux>> result = cmd + .georadius(command.getKey(), command.getPoint().getX(), command.getPoint().getY(), + command.getDistance().getValue(), LettuceConverters.toGeoArgsUnit(command.getDistance().getMetric()), + geoArgs) // + .map(converter(command.getDistance().getMetric())::convert); - return result.map(value -> new CommandResponse<>(command, value)); + return Mono.just(new CommandResponse<>(command, result)); })); } @@ -183,7 +183,7 @@ public class LettuceReactiveGeoCommands implements ReactiveGeoCommands { * @see org.springframework.data.redis.connection.ReactiveGeoCommands#geoRadiusByMember(org.reactivestreams.Publisher) */ @Override - public Flux>>> geoRadiusByMember( + public Flux>>>> geoRadiusByMember( Publisher commands) { return connection.execute(cmd -> Flux.from(commands).flatMap(command -> { @@ -195,12 +195,12 @@ public class LettuceReactiveGeoCommands implements ReactiveGeoCommands { GeoArgs geoArgs = command.getArgs().isPresent() ? LettuceConverters.toGeoArgs(command.getArgs().get()) : new GeoArgs(); - Mono>> result = cmd + Flux>> result = cmd .georadiusbymember(command.getKey(), command.getMember(), command.getDistance().getValue(), LettuceConverters.toGeoArgsUnit(command.getDistance().getMetric()), geoArgs) - .map(converter(command.getDistance().getMetric())::convert).collectList().map(GeoResults::new); + .map(converter(command.getDistance().getMetric())::convert); - return result.map(value -> new CommandResponse<>(command, value)); + return Mono.just(new CommandResponse<>(command, result)); })); } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHashCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHashCommands.java index f43bb2bd9..1d899382e 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHashCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHashCommands.java @@ -168,15 +168,15 @@ public class LettuceReactiveHashCommands implements ReactiveHashCommands { * @see org.springframework.data.redis.connection.ReactiveHashCommands#hKeys(org.reactivestreams.Publisher) */ @Override - public Flux> hKeys(Publisher commands) { + public Flux>> hKeys(Publisher commands) { return connection.execute(cmd -> Flux.from(commands).flatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); - Mono> result = cmd.hkeys(command.getKey()).collectList(); + Flux result = cmd.hkeys(command.getKey()); - return result.map(value -> new MultiValueResponse<>(command, value)); + return Mono.just(new CommandResponse<>(command, result)); })); } @@ -185,15 +185,15 @@ public class LettuceReactiveHashCommands implements ReactiveHashCommands { * @see org.springframework.data.redis.connection.ReactiveHashCommands#hKeys(org.reactivestreams.Publisher) */ @Override - public Flux> hVals(Publisher commands) { + public Flux>> hVals(Publisher commands) { return connection.execute(cmd -> Flux.from(commands).flatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); - Mono> result = cmd.hvals(command.getKey()).collectList(); + Flux result = cmd.hvals(command.getKey()); - return result.map(value -> new MultiValueResponse<>(command, value)); + return Mono.just(new CommandResponse<>(command, result)); })); } @@ -202,7 +202,8 @@ public class LettuceReactiveHashCommands implements ReactiveHashCommands { * @see org.springframework.data.redis.connection.ReactiveHashCommands#hGetAll(org.reactivestreams.Publisher) */ @Override - public Flux>> hGetAll(Publisher commands) { + public Flux>>> hGetAll( + Publisher commands) { return connection.execute(cmd -> Flux.from(commands).flatMap(command -> { @@ -210,7 +211,7 @@ public class LettuceReactiveHashCommands implements ReactiveHashCommands { Mono> result = cmd.hgetall(command.getKey()); - return result.map(value -> new CommandResponse<>(command, value)); + return Mono.just(new CommandResponse<>(command, result.flatMapMany(v -> Flux.fromStream(v.entrySet().stream())))); })); } } 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 e73e27407..8b79cac52 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 @@ -24,6 +24,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.redis.connection.ReactiveListCommands; import org.springframework.data.redis.connection.ReactiveRedisConnection.BooleanResponse; 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; @@ -109,15 +110,15 @@ public class LettuceReactiveListCommands implements ReactiveListCommands { * @see org.springframework.data.redis.connection.ReactiveListCommands#lRange(org.reactivestreams.Publisher) */ @Override - public Flux> lRange(Publisher commands) { + public Flux>> lRange(Publisher commands) { return connection.execute(cmd -> Flux.from(commands).flatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getRange(), "Range must not be null!"); - return cmd.lrange(command.getKey(), command.getRange().getLowerBound(), command.getRange().getUpperBound()) - .collectList().map(value -> new MultiValueResponse<>(command, value)); + Flux result = cmd.lrange(command.getKey(), command.getRange().getLowerBound(), command.getRange().getUpperBound()); + return Mono.just(new CommandResponse<>(command, result)); })); } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSetCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSetCommands.java index 6adcbeec3..a9fece31c 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSetCommands.java @@ -15,22 +15,20 @@ */ package org.springframework.data.redis.connection.lettuce; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.List; import org.reactivestreams.Publisher; import org.springframework.data.redis.connection.ReactiveRedisConnection.BooleanResponse; 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.ReactiveSetCommands; import org.springframework.util.Assert; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - /** * @author Christoph Strobl * @author Mark Paluch @@ -155,14 +153,14 @@ public class LettuceReactiveSetCommands implements ReactiveSetCommands { * @see org.springframework.data.redis.connection.ReactiveSetCommands#sInter(org.reactivestreams.Publisher) */ @Override - public Flux> sInter(Publisher commands) { + public Flux>> sInter(Publisher commands) { return connection.execute(cmd -> Flux.from(commands).flatMap(command -> { Assert.notNull(command.getKeys(), "Keys must not be null!"); - return cmd.sinter(command.getKeys().stream().toArray(ByteBuffer[]::new)).collectList() - .map(value -> new MultiValueResponse<>(command, value)); + Flux result = cmd.sinter(command.getKeys().stream().toArray(ByteBuffer[]::new)); + return Mono.just(new CommandResponse<>(command, result)); })); } @@ -188,14 +186,14 @@ public class LettuceReactiveSetCommands implements ReactiveSetCommands { * @see org.springframework.data.redis.connection.ReactiveSetCommands#sInter(org.reactivestreams.Publisher) */ @Override - public Flux> sUnion(Publisher commands) { + public Flux>> sUnion(Publisher commands) { return connection.execute(cmd -> Flux.from(commands).flatMap(command -> { Assert.notNull(command.getKeys(), "Keys must not be null!"); - return cmd.sunion(command.getKeys().stream().toArray(ByteBuffer[]::new)).collectList() - .map(value -> new MultiValueResponse<>(command, value)); + Flux result = cmd.sunion(command.getKeys().stream().toArray(ByteBuffer[]::new)); + return Mono.just(new CommandResponse<>(command, result)); })); } @@ -221,14 +219,14 @@ public class LettuceReactiveSetCommands implements ReactiveSetCommands { * @see org.springframework.data.redis.connection.ReactiveSetCommands#sInter(org.reactivestreams.Publisher) */ @Override - public Flux> sDiff(Publisher commands) { + public Flux>> sDiff(Publisher commands) { return connection.execute(cmd -> Flux.from(commands).flatMap(command -> { Assert.notNull(command.getKeys(), "Keys must not be null!"); - return cmd.sdiff(command.getKeys().stream().toArray(ByteBuffer[]::new)).collectList() - .map(value -> new MultiValueResponse<>(command, value)); + Flux result = cmd.sdiff(command.getKeys().stream().toArray(ByteBuffer[]::new)); + return Mono.just(new CommandResponse<>(command, result)); })); } @@ -254,13 +252,14 @@ public class LettuceReactiveSetCommands implements ReactiveSetCommands { * @see org.springframework.data.redis.connection.ReactiveSetCommands#sMembers(org.reactivestreams.Publisher) */ @Override - public Flux> sMembers(Publisher commands) { + public Flux>> sMembers(Publisher commands) { return connection.execute(cmd -> Flux.from(commands).flatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); - return cmd.smembers(command.getKey()).collectList().map(value -> new MultiValueResponse<>(command, value)); + Flux result = cmd.smembers(command.getKey()); + return Mono.just(new CommandResponse<>(command, result)); })); } @@ -269,7 +268,7 @@ public class LettuceReactiveSetCommands implements ReactiveSetCommands { * @see org.springframework.data.redis.connection.ReactiveSetCommands#sRandMembers(org.reactivestreams.Publisher) */ @Override - public Flux> sRandMember( + public Flux>> sRandMember( Publisher commands) { return connection.execute(cmd -> Flux.from(commands).flatMap(command -> { @@ -278,10 +277,10 @@ public class LettuceReactiveSetCommands implements ReactiveSetCommands { boolean singleElement = !command.getCount().isPresent() || command.getCount().get().equals(1L); - Mono> result = singleElement ? cmd.srandmember(command.getKey()).map(Collections::singletonList) - : cmd.srandmember(command.getKey(), command.getCount().get()).collectList(); + Publisher result = singleElement ? cmd.srandmember(command.getKey()) + : cmd.srandmember(command.getKey(), command.getCount().get()); - return result.map(value -> new MultiValueResponse<>(command, value)); + return Mono.just(new CommandResponse<>(command, Flux.from(result))); })); } 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 ad67be957..5bc003369 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 @@ -32,8 +32,8 @@ import org.reactivestreams.Publisher; import org.springframework.core.convert.converter.Converter; import org.springframework.data.domain.Sort.Direction; import org.springframework.data.redis.connection.DefaultTuple; +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.ReactiveZSetCommands; import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; @@ -174,43 +174,39 @@ public class LettuceReactiveZSetCommands implements ReactiveZSetCommands { * @see org.springframework.data.redis.connection.ReactiveZSetCommands#zRange(org.reactivestreams.Publisher) */ @Override - public Flux> zRange(Publisher commands) { + public Flux>> zRange(Publisher commands) { return connection.execute(cmd -> Flux.from(commands).flatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getRange(), "Range must not be null!"); - Mono> result; + Flux result; 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())).collectList(); + result = cmd.zrangeWithScores(command.getKey(), command.getRange().getLowerBound(), + command.getRange().getUpperBound()).map(sc -> (Tuple) new DefaultTuple(getBytes(sc), sc.getScore())); } else { result = cmd.zrange(command.getKey(), command.getRange().getLowerBound(), command.getRange().getUpperBound()) - .map(value -> (Tuple) new DefaultTuple(ByteUtils.getBytes(value), Double.NaN)).collectList(); + .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())).collectList(); + result = cmd.zrevrangeWithScores(command.getKey(), command.getRange().getLowerBound(), + command.getRange().getUpperBound()).map(sc -> (Tuple) new DefaultTuple(getBytes(sc), sc.getScore())); } else { result = cmd .zrevrange(command.getKey(), command.getRange().getLowerBound(), command.getRange().getUpperBound()) - .map(value -> (Tuple) new DefaultTuple(ByteUtils.getBytes(value), Double.NaN)).collectList(); + .map(value -> (Tuple) new DefaultTuple(ByteUtils.getBytes(value), Double.NaN)); } } - return result.map(value -> new MultiValueResponse<>(command, value)); + return Mono.just(new CommandResponse<>(command, result)); })); } @@ -219,7 +215,8 @@ public class LettuceReactiveZSetCommands implements ReactiveZSetCommands { * @see org.springframework.data.redis.connection.ReactiveZSetCommands#zRange(org.reactivestreams.Publisher) */ @Override - public Flux> zRangeByScore(Publisher commands) { + public Flux>> zRangeByScore( + Publisher commands) { return connection.execute(cmd -> Flux.from(commands).flatMap(command -> { @@ -228,7 +225,7 @@ public class LettuceReactiveZSetCommands implements ReactiveZSetCommands { boolean isLimited = command.getLimit().isPresent(); - Mono> result; + Publisher result; if (ObjectUtils.nullSafeEquals(command.getDirection(), Direction.ASC)) { @@ -238,21 +235,21 @@ public class LettuceReactiveZSetCommands implements ReactiveZSetCommands { if (!isLimited) { result = cmd.zrangebyscoreWithScores(command.getKey(), range) - .map(sc -> (Tuple) new DefaultTuple(ByteUtils.getBytes(sc.getValue()), sc.getScore())).collectList(); + .map(sc -> (Tuple) new DefaultTuple(ByteUtils.getBytes(sc.getValue()), sc.getScore())); } else { result = cmd .zrangebyscoreWithScores(command.getKey(), range, LettuceConverters.toLimit(command.getLimit().get())) - .map(sc -> (Tuple) new DefaultTuple(ByteUtils.getBytes(sc.getValue()), sc.getScore())).collectList(); + .map(sc -> (Tuple) new DefaultTuple(ByteUtils.getBytes(sc.getValue()), sc.getScore())); } } else { if (!isLimited) { result = cmd.zrangebyscore(command.getKey(), range) - .map(value -> (Tuple) new DefaultTuple(ByteUtils.getBytes(value), Double.NaN)).collectList(); + .map(value -> (Tuple) new DefaultTuple(ByteUtils.getBytes(value), Double.NaN)); } else { result = cmd.zrangebyscore(command.getKey(), range, LettuceConverters.toLimit(command.getLimit().get())) - .map(value -> (Tuple) new DefaultTuple(ByteUtils.getBytes(value), Double.NaN)).collectList(); + .map(value -> (Tuple) new DefaultTuple(ByteUtils.getBytes(value), Double.NaN)); } } } else { @@ -263,28 +260,28 @@ public class LettuceReactiveZSetCommands implements ReactiveZSetCommands { if (!isLimited) { result = cmd.zrevrangebyscoreWithScores(command.getKey(), range) - .map(sc -> (Tuple) new DefaultTuple(ByteUtils.getBytes(sc.getValue()), sc.getScore())).collectList(); + .map(sc -> (Tuple) new DefaultTuple(ByteUtils.getBytes(sc.getValue()), sc.getScore())); } else { result = cmd .zrevrangebyscoreWithScores(command.getKey(), range, LettuceConverters.toLimit(command.getLimit().get())) - .map(sc -> (Tuple) new DefaultTuple(ByteUtils.getBytes(sc.getValue()), sc.getScore())).collectList(); + .map(sc -> (Tuple) new DefaultTuple(ByteUtils.getBytes(sc.getValue()), sc.getScore())); } } else { if (!isLimited) { result = cmd.zrevrangebyscore(command.getKey(), range) - .map(value -> (Tuple) new DefaultTuple(ByteUtils.getBytes(value), Double.NaN)).collectList(); + .map(value -> (Tuple) new DefaultTuple(ByteUtils.getBytes(value), Double.NaN)); } else { result = cmd.zrevrangebyscore(command.getKey(), range, LettuceConverters.toLimit(command.getLimit().get())) - .map(value -> (Tuple) new DefaultTuple(ByteUtils.getBytes(value), Double.NaN)).collectList(); + .map(value -> (Tuple) new DefaultTuple(ByteUtils.getBytes(value), Double.NaN)); } } } - return result.map(value -> new MultiValueResponse<>(command, value)); + return Mono.just(new CommandResponse<>(command, Flux.from(result))); })); } @@ -432,7 +429,8 @@ public class LettuceReactiveZSetCommands implements ReactiveZSetCommands { * @see org.springframework.data.redis.connection.ReactiveZSetCommands#zRangeByLex(org.reactivestreams.Publisher) */ @Override - public Flux> zRangeByLex(Publisher commands) { + public Flux>> zRangeByLex( + Publisher commands) { return connection.execute(cmd -> Flux.from(commands).flatMap(command -> { @@ -457,7 +455,7 @@ public class LettuceReactiveZSetCommands implements ReactiveZSetCommands { } } - return result.collectList().map(value -> new MultiValueResponse<>(command, value)); + return Mono.just(new CommandResponse<>(command, result)); })); } diff --git a/src/main/java/org/springframework/data/redis/core/DefaultReactiveGeoOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultReactiveGeoOperations.java index c0123e78f..acaee8013 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultReactiveGeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultReactiveGeoOperations.java @@ -15,7 +15,6 @@ */ package org.springframework.data.redis.core; -import org.springframework.data.redis.serializer.RedisSerializationContext; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -30,12 +29,12 @@ import org.reactivestreams.Publisher; import org.springframework.data.geo.Circle; import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResult; -import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Metric; import org.springframework.data.geo.Point; import org.springframework.data.redis.connection.ReactiveGeoCommands; import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation; import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs; +import org.springframework.data.redis.serializer.RedisSerializationContext; import org.springframework.util.Assert; /** @@ -234,72 +233,60 @@ public class DefaultReactiveGeoOperations implements ReactiveGeoOperations * @see org.springframework.data.redis.core.ReactiveGeoOperations#geoRadius(java.lang.Object, org.springframework.data.geo.Circle) */ @Override - public Mono>> geoRadius(K key, Circle within) { + public Flux>> geoRadius(K key, Circle within) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(within, "Circle must not be null!"); - return createMono(connection -> connection.geoRadius(rawKey(key), within) // - .flatMapMany(Flux::fromIterable) // - .map(location -> new GeoLocation<>(readValue(location.getName()), location.getPoint())) // - .collectList()); + return createFlux(connection -> connection.geoRadius(rawKey(key), within).map(this::readGeoResult)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveGeoOperations#geoRadius(java.lang.Object, org.springframework.data.geo.Circle, org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs) */ @Override - public Mono>> geoRadius(K key, Circle within, GeoRadiusCommandArgs args) { + public Flux>> geoRadius(K key, Circle within, GeoRadiusCommandArgs args) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(within, "Circle must not be null!"); Assert.notNull(args, "GeoRadiusCommandArgs must not be null!"); - return createMono(connection -> connection.geoRadius(rawKey(key), within, args) // - .flatMapMany(Flux::fromIterable) // - .map(geoResult -> new GeoResult<>( - new GeoLocation<>(readValue(geoResult.getContent().getName()), geoResult.getContent().getPoint()), - geoResult.getDistance())) // - .collectList() // - .map(GeoResults::new)); + return createFlux(connection -> connection.geoRadius(rawKey(key), within, args) // + .map(this::readGeoResult)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveGeoOperations#geoRadiusByMember(java.lang.Object, java.lang.Object, double) */ @Override - public Mono>> geoRadiusByMember(K key, V member, double radius) { + public Flux>> geoRadiusByMember(K key, V member, double radius) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(member, "Member must not be null!"); - return createMono(connection -> connection.geoRadiusByMember(rawKey(key), rawValue(member), new Distance(radius)) // - .flatMapMany(Flux::fromIterable) // - .map(geoLocation -> new GeoLocation<>(readValue(geoLocation.getName()), geoLocation.getPoint())) // - .collectList()); + return createFlux(connection -> connection.geoRadiusByMember(rawKey(key), rawValue(member), new Distance(radius)) // + .map(this::readGeoResult)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveGeoOperations#geoRadiusByMember(java.lang.Object, java.lang.Object, org.springframework.data.geo.Distance) */ @Override - public Mono>> geoRadiusByMember(K key, V member, Distance distance) { + public Flux>> geoRadiusByMember(K key, V member, Distance distance) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(member, "Member must not be null!"); Assert.notNull(distance, "Distance must not be null!"); - return createMono(connection -> connection.geoRadiusByMember(rawKey(key), rawValue(member), distance) // - .flatMapMany(Flux::fromIterable) // - .map(geoLocation -> new GeoLocation<>(readValue(geoLocation.getName()), geoLocation.getPoint())) // - .collectList()); + return createFlux(connection -> connection.geoRadiusByMember(rawKey(key), rawValue(member), distance) // + .map(this::readGeoResult)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveGeoOperations#geoRadiusByMember(java.lang.Object, java.lang.Object, org.springframework.data.geo.Distance, org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs) */ @Override - public Mono>> geoRadiusByMember(K key, V member, Distance distance, + public Flux>> geoRadiusByMember(K key, V member, Distance distance, GeoRadiusCommandArgs args) { Assert.notNull(key, "Key must not be null!"); @@ -307,13 +294,8 @@ public class DefaultReactiveGeoOperations implements ReactiveGeoOperations Assert.notNull(distance, "Distance must not be null!"); Assert.notNull(args, "GeoRadiusCommandArgs must not be null!"); - return createMono(connection -> connection.geoRadiusByMember(rawKey(key), rawValue(member), distance, args) // - .flatMapMany(Flux::fromIterable) // - .map(geoResult -> new GeoResult<>( - new GeoLocation<>(readValue(geoResult.getContent().getName()), geoResult.getContent().getPoint()), - geoResult.getDistance())) // - .collectList() // - .map(GeoResults::new)); + return createFlux(connection -> connection.geoRadiusByMember(rawKey(key), rawValue(member), distance, args)) + .map(this::readGeoResult); } /* (non-Javadoc) @@ -369,4 +351,10 @@ public class DefaultReactiveGeoOperations implements ReactiveGeoOperations private V readValue(ByteBuffer buffer) { return serializationContext.getValueSerializationPair().read(buffer); } + + private GeoResult> readGeoResult(GeoResult> source) { + + return new GeoResult<>(new GeoLocation(readValue(source.getContent().getName()), source.getContent().getPoint()), + source.getDistance()); + } } diff --git a/src/main/java/org/springframework/data/redis/core/DefaultReactiveHashOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultReactiveHashOperations.java index 66df09dca..2b3a2dcff 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultReactiveHashOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultReactiveHashOperations.java @@ -21,6 +21,7 @@ import reactor.core.publisher.Mono; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -151,14 +152,12 @@ public class DefaultReactiveHashOperations implements ReactiveHashOpe * @see org.springframework.data.redis.core.ReactiveHashOperations#keys(java.lang.Object) */ @Override - public Mono> keys(H key) { + public Flux keys(H key) { Assert.notNull(key, "Key must not be null!"); - return createMono(connection -> connection.hKeys(rawKey(key)) // - .flatMapMany(Flux::fromIterable) // - .map(this::readHashKey) // - .collectList()); + return createFlux(connection -> connection.hKeys(rawKey(key)) // + .map(this::readHashKey)); } /* (non-Javadoc) @@ -216,26 +215,24 @@ public class DefaultReactiveHashOperations implements ReactiveHashOpe * @see org.springframework.data.redis.core.ReactiveHashOperations#values(java.lang.Object) */ @Override - public Mono> values(H key) { + public Flux values(H key) { Assert.notNull(key, "Key must not be null!"); - return createMono(connection -> connection.hVals(rawKey(key)) // - .flatMapMany(Flux::fromIterable) // - .map(this::readHashValue) // - .collectList()); + return createFlux(connection -> connection.hVals(rawKey(key)) // + .map(this::readHashValue)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveHashOperations#entries(java.lang.Object) */ @Override - public Mono> entries(H key) { + public Flux> entries(H key) { Assert.notNull(key, "Key must not be null!"); - return createMono(connection -> connection.hGetAll(rawKey(key)) // - .map(this::deserializeHashEntries)); + return createFlux(connection -> connection.hGetAll(rawKey(key)) // + .map(this::deserializeHashEntry)); } /* (non-Javadoc) @@ -256,6 +253,13 @@ public class DefaultReactiveHashOperations implements ReactiveHashOpe return template.createMono(connection -> function.apply(connection.hashCommands())); } + private Flux createFlux(Function> function) { + + Assert.notNull(function, "Function must not be null!"); + + return template.createFlux(connection -> function.apply(connection.hashCommands())); + } + private ByteBuffer rawKey(H key) { return serializationContext.getKeySerializationPair().write(key); } @@ -278,15 +282,9 @@ public class DefaultReactiveHashOperations implements ReactiveHashOpe return (HV) serializationContext.getHashValueSerializationPair().read(value); } - private Map deserializeHashEntries(Map source) { - - Map deserialized = new LinkedHashMap<>(source.size()); - - source.forEach((k, v) -> { - deserialized.put(readHashKey(k), readHashValue(v)); - }); - - return deserialized; + private Map.Entry deserializeHashEntry(Map.Entry source) { + return Collections.singletonMap(readHashKey(source.getKey()), readHashValue(source.getValue())).entrySet() + .iterator().next(); } private List deserializeHashValues(List source) { diff --git a/src/main/java/org/springframework/data/redis/core/DefaultReactiveListOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultReactiveListOperations.java index 71fca3fd3..7c9ed5778 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultReactiveListOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultReactiveListOperations.java @@ -20,11 +20,9 @@ import reactor.core.publisher.Mono; import java.nio.ByteBuffer; import java.time.Duration; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.Function; @@ -66,11 +64,11 @@ public class DefaultReactiveListOperations implements ReactiveListOperatio * @see org.springframework.data.redis.core.ReactiveListOperations#range(java.lang.Object, long, long) */ @Override - public Mono> range(K key, long start, long end) { + public Flux range(K key, long start, long end) { Assert.notNull(key, "Key must not be null!"); - return createMono(connection -> connection.lRange(rawKey(key), start, end).map(this::deserializeValues)); + return createFlux(connection -> connection.lRange(rawKey(key), start, end).map(this::readValue)); } /* (non-Javadoc) @@ -340,6 +338,13 @@ public class DefaultReactiveListOperations implements ReactiveListOperatio return template.createMono(connection -> function.apply(connection.listCommands())); } + private Flux createFlux(Function> function) { + + Assert.notNull(function, "Function must not be null!"); + + return template.createFlux(connection -> function.apply(connection.listCommands())); + } + private boolean isZeroOrGreater1Second(Duration timeout) { return timeout.isZero() || timeout.getNano() % TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS) == 0; } @@ -355,15 +360,4 @@ public class DefaultReactiveListOperations implements ReactiveListOperatio private V readValue(ByteBuffer buffer) { return serializationContext.getValueSerializationPair().read(buffer); } - - private List deserializeValues(List source) { - - List result = new ArrayList(source.size()); - - for (ByteBuffer buffer : source) { - result.add(readValue(buffer)); - } - - return result; - } } diff --git a/src/main/java/org/springframework/data/redis/core/DefaultReactiveSetOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultReactiveSetOperations.java index c88fc5ed1..fd7841107 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultReactiveSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultReactiveSetOperations.java @@ -22,9 +22,7 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.LinkedHashSet; import java.util.List; -import java.util.Set; import java.util.function.Function; import org.reactivestreams.Publisher; @@ -147,7 +145,7 @@ public class DefaultReactiveSetOperations implements ReactiveSetOperations * @see org.springframework.data.redis.core.ReactiveSetOperations#intersect(java.lang.Object, java.lang.Object) */ @Override - public Mono> intersect(K key, K otherKey) { + public Flux intersect(K key, K otherKey) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(otherKey, "Other key must not be null!"); @@ -159,16 +157,16 @@ public class DefaultReactiveSetOperations implements ReactiveSetOperations * @see org.springframework.data.redis.core.ReactiveSetOperations#intersect(java.lang.Object, java.util.Collection) */ @Override - public Mono> intersect(K key, Collection otherKeys) { + public Flux intersect(K key, Collection otherKeys) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(otherKeys, "Other keys must not be null!"); - return createMono(connection -> Flux.fromIterable(getKeys(key, otherKeys)) // + return createFlux(connection -> Flux.fromIterable(getKeys(key, otherKeys)) // .map(this::rawKey) // .collectList() // - .flatMap(connection::sInter) // - .map(this::readValueSet)); + .flatMapMany(connection::sInter) // + .map(this::readValue)); } /* (non-Javadoc) @@ -204,7 +202,7 @@ public class DefaultReactiveSetOperations implements ReactiveSetOperations * @see org.springframework.data.redis.core.ReactiveSetOperations#union(java.lang.Object, java.lang.Object) */ @Override - public Mono> union(K key, K otherKey) { + public Flux union(K key, K otherKey) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(otherKey, "Other key must not be null!"); @@ -216,16 +214,16 @@ public class DefaultReactiveSetOperations implements ReactiveSetOperations * @see org.springframework.data.redis.core.ReactiveSetOperations#union(java.lang.Object, java.util.Collection) */ @Override - public Mono> union(K key, Collection otherKeys) { + public Flux union(K key, Collection otherKeys) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(otherKeys, "Other keys must not be null!"); - return createMono(connection -> Flux.fromIterable(getKeys(key, otherKeys)) // + return createFlux(connection -> Flux.fromIterable(getKeys(key, otherKeys)) // .map(this::rawKey) // .collectList() // - .flatMap(connection::sUnion) // - .map(this::readValueSet)); + .flatMapMany(connection::sUnion) // + .map(this::readValue)); } /* (non-Javadoc) @@ -261,7 +259,7 @@ public class DefaultReactiveSetOperations implements ReactiveSetOperations * @see org.springframework.data.redis.core.ReactiveSetOperations#difference(java.lang.Object, java.lang.Object) */ @Override - public Mono> difference(K key, K otherKey) { + public Flux difference(K key, K otherKey) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(otherKey, "Other key must not be null!"); @@ -273,16 +271,16 @@ public class DefaultReactiveSetOperations implements ReactiveSetOperations * @see org.springframework.data.redis.core.ReactiveSetOperations#difference(java.lang.Object, java.util.Collection) */ @Override - public Mono> difference(K key, Collection otherKeys) { + public Flux difference(K key, Collection otherKeys) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(otherKeys, "Other keys must not be null!"); - return createMono(connection -> Flux.fromIterable(getKeys(key, otherKeys)) // + return createFlux(connection -> Flux.fromIterable(getKeys(key, otherKeys)) // .map(this::rawKey) // .collectList() // - .flatMap(connection::sDiff) // - .map(this::readValueSet)); + .flatMapMany(connection::sDiff) // + .map(this::readValue)); } /* (non-Javadoc) @@ -318,11 +316,11 @@ public class DefaultReactiveSetOperations implements ReactiveSetOperations * @see org.springframework.data.redis.core.ReactiveSetOperations#members(java.lang.Object) */ @Override - public Mono> members(K key) { + public Flux members(K key) { Assert.notNull(key, "Key must not be null!"); - return createMono(connection -> connection.sMembers(rawKey(key)).map(this::readValueSet)); + return createFlux(connection -> connection.sMembers(rawKey(key)).map(this::readValue)); } /* (non-Javadoc) @@ -340,22 +338,22 @@ public class DefaultReactiveSetOperations implements ReactiveSetOperations * @see org.springframework.data.redis.core.ReactiveSetOperations#distinctRandomMembers(java.lang.Object, long) */ @Override - public Mono> distinctRandomMembers(K key, long count) { + public Flux distinctRandomMembers(K key, long count) { Assert.isTrue(count > 0, "Negative count not supported. Use randomMembers to allow duplicate elements."); - return createMono(connection -> connection.sRandMember(rawKey(key), count).map(this::readValueSet)); + return createFlux(connection -> connection.sRandMember(rawKey(key), count).map(this::readValue)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveSetOperations#randomMembers(java.lang.Object, long) */ @Override - public Mono> randomMembers(K key, long count) { + public Flux randomMembers(K key, long count) { Assert.isTrue(count > 0, "Use a positive number for count. This method is already allowing duplicate elements."); - return createMono(connection -> connection.sRandMember(rawKey(key), -count).map(this::readValueList)); + return createFlux(connection -> connection.sRandMember(rawKey(key), -count).map(this::readValue)); } /* (non-Javadoc) @@ -376,6 +374,13 @@ public class DefaultReactiveSetOperations implements ReactiveSetOperations return template.createMono(connection -> function.apply(connection.setCommands())); } + private Flux createFlux(Function> function) { + + Assert.notNull(function, "Function must not be null!"); + + return template.createFlux(connection -> function.apply(connection.setCommands())); + } + private ByteBuffer rawKey(K key) { return serializationContext.getKeySerializationPair().write(key); } @@ -397,26 +402,4 @@ public class DefaultReactiveSetOperations implements ReactiveSetOperations private V readValue(ByteBuffer buffer) { return serializationContext.getValueSerializationPair().read(buffer); } - - private Set readValueSet(Collection raw) { - - Set result = new LinkedHashSet<>(raw.size()); - - for (ByteBuffer buffer : raw) { - result.add(readValue(buffer)); - } - - return result; - } - - private List readValueList(Collection raw) { - - List result = new ArrayList<>(raw.size()); - - for (ByteBuffer buffer : raw) { - result.add(readValue(buffer)); - } - - return result; - } } 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 096be12be..e6abb5af4 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultReactiveZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultReactiveZSetOperations.java @@ -22,9 +22,7 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.LinkedHashSet; import java.util.List; -import java.util.Set; import java.util.function.Function; import org.reactivestreams.Publisher; @@ -151,150 +149,149 @@ public class DefaultReactiveZSetOperations implements ReactiveZSetOperatio * @see org.springframework.data.redis.core.ReactiveZSetOperations#range(java.lang.Object, org.springframework.data.domain.Range) */ @Override - public Mono> range(K key, Range range) { + public Flux range(K key, Range range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); - return createMono(connection -> connection.zRange(rawKey(key), range).map(this::readValueSet)); + return createFlux(connection -> connection.zRange(rawKey(key), range).map(this::readValue)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#rangeWithScores(java.lang.Object, org.springframework.data.domain.Range) */ @Override - public Mono>> rangeWithScores(K key, Range range) { + public Flux> rangeWithScores(K key, Range range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); - return createMono(connection -> connection.zRangeWithScores(rawKey(key), range).map(this::readTypedTupleSet)); + return createFlux(connection -> connection.zRangeWithScores(rawKey(key), range).map(this::readTypedTuple)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#rangeByScore(java.lang.Object, org.springframework.data.domain.Range) */ @Override - public Mono> rangeByScore(K key, Range range) { + public Flux rangeByScore(K key, Range range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); - return createMono(connection -> connection.zRangeByScore(rawKey(key), range).map(this::readValueSet)); + return createFlux(connection -> connection.zRangeByScore(rawKey(key), range).map(this::readValue)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#rangeByScoreWithScores(java.lang.Object, org.springframework.data.domain.Range) */ @Override - public Mono>> rangeByScoreWithScores(K key, Range range) { + public Flux> rangeByScoreWithScores(K key, Range range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); - return createMono( - connection -> connection.zRangeByScoreWithScores(rawKey(key), range).map(this::readTypedTupleSet)); + return createFlux(connection -> connection.zRangeByScoreWithScores(rawKey(key), range).map(this::readTypedTuple)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#rangeByScore(java.lang.Object, org.springframework.data.domain.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) */ @Override - public Mono> rangeByScore(K key, Range range, Limit limit) { + public Flux rangeByScore(K key, Range range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); - return createMono(connection -> connection.zRangeByScore(rawKey(key), range, limit).map(this::readValueSet)); + return createFlux(connection -> connection.zRangeByScore(rawKey(key), range, limit).map(this::readValue)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#rangeByScoreWithScores(java.lang.Object, org.springframework.data.domain.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) */ @Override - public Mono>> rangeByScoreWithScores(K key, Range range, Limit limit) { + public Flux> rangeByScoreWithScores(K key, Range range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); Assert.notNull(limit, "Limit must not be null!"); - return createMono( - connection -> connection.zRangeByScoreWithScores(rawKey(key), range, limit).map(this::readTypedTupleSet)); + return createFlux( + connection -> connection.zRangeByScoreWithScores(rawKey(key), range, limit).map(this::readTypedTuple)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#reverseRange(java.lang.Object, org.springframework.data.domain.Range) */ @Override - public Mono> reverseRange(K key, Range range) { + public Flux reverseRange(K key, Range range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); - return createMono(connection -> connection.zRevRange(rawKey(key), range).map(this::readValueSet)); + return createFlux(connection -> connection.zRevRange(rawKey(key), range).map(this::readValue)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#reverseRangeWithScores(java.lang.Object, org.springframework.data.domain.Range) */ @Override - public Mono>> reverseRangeWithScores(K key, Range range) { + public Flux> reverseRangeWithScores(K key, Range range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); - return createMono(connection -> connection.zRevRangeWithScores(rawKey(key), range).map(this::readTypedTupleSet)); + return createFlux(connection -> connection.zRevRangeWithScores(rawKey(key), range).map(this::readTypedTuple)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#reverseRangeByScore(java.lang.Object, org.springframework.data.domain.Range) */ @Override - public Mono> reverseRangeByScore(K key, Range range) { + public Flux reverseRangeByScore(K key, Range range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); - return createMono(connection -> connection.zRevRangeByScore(rawKey(key), range).map(this::readValueSet)); + return createFlux(connection -> connection.zRevRangeByScore(rawKey(key), range).map(this::readValue)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#reverseRangeByScoreWithScores(java.lang.Object, org.springframework.data.domain.Range) */ @Override - public Mono>> reverseRangeByScoreWithScores(K key, Range range) { + public Flux> reverseRangeByScoreWithScores(K key, Range range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); - return createMono( - connection -> connection.zRevRangeByScoreWithScores(rawKey(key), range).map(this::readTypedTupleSet)); + return createFlux( + connection -> connection.zRevRangeByScoreWithScores(rawKey(key), range).map(this::readTypedTuple)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#reverseRangeByScore(java.lang.Object, org.springframework.data.domain.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) */ @Override - public Mono> reverseRangeByScore(K key, Range range, Limit limit) { + public Flux reverseRangeByScore(K key, Range range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); - return createMono(connection -> connection.zRevRangeByScore(rawKey(key), range, limit).map(this::readValueSet)); + return createFlux(connection -> connection.zRevRangeByScore(rawKey(key), range, limit).map(this::readValue)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#reverseRangeByScoreWithScores(java.lang.Object, org.springframework.data.domain.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) */ @Override - public Mono>> reverseRangeByScoreWithScores(K key, Range range, Limit limit) { + public Flux> reverseRangeByScoreWithScores(K key, Range range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); Assert.notNull(limit, "Limit must not be null!"); - return createMono( - connection -> connection.zRevRangeByScoreWithScores(rawKey(key), range, limit).map(this::readTypedTupleSet)); + return createFlux( + connection -> connection.zRevRangeByScoreWithScores(rawKey(key), range, limit).map(this::readTypedTuple)); } /* (non-Javadoc) @@ -418,50 +415,50 @@ public class DefaultReactiveZSetOperations implements ReactiveZSetOperatio * @see org.springframework.data.redis.core.ReactiveZSetOperations#rangeByLex(java.lang.Object, org.springframework.data.domain.Range) */ @Override - public Mono> rangeByLex(K key, Range range) { + public Flux rangeByLex(K key, Range range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); - return createMono(connection -> connection.zRangeByLex(rawKey(key), range).map(this::readValueSet)); + return createFlux(connection -> connection.zRangeByLex(rawKey(key), range).map(this::readValue)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#rangeByLex(java.lang.Object, org.springframework.data.domain.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) */ @Override - public Mono> rangeByLex(K key, Range range, Limit limit) { + public Flux rangeByLex(K key, Range range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); Assert.notNull(limit, "Limit must not be null!"); - return createMono(connection -> connection.zRangeByLex(rawKey(key), range, limit).map(this::readValueSet)); + return createFlux(connection -> connection.zRangeByLex(rawKey(key), range, limit).map(this::readValue)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#reverseRangeByLex(java.lang.Object, org.springframework.data.domain.Range) */ @Override - public Mono> reverseRangeByLex(K key, Range range) { + public Flux reverseRangeByLex(K key, Range range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); - return createMono(connection -> connection.zRevRangeByLex(rawKey(key), range).map(this::readValueSet)); + return createFlux(connection -> connection.zRevRangeByLex(rawKey(key), range).map(this::readValue)); } /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveZSetOperations#reverseRangeByLex(java.lang.Object, org.springframework.data.domain.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) */ @Override - public Mono> reverseRangeByLex(K key, Range range, Limit limit) { + public Flux reverseRangeByLex(K key, Range range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); Assert.notNull(limit, "Limit must not be null!"); - return createMono(connection -> connection.zRevRangeByLex(rawKey(key), range, limit).map(this::readValueSet)); + return createFlux(connection -> connection.zRevRangeByLex(rawKey(key), range, limit).map(this::readValue)); } /* (non-Javadoc) @@ -482,6 +479,13 @@ public class DefaultReactiveZSetOperations implements ReactiveZSetOperatio return template.createMono(connection -> function.apply(connection.zSetCommands())); } + private Flux createFlux(Function> function) { + + Assert.notNull(function, "Function must not be null!"); + + return template.createFlux(connection -> function.apply(connection.zSetCommands())); + } + private ByteBuffer rawKey(K key) { return serializationContext.getKeySerializationPair().write(key); } @@ -504,25 +508,7 @@ public class DefaultReactiveZSetOperations implements ReactiveZSetOperatio return serializationContext.getValueSerializationPair().read(buffer); } - private Set readValueSet(Collection raw) { - - Set result = new LinkedHashSet<>(raw.size()); - - for (ByteBuffer buffer : raw) { - result.add(readValue(buffer)); - } - - return result; - } - - private Set> readTypedTupleSet(Collection raw) { - - Set> result = new LinkedHashSet<>(raw.size()); - - for (Tuple tuple : raw) { - result.add(new DefaultTypedTuple<>(readValue(ByteBuffer.wrap(tuple.getValue())), tuple.getScore())); - } - - return result; + private TypedTuple readTypedTuple(Tuple raw) { + return new DefaultTypedTuple<>(readValue(ByteBuffer.wrap(raw.getValue())), raw.getScore()); } } diff --git a/src/main/java/org/springframework/data/redis/core/ReactiveGeoOperations.java b/src/main/java/org/springframework/data/redis/core/ReactiveGeoOperations.java index c6eb50922..909e5bcab 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveGeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveGeoOperations.java @@ -25,7 +25,7 @@ import java.util.Map; import org.reactivestreams.Publisher; import org.springframework.data.geo.Circle; import org.springframework.data.geo.Distance; -import org.springframework.data.geo.GeoResults; +import org.springframework.data.geo.GeoResult; import org.springframework.data.geo.Metric; import org.springframework.data.geo.Point; import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation; @@ -35,6 +35,7 @@ import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusComma * Reactive Redis operations for geo commands. * * @author Mark Paluch + * @author Christoph Strobl * @see Redis Documentation: Geo Commands * @since 2.0 */ @@ -162,7 +163,7 @@ public interface ReactiveGeoOperations { * @return never {@literal null}. * @see Redis Documentation: GEORADIUS */ - Mono>> geoRadius(K key, Circle within); + Flux>> geoRadius(K key, Circle within); /** * Get the {@literal member}s within the boundaries of a given {@link Circle} applying {@link GeoRadiusCommandArgs}. @@ -173,7 +174,7 @@ public interface ReactiveGeoOperations { * @return never {@literal null}. * @see Redis Documentation: GEORADIUS */ - Mono>> geoRadius(K key, Circle within, GeoRadiusCommandArgs args); + Flux>> geoRadius(K key, Circle within, GeoRadiusCommandArgs args); /** * Get the {@literal member}s within the circle defined by the {@literal members} coordinates and given @@ -185,7 +186,7 @@ public interface ReactiveGeoOperations { * @return never {@literal null}. * @see Redis Documentation: GEORADIUSBYMEMBER */ - Mono>> geoRadiusByMember(K key, M member, double radius); + Flux>> geoRadiusByMember(K key, M member, double radius); /** * Get the {@literal member}s within the circle defined by the {@literal members} coordinates and given @@ -197,7 +198,7 @@ public interface ReactiveGeoOperations { * @return never {@literal null}. * @see Redis Documentation: GEORADIUSBYMEMBER */ - Mono>> geoRadiusByMember(K key, M member, Distance distance); + Flux>> geoRadiusByMember(K key, M member, Distance distance); /** * Get the {@literal member}s within the circle defined by the {@literal members} coordinates and given @@ -210,7 +211,7 @@ public interface ReactiveGeoOperations { * @return never {@literal null}. * @see Redis Documentation: GEORADIUSBYMEMBER */ - Mono>> geoRadiusByMember(K key, M member, Distance distance, GeoRadiusCommandArgs args); + Flux>> geoRadiusByMember(K key, M member, Distance distance, GeoRadiusCommandArgs args); /** * Remove the {@literal member}s. diff --git a/src/main/java/org/springframework/data/redis/core/ReactiveHashOperations.java b/src/main/java/org/springframework/data/redis/core/ReactiveHashOperations.java index 1196fb351..c1e14aa39 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveHashOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveHashOperations.java @@ -15,6 +15,7 @@ */ package org.springframework.data.redis.core; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.util.Collection; @@ -25,6 +26,7 @@ import java.util.Map; * Redis map specific operations working on a hash. * * @author Mark Paluch + * @author Christoph Strobl * @since 2.0 */ public interface ReactiveHashOperations { @@ -91,7 +93,7 @@ public interface ReactiveHashOperations { * @param key must not be {@literal null}. * @return */ - Mono> keys(H key); + Flux keys(H key); /** * Get size of hash at {@code key}. @@ -134,7 +136,7 @@ public interface ReactiveHashOperations { * @param key must not be {@literal null}. * @return */ - Mono> values(H key); + Flux values(H key); /** * Get entire hash stored at {@code key}. @@ -142,7 +144,7 @@ public interface ReactiveHashOperations { * @param key must not be {@literal null}. * @return */ - Mono> entries(H key); + Flux> entries(H key); /** * Removes the given {@literal key}. diff --git a/src/main/java/org/springframework/data/redis/core/ReactiveListOperations.java b/src/main/java/org/springframework/data/redis/core/ReactiveListOperations.java index fc4670325..15860c8b8 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveListOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveListOperations.java @@ -15,6 +15,7 @@ */ package org.springframework.data.redis.core; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.time.Duration; @@ -25,6 +26,8 @@ import java.util.List; * Redis list specific operations. * * @author Mark Paluch + * @author Christoph Strobl + * @see Redis Documentation: List Commands * @since 2.0 */ public interface ReactiveListOperations { @@ -38,7 +41,7 @@ public interface ReactiveListOperations { * @return * @see Redis Documentation: LRANGE */ - Mono> range(K key, long start, long end); + Flux range(K key, long start, long end); /** * Trim list at {@code key} to elements between {@code start} and {@code end}. diff --git a/src/main/java/org/springframework/data/redis/core/ReactiveSetOperations.java b/src/main/java/org/springframework/data/redis/core/ReactiveSetOperations.java index d378eae07..071150159 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveSetOperations.java @@ -15,16 +15,17 @@ */ package org.springframework.data.redis.core; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.util.Collection; -import java.util.List; -import java.util.Set; /** * Redis set specific operations. * * @author Mark Paluch + * @author Christoph Strobl + * @see Redis Documentation: Set Commands * @since 2.0 */ public interface ReactiveSetOperations { @@ -96,7 +97,7 @@ public interface ReactiveSetOperations { * @return * @see Redis Documentation: SINTER */ - Mono> intersect(K key, K otherKey); + Flux intersect(K key, K otherKey); /** * Returns the members intersecting all given sets at {@code key} and {@code otherKeys}. @@ -106,7 +107,7 @@ public interface ReactiveSetOperations { * @return * @see Redis Documentation: SINTER */ - Mono> intersect(K key, Collection otherKeys); + Flux intersect(K key, Collection otherKeys); /** * Intersect all given sets at {@code key} and {@code otherKey} and store result in {@code destKey}. @@ -138,7 +139,7 @@ public interface ReactiveSetOperations { * @return * @see Redis Documentation: SUNION */ - Mono> union(K key, K otherKey); + Flux union(K key, K otherKey); /** * Union all sets at given {@code keys} and {@code otherKeys}. @@ -148,7 +149,7 @@ public interface ReactiveSetOperations { * @return * @see Redis Documentation: SUNION */ - Mono> union(K key, Collection otherKeys); + Flux union(K key, Collection otherKeys); /** * Union all sets at given {@code key} and {@code otherKey} and store result in {@code destKey}. @@ -180,7 +181,7 @@ public interface ReactiveSetOperations { * @return * @see Redis Documentation: SDIFF */ - Mono> difference(K key, K otherKey); + Flux difference(K key, K otherKey); /** * Diff all sets for given {@code key} and {@code otherKeys}. @@ -190,7 +191,7 @@ public interface ReactiveSetOperations { * @return * @see Redis Documentation: SDIFF */ - Mono> difference(K key, Collection otherKeys); + Flux difference(K key, Collection otherKeys); /** * Diff all sets for given {@code key} and {@code otherKey} and store result in {@code destKey}. @@ -221,7 +222,7 @@ public interface ReactiveSetOperations { * @return * @see Redis Documentation: SMEMBERS */ - Mono> members(K key); + Flux members(K key); /** * Get random element from set at {@code key}. @@ -240,7 +241,7 @@ public interface ReactiveSetOperations { * @return * @see Redis Documentation: SRANDMEMBER */ - Mono> distinctRandomMembers(K key, long count); + Flux distinctRandomMembers(K key, long count); /** * Get {@code count} random elements from set at {@code key}. @@ -250,7 +251,7 @@ public interface ReactiveSetOperations { * @return * @see Redis Documentation: SRANDMEMBER */ - Mono> randomMembers(K key, long count); + Flux randomMembers(K key, long count); /** * Removes the given {@literal key}. 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 fa26085e8..9ecd27882 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveZSetOperations.java @@ -15,10 +15,10 @@ */ package org.springframework.data.redis.core; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.util.Collection; -import java.util.Set; import org.springframework.data.domain.Range; import org.springframework.data.redis.connection.RedisZSetCommands.Limit; @@ -29,6 +29,8 @@ import org.springframework.data.redis.core.ZSetOperations.TypedTuple; * Redis ZSet/sorted set specific operations. * * @author Mark Paluch + * @author Christoph Strobl + * @see Redis Documentation: Sorted Set Commands * @since 2.0 */ public interface ReactiveZSetOperations { @@ -103,7 +105,7 @@ public interface ReactiveZSetOperations { * @return * @see Redis Documentation: ZRANGE */ - Mono> range(K key, Range range); + Flux range(K key, Range range); /** * Get set of {@link Tuple}s between {@code start} and {@code end} from sorted set. @@ -113,7 +115,7 @@ public interface ReactiveZSetOperations { * @return * @see Redis Documentation: ZRANGE */ - Mono>> rangeWithScores(K key, Range range); + Flux> rangeWithScores(K key, Range range); /** * Get elements where score is between {@code min} and {@code max} from sorted set. @@ -123,7 +125,7 @@ public interface ReactiveZSetOperations { * @return * @see Redis Documentation: ZRANGEBYSCORE */ - Mono> rangeByScore(K key, Range range); + Flux rangeByScore(K key, Range range); /** * Get set of {@link Tuple}s where score is between {@code min} and {@code max} from sorted set. @@ -133,7 +135,7 @@ public interface ReactiveZSetOperations { * @return * @see Redis Documentation: ZRANGEBYSCORE */ - Mono>> rangeByScoreWithScores(K key, Range range); + Flux> rangeByScoreWithScores(K key, Range range); /** * Get elements in range from {@code start} to {@code end} where score is between {@code min} and {@code max} from @@ -145,7 +147,7 @@ public interface ReactiveZSetOperations { * @return * @see Redis Documentation: ZRANGEBYSCORE */ - Mono> rangeByScore(K key, Range range, Limit limit); + Flux rangeByScore(K key, Range range, Limit limit); /** * Get set of {@link Tuple}s in range from {@code start} to {@code end} where score is between {@code min} and @@ -157,7 +159,7 @@ public interface ReactiveZSetOperations { * @return * @see Redis Documentation: ZRANGEBYSCORE */ - Mono>> rangeByScoreWithScores(K key, Range range, Limit limit); + Flux> rangeByScoreWithScores(K key, Range range, Limit limit); /** * Get elements in range from {@code start} to {@code end} from sorted set ordered from high to low. @@ -167,7 +169,7 @@ public interface ReactiveZSetOperations { * @return * @see Redis Documentation: ZREVRANGE */ - Mono> reverseRange(K key, Range range); + Flux reverseRange(K key, Range range); /** * Get set of {@link Tuple}s in range from {@code start} to {@code end} from sorted set ordered from high to low. @@ -177,7 +179,7 @@ public interface ReactiveZSetOperations { * @return * @see Redis Documentation: ZREVRANGE */ - Mono>> reverseRangeWithScores(K key, Range range); + Flux> reverseRangeWithScores(K key, Range range); /** * Get elements where score is between {@code min} and {@code max} from sorted set ordered from high to low. @@ -187,7 +189,7 @@ public interface ReactiveZSetOperations { * @return * @see Redis Documentation: ZREVRANGE */ - Mono> reverseRangeByScore(K key, Range range); + Flux reverseRangeByScore(K key, Range range); /** * Get set of {@link Tuple} where score is between {@code min} and {@code max} from sorted set ordered from high to @@ -198,7 +200,7 @@ public interface ReactiveZSetOperations { * @return * @see Redis Documentation: ZREVRANGEBYSCORE */ - Mono>> reverseRangeByScoreWithScores(K key, Range range); + Flux> reverseRangeByScoreWithScores(K key, Range range); /** * Get elements in range from {@code start} to {@code end} where score is between {@code min} and {@code max} from @@ -210,7 +212,7 @@ public interface ReactiveZSetOperations { * @return * @see Redis Documentation: ZREVRANGEBYSCORE */ - Mono> reverseRangeByScore(K key, Range range, Limit limit); + Flux reverseRangeByScore(K key, Range range, Limit limit); /** * Get set of {@link Tuple} in range from {@code start} to {@code end} where score is between {@code min} and @@ -222,7 +224,7 @@ public interface ReactiveZSetOperations { * @return * @see Redis Documentation: ZREVRANGEBYSCORE */ - Mono>> reverseRangeByScoreWithScores(K key, Range range, Limit limit); + Flux> reverseRangeByScoreWithScores(K key, Range range, Limit limit); /** * Count number of elements within sorted set with scores between {@code min} and {@code max}. @@ -325,7 +327,7 @@ public interface ReactiveZSetOperations { * @param range must not be {@literal null}. * @see Redis Documentation: ZRANGEBYLEX */ - Mono> rangeByLex(K key, Range range); + Flux rangeByLex(K key, Range range); /** * Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at @@ -338,7 +340,7 @@ public interface ReactiveZSetOperations { * @return * @see Redis Documentation: ZRANGEBYLEX */ - Mono> rangeByLex(K key, Range range, Limit limit); + Flux rangeByLex(K key, Range range, Limit limit); /** * Get all elements with reverse lexicographical ordering from {@literal ZSET} at {@code key} with a value between @@ -348,7 +350,7 @@ public interface ReactiveZSetOperations { * @param range must not be {@literal null}. * @see Redis Documentation: ZREVRANGEBYLEX */ - Mono> reverseRangeByLex(K key, Range range); + Flux reverseRangeByLex(K key, Range range); /** * Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at @@ -361,7 +363,7 @@ public interface ReactiveZSetOperations { * @return * @see Redis Documentation: ZREVRANGEBYLEX */ - Mono> reverseRangeByLex(K key, Range range, Limit limit); + Flux reverseRangeByLex(K key, Range range, Limit limit); /** * Removes the given {@literal key}. diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommandsTests.java index 454a796a4..4c32f7c0f 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommandsTests.java @@ -15,7 +15,6 @@ */ package org.springframework.data.redis.connection.lettuce; -import static org.hamcrest.collection.IsCollectionWithSize.*; import static org.hamcrest.collection.IsIterableContainingInOrder.*; import static org.hamcrest.core.Is.*; import static org.hamcrest.core.IsNull.*; @@ -24,6 +23,8 @@ import static org.junit.Assert.*; import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*; import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*; +import reactor.test.StepVerifier; + import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.Arrays; @@ -32,7 +33,6 @@ import java.util.List; import org.junit.Test; import org.springframework.data.geo.Circle; import org.springframework.data.geo.Distance; -import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Metrics; import org.springframework.data.geo.Point; import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation; @@ -150,14 +150,17 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME); nativeCommands.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO_MEMBER_NAME); - assertThat( - connection.geoCommands() - .geoRadius(KEY_1_BBUFFER, new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS))).block(), - hasSize(3)); - assertThat( - connection.geoCommands() - .geoRadius(KEY_1_BBUFFER, new Circle(new Point(15D, 37D), new Distance(150D, KILOMETERS))).block(), - hasSize(2)); + StepVerifier + .create(connection.geoCommands().geoRadius(KEY_1_BBUFFER, + new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)))) // + .expectNextCount(3) // + .expectComplete(); + + StepVerifier + .create(connection.geoCommands().geoRadius(KEY_1_BBUFFER, + new Circle(new Point(15D, 37D), new Distance(150D, KILOMETERS)))) // + .expectNextCount(2) // + .expectComplete(); } @Test // DATAREDIS-525 @@ -167,11 +170,15 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME); nativeCommands.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO_MEMBER_NAME); - GeoResults> result = connection.geoCommands().geoRadius(KEY_1_BBUFFER, - new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().includeDistance()).block(); + StepVerifier + .create(connection.geoCommands().geoRadius(KEY_1_BBUFFER, + new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().includeDistance())) // + .consumeNextWith(actual -> { - assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(130.423D, 0.005))); - assertThat(result.getContent().get(0).getDistance().getUnit(), is("km")); + assertThat(actual.getDistance().getValue(), is(closeTo(130.423D, 0.005))); + assertThat(actual.getDistance().getUnit(), is("km")); + }) // + .expectComplete(); } @Test // DATAREDIS-525 @@ -181,10 +188,11 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME); nativeCommands.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO_MEMBER_NAME); - GeoResults> result = connection.geoCommands().geoRadius(KEY_1_BBUFFER, - new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().limit(2)).block(); - - assertThat(result.getContent(), hasSize(2)); + StepVerifier + .create(connection.geoCommands().geoRadius(KEY_1_BBUFFER, + new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().limit(2))) // + .expectNextCount(2) // + .expectComplete(); } @Test // DATAREDIS-525 @@ -194,11 +202,16 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME); nativeCommands.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO_MEMBER_NAME); - List> result = connection.geoCommands() - .geoRadiusByMember(KEY_1_BBUFFER, ARIGENTO.getName(), new Distance(100, KILOMETERS)).block(); - - assertThat(result.get(0).getName(), is(ARIGENTO.getName())); - assertThat(result.get(1).getName(), is(PALERMO.getName())); + StepVerifier + .create(connection.geoCommands().geoRadiusByMember(KEY_1_BBUFFER, ARIGENTO.getName(), + new Distance(100, KILOMETERS))) // + .consumeNextWith(actual -> { + assertThat(actual.getContent().getName(), is(ARIGENTO.getName())); + }) // + .consumeNextWith(actual -> { + assertThat(actual.getContent().getName(), is(PALERMO.getName())); + }) // + .expectComplete(); } @Test // DATAREDIS-525 @@ -208,12 +221,17 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME); nativeCommands.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO_MEMBER_NAME); - GeoResults> result = connection.geoCommands().geoRadiusByMember(KEY_1_BBUFFER, - PALERMO.getName(), new Distance(100, KILOMETERS), newGeoRadiusArgs().includeDistance()).block(); + StepVerifier + .create(connection.geoCommands().geoRadiusByMember(KEY_1_BBUFFER, PALERMO.getName(), + new Distance(100, KILOMETERS), newGeoRadiusArgs().includeDistance())) // + .consumeNextWith(actual -> { + + assertThat(actual.getDistance().getValue(), is(closeTo(90.978D, 0.005))); + assertThat(actual.getDistance().getUnit(), is("km")); + }) // + .expectNextCount(1) // + .verifyComplete(); - assertThat(result.getContent(), hasSize(2)); - assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(90.978D, 0.005))); - assertThat(result.getContent().get(0).getDistance().getUnit(), is("km")); } @Test // DATAREDIS-525 @@ -223,11 +241,11 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME); nativeCommands.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO_MEMBER_NAME); - GeoResults> result = connection.geoCommands() - .geoRadiusByMember(KEY_1_BBUFFER, PALERMO.getName(), new Distance(200, KILOMETERS), newGeoRadiusArgs().limit(2)) - .block(); - - assertThat(result.getContent(), hasSize(2)); + StepVerifier + .create(connection.geoCommands().geoRadiusByMember(KEY_1_BBUFFER, PALERMO.getName(), + new Distance(200, KILOMETERS), newGeoRadiusArgs().limit(2))) // + .expectNextCount(2) // + .verifyComplete(); } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHashCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHashCommandsTests.java index 6977068e2..b7780c8cc 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHashCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHashCommandsTests.java @@ -15,13 +15,14 @@ */ package org.springframework.data.redis.connection.lettuce; -import static org.hamcrest.collection.IsIterableContainingInAnyOrder.*; import static org.hamcrest.collection.IsIterableContainingInOrder.*; import static org.hamcrest.core.Is.*; import static org.hamcrest.core.IsEqual.*; import static org.hamcrest.core.IsNull.*; import static org.junit.Assert.*; +import reactor.test.StepVerifier; + import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.Arrays; @@ -170,8 +171,9 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes nativeCommands.hset(KEY_1, FIELD_2, VALUE_2); nativeCommands.hset(KEY_1, FIELD_3, VALUE_3); - assertThat(connection.hashCommands().hKeys(KEY_1_BBUFFER).block(), - containsInAnyOrder(FIELD_1_BBUFFER, FIELD_2_BBUFFER, FIELD_3_BBUFFER)); + StepVerifier.create(connection.hashCommands().hKeys(KEY_1_BBUFFER)) // + .expectNext(FIELD_1_BBUFFER, FIELD_2_BBUFFER, FIELD_3_BBUFFER) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -181,8 +183,9 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes nativeCommands.hset(KEY_1, FIELD_2, VALUE_2); nativeCommands.hset(KEY_1, FIELD_3, VALUE_3); - assertThat(connection.hashCommands().hVals(KEY_1_BBUFFER).block(), - containsInAnyOrder(VALUE_1_BBUFFER, VALUE_2_BBUFFER, VALUE_3_BBUFFER)); + StepVerifier.create(connection.hashCommands().hVals(KEY_1_BBUFFER)) + .expectNext(VALUE_1_BBUFFER, VALUE_2_BBUFFER, VALUE_3_BBUFFER) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -197,6 +200,11 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes expected.put(FIELD_2_BBUFFER, VALUE_2_BBUFFER); expected.put(FIELD_3_BBUFFER, VALUE_3_BBUFFER); - assertThat(connection.hashCommands().hGetAll(KEY_1_BBUFFER).block(), is(equalTo(expected))); + StepVerifier.create(connection.hashCommands().hGetAll(KEY_1_BBUFFER).buffer(3)) // + .consumeNextWith(list -> { + assertTrue(list.containsAll(expected.entrySet())); + }) // + .verifyComplete(); + } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommandTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommandTests.java index 41156a7a8..212d00b03 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommandTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommandTests.java @@ -101,7 +101,7 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3); - assertThat(connection.listCommands().lRange(KEY_1_BBUFFER, 1, 2).block(), + assertThat(connection.listCommands().lRange(KEY_1_BBUFFER, 1, 2).toIterable(), contains(VALUE_2_BBUFFER, VALUE_3_BBUFFER)); } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSetCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSetCommandsTests.java index 233b216e5..1d8ca5380 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSetCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSetCommandsTests.java @@ -16,17 +16,15 @@ package org.springframework.data.redis.connection.lettuce; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.*; -import static org.hamcrest.collection.IsIterableContainingInOrder.*; import static org.hamcrest.core.AnyOf.*; import static org.hamcrest.core.Is.*; import static org.hamcrest.core.IsEqual.*; -import static org.hamcrest.core.IsNot.*; import static org.hamcrest.core.IsNull.*; import static org.junit.Assert.*; -import java.nio.ByteBuffer; +import reactor.test.StepVerifier; + import java.util.Arrays; -import java.util.List; import org.junit.Test; @@ -137,9 +135,9 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2); nativeCommands.sadd(KEY_2, VALUE_2, VALUE_3); - List result = connection.setCommands().sInter(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block(); - assertThat(result, contains(VALUE_2_BBUFFER)); - assertThat(result, not(containsInAnyOrder(VALUE_1_BBUFFER, VALUE_3_BBUFFER))); + StepVerifier.create(connection.setCommands().sInter(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER))) // + .expectNext(VALUE_2_BBUFFER) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -159,8 +157,9 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2); nativeCommands.sadd(KEY_2, VALUE_2, VALUE_3); - List result = connection.setCommands().sUnion(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block(); - assertThat(result, containsInAnyOrder(VALUE_1_BBUFFER, VALUE_3_BBUFFER, VALUE_2_BBUFFER)); + StepVerifier.create(connection.setCommands().sUnion(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER))) // + .expectNextCount(3) // + .expectComplete(); } @Test // DATAREDIS-525 @@ -179,9 +178,9 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2); nativeCommands.sadd(KEY_2, VALUE_2, VALUE_3); - List result = connection.setCommands().sDiff(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block(); - assertThat(result, containsInAnyOrder(VALUE_1_BBUFFER)); - assertThat(result, not(containsInAnyOrder(VALUE_2_BBUFFER, VALUE_3_BBUFFER))); + StepVerifier.create(connection.setCommands().sDiff(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER))) // + .expectNext(VALUE_1_BBUFFER) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -199,8 +198,10 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3); - assertThat(connection.setCommands().sMembers(KEY_1_BBUFFER).block(), - containsInAnyOrder(VALUE_1_BBUFFER, VALUE_2_BBUFFER, VALUE_3_BBUFFER)); + StepVerifier.create(connection.setCommands().sMembers(KEY_1_BBUFFER).buffer(3)) // + .consumeNextWith( + list -> assertThat(list, containsInAnyOrder(VALUE_1_BBUFFER, VALUE_2_BBUFFER, VALUE_3_BBUFFER))) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -217,7 +218,9 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3); - assertThat(connection.setCommands().sRandMember(KEY_1_BBUFFER, 2L).block().size(), is(2)); + StepVerifier.create(connection.setCommands().sRandMember(KEY_1_BBUFFER, 2L)) // + .expectNextCount(2) // + .verifyComplete(); } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveZSetCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveZSetCommandsTests.java index d49f265cc..253bc5008 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveZSetCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveZSetCommandsTests.java @@ -19,6 +19,8 @@ import static org.hamcrest.core.Is.*; import static org.junit.Assert.*; import static org.junit.Assume.*; +import reactor.test.StepVerifier; + import java.nio.ByteBuffer; import java.util.Arrays; @@ -85,8 +87,9 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat(connection.zSetCommands().zRange(KEY_1_BBUFFER, new Range(1L, 2L)).block(), - IsIterableContainingInOrder.contains(VALUE_2_BBUFFER, VALUE_3_BBUFFER)); + StepVerifier.create(connection.zSetCommands().zRange(KEY_1_BBUFFER, new Range(1L, 2L))) // + .expectNext(VALUE_2_BBUFFER, VALUE_3_BBUFFER) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -96,9 +99,9 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat(connection.zSetCommands().zRangeWithScores(KEY_1_BBUFFER, new Range(1L, 2L)).block(), - IsIterableContainingInOrder.contains(new DefaultTuple(VALUE_2_BBUFFER.array(), 2D), - new DefaultTuple(VALUE_3_BBUFFER.array(), 3D))); + StepVerifier.create(connection.zSetCommands().zRangeWithScores(KEY_1_BBUFFER, new Range(1L, 2L))) // + .expectNext(new DefaultTuple(VALUE_2_BBUFFER.array(), 2D), new DefaultTuple(VALUE_3_BBUFFER.array(), 3D)) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -108,8 +111,9 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat(connection.zSetCommands().zRevRange(KEY_1_BBUFFER, new Range(1L, 2L)).block(), - IsIterableContainingInOrder.contains(VALUE_2_BBUFFER, VALUE_1_BBUFFER)); + StepVerifier.create(connection.zSetCommands().zRevRange(KEY_1_BBUFFER, new Range(1L, 2L))) // + .expectNext(VALUE_2_BBUFFER, VALUE_1_BBUFFER) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -119,9 +123,9 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat(connection.zSetCommands().zRevRangeWithScores(KEY_1_BBUFFER, new Range(1L, 2L)).block(), - IsIterableContainingInOrder.contains(new DefaultTuple(VALUE_2_BBUFFER.array(), 2D), - new DefaultTuple(VALUE_1_BBUFFER.array(), 1D))); + StepVerifier.create(connection.zSetCommands().zRevRangeWithScores(KEY_1_BBUFFER, new Range(1L, 2L))) // + .expectNext(new DefaultTuple(VALUE_2_BBUFFER.array(), 2D), new DefaultTuple(VALUE_1_BBUFFER.array(), 1D)) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -131,8 +135,9 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat(connection.zSetCommands().zRangeByScore(KEY_1_BBUFFER, new Range<>(2D, 3D)).block(), - IsIterableContainingInOrder.contains(VALUE_2_BBUFFER, VALUE_3_BBUFFER)); + StepVerifier.create(connection.zSetCommands().zRangeByScore(KEY_1_BBUFFER, new Range<>(2D, 3D))) // + .expectNext(VALUE_2_BBUFFER, VALUE_3_BBUFFER) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -142,8 +147,9 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat(connection.zSetCommands().zRangeByScore(KEY_1_BBUFFER, new Range<>(2D, 3D, false, true)).block(), - IsIterableContainingInOrder.contains(VALUE_3_BBUFFER)); + StepVerifier.create(connection.zSetCommands().zRangeByScore(KEY_1_BBUFFER, new Range<>(2D, 3D, false, true))) // + .expectNext(VALUE_3_BBUFFER) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -153,8 +159,9 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat(connection.zSetCommands().zRangeByScore(KEY_1_BBUFFER, new Range<>(2D, 3D, true, false)).block(), - IsIterableContainingInOrder.contains(VALUE_2_BBUFFER)); + StepVerifier.create(connection.zSetCommands().zRangeByScore(KEY_1_BBUFFER, new Range<>(2D, 3D, true, false))) // + .expectNext(VALUE_2_BBUFFER) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -164,9 +171,9 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat(connection.zSetCommands().zRangeByScoreWithScores(KEY_1_BBUFFER, new Range<>(2D, 3D)).block(), - IsIterableContainingInOrder.contains(new DefaultTuple(VALUE_2_BBUFFER.array(), 2D), - new DefaultTuple(VALUE_3_BBUFFER.array(), 3D))); + StepVerifier.create(connection.zSetCommands().zRangeByScoreWithScores(KEY_1_BBUFFER, new Range<>(2D, 3D))) // + .expectNext(new DefaultTuple(VALUE_2_BBUFFER.array(), 2D), new DefaultTuple(VALUE_3_BBUFFER.array(), 3D)) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -176,9 +183,10 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat( - connection.zSetCommands().zRangeByScoreWithScores(KEY_1_BBUFFER, new Range<>(2D, 3D, false, true)).block(), - IsIterableContainingInOrder.contains(new DefaultTuple(VALUE_3_BBUFFER.array(), 3D))); + StepVerifier + .create(connection.zSetCommands().zRangeByScoreWithScores(KEY_1_BBUFFER, new Range<>(2D, 3D, false, true))) // + .expectNext(new DefaultTuple(VALUE_3_BBUFFER.array(), 3D)) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -188,9 +196,10 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat( - connection.zSetCommands().zRangeByScoreWithScores(KEY_1_BBUFFER, new Range<>(2D, 3D, true, false)).block(), - IsIterableContainingInOrder.contains(new DefaultTuple(VALUE_2_BBUFFER.array(), 2D))); + StepVerifier + .create(connection.zSetCommands().zRangeByScoreWithScores(KEY_1_BBUFFER, new Range<>(2D, 3D, true, false))) // + .expectNext(new DefaultTuple(VALUE_2_BBUFFER.array(), 2D)) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -200,8 +209,9 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat(connection.zSetCommands().zRevRangeByScore(KEY_1_BBUFFER, new Range<>(2D, 3D)).block(), - IsIterableContainingInOrder.contains(VALUE_3_BBUFFER, VALUE_2_BBUFFER)); + StepVerifier.create(connection.zSetCommands().zRevRangeByScore(KEY_1_BBUFFER, new Range<>(2D, 3D))) // + .expectNext(VALUE_3_BBUFFER, VALUE_2_BBUFFER) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -211,8 +221,9 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat(connection.zSetCommands().zRevRangeByScore(KEY_1_BBUFFER, new Range<>(2D, 3D, false, true)).block(), - IsIterableContainingInOrder.contains(VALUE_3_BBUFFER)); + StepVerifier.create(connection.zSetCommands().zRevRangeByScore(KEY_1_BBUFFER, new Range<>(2D, 3D, false, true))) // + .expectNext(VALUE_3_BBUFFER) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -222,8 +233,9 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat(connection.zSetCommands().zRevRangeByScore(KEY_1_BBUFFER, new Range<>(2D, 3D, true, false)).block(), - IsIterableContainingInOrder.contains(VALUE_2_BBUFFER)); + StepVerifier.create(connection.zSetCommands().zRevRangeByScore(KEY_1_BBUFFER, new Range<>(2D, 3D, true, false))) // + .expectNext(VALUE_2_BBUFFER) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -233,9 +245,9 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat(connection.zSetCommands().zRevRangeByScoreWithScores(KEY_1_BBUFFER, new Range<>(2D, 3D)).block(), - IsIterableContainingInOrder.contains(new DefaultTuple(VALUE_3_BBUFFER.array(), 3D), - new DefaultTuple(VALUE_2_BBUFFER.array(), 2D))); + StepVerifier.create(connection.zSetCommands().zRevRangeByScoreWithScores(KEY_1_BBUFFER, new Range<>(2D, 3D))) // + .expectNext(new DefaultTuple(VALUE_3_BBUFFER.array(), 3D), new DefaultTuple(VALUE_2_BBUFFER.array(), 2D)) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -245,9 +257,10 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat( - connection.zSetCommands().zRevRangeByScoreWithScores(KEY_1_BBUFFER, new Range<>(2D, 3D, false, true)).block(), - IsIterableContainingInOrder.contains(new DefaultTuple(VALUE_3_BBUFFER.array(), 3D))); + StepVerifier + .create(connection.zSetCommands().zRevRangeByScoreWithScores(KEY_1_BBUFFER, new Range<>(2D, 3D, false, true))) // + .expectNext(new DefaultTuple(VALUE_3_BBUFFER.array(), 3D)) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -257,9 +270,10 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 2D, VALUE_2); nativeCommands.zadd(KEY_1, 3D, VALUE_3); - assertThat( - connection.zSetCommands().zRevRangeByScoreWithScores(KEY_1_BBUFFER, new Range<>(2D, 3D, true, false)).block(), - IsIterableContainingInOrder.contains(new DefaultTuple(VALUE_2_BBUFFER.array(), 2D))); + StepVerifier + .create(connection.zSetCommands().zRevRangeByScoreWithScores(KEY_1_BBUFFER, new Range<>(2D, 3D, true, false))) // + .expectNext(new DefaultTuple(VALUE_2_BBUFFER.array(), 2D)) // + .verifyComplete(); } @Test // DATAREDIS-525 @@ -443,14 +457,17 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 0D, "f"); nativeCommands.zadd(KEY_1, 0D, "g"); - assertThat(connection.zSetCommands().zRangeByLex(KEY_1_BBUFFER, new Range<>("", "c")).block(), + assertThat(connection.zSetCommands().zRangeByLex(KEY_1_BBUFFER, new Range<>("", "c")).collectList().block(), IsIterableContainingInOrder.contains(ByteBuffer.wrap("a".getBytes()), ByteBuffer.wrap("b".getBytes()), ByteBuffer.wrap("c".getBytes()))); - assertThat(connection.zSetCommands().zRangeByLex(KEY_1_BBUFFER, new Range<>("", "c", true, false)).block(), + assertThat( + connection.zSetCommands().zRangeByLex(KEY_1_BBUFFER, new Range<>("", "c", true, false)).collectList().block(), IsIterableContainingInOrder.contains(ByteBuffer.wrap("a".getBytes()), ByteBuffer.wrap("b".getBytes()))); - assertThat(connection.zSetCommands().zRangeByLex(KEY_1_BBUFFER, new Range<>("aaa", "g", true, false)).block(), + assertThat( + connection.zSetCommands().zRangeByLex(KEY_1_BBUFFER, new Range<>("aaa", "g", true, false)).collectList() + .block(), IsIterableContainingInOrder.contains(ByteBuffer.wrap("b".getBytes()), ByteBuffer.wrap("c".getBytes()), ByteBuffer.wrap("d".getBytes()), ByteBuffer.wrap("e".getBytes()), ByteBuffer.wrap("f".getBytes()))); } @@ -466,14 +483,18 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes nativeCommands.zadd(KEY_1, 0D, "f"); nativeCommands.zadd(KEY_1, 0D, "g"); - assertThat(connection.zSetCommands().zRevRangeByLex(KEY_1_BBUFFER, new Range<>("", "c")).block(), + assertThat(connection.zSetCommands().zRevRangeByLex(KEY_1_BBUFFER, new Range<>("", "c")).collectList().block(), IsIterableContainingInOrder.contains(ByteBuffer.wrap("c".getBytes()), ByteBuffer.wrap("b".getBytes()), ByteBuffer.wrap("a".getBytes()))); - assertThat(connection.zSetCommands().zRevRangeByLex(KEY_1_BBUFFER, new Range<>("", "c", true, false)).block(), + assertThat( + connection.zSetCommands().zRevRangeByLex(KEY_1_BBUFFER, new Range<>("", "c", true, false)).collectList() + .block(), IsIterableContainingInOrder.contains(ByteBuffer.wrap("b".getBytes()), ByteBuffer.wrap("a".getBytes()))); - assertThat(connection.zSetCommands().zRevRangeByLex(KEY_1_BBUFFER, new Range<>("aaa", "g", true, false)).block(), + assertThat( + connection.zSetCommands().zRevRangeByLex(KEY_1_BBUFFER, new Range<>("aaa", "g", true, false)).collectList() + .block(), IsIterableContainingInOrder.contains(ByteBuffer.wrap("f".getBytes()), ByteBuffer.wrap("e".getBytes()), ByteBuffer.wrap("d".getBytes()), ByteBuffer.wrap("c".getBytes()), ByteBuffer.wrap("b".getBytes()))); } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveGeoOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveGeoOperationsIntegrationTests.java index 7614ed0f4..a06dc0040 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveGeoOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveGeoOperationsIntegrationTests.java @@ -139,7 +139,9 @@ public class DefaultReactiveGeoOperationsIntegrationTests { memberCoordinateMap.put(valueFactory.instance(), POINT_PALERMO); memberCoordinateMap.put(valueFactory.instance(), POINT_CATANIA); - StepVerifier.create(geoOperations.geoAdd(key, memberCoordinateMap)).expectNext(2L).verifyComplete(); + StepVerifier.create(geoOperations.geoAdd(key, memberCoordinateMap)) // + .expectNext(2L) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -150,7 +152,9 @@ public class DefaultReactiveGeoOperationsIntegrationTests { List> geoLocations = Arrays.asList(new GeoLocation<>(valueFactory.instance(), POINT_ARIGENTO), new GeoLocation<>(valueFactory.instance(), POINT_PALERMO)); - StepVerifier.create(geoOperations.geoAdd(key, geoLocations)).expectNext(2L).verifyComplete(); + StepVerifier.create(geoOperations.geoAdd(key, geoLocations)) // + .expectNext(2L) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -165,8 +169,9 @@ public class DefaultReactiveGeoOperationsIntegrationTests { Flux>> geoLocations = Flux.just(batch1, batch2); - StepVerifier.create(geoOperations.geoAdd(key, geoLocations)).expectNext(2L).expectNext(1L).expectComplete() - .verify(); + StepVerifier.create(geoOperations.geoAdd(key, geoLocations)).expectNext(2L) // + .expectNext(1L) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -179,11 +184,13 @@ public class DefaultReactiveGeoOperationsIntegrationTests { geoOperations.geoAdd(key, POINT_PALERMO, member1).block(); geoOperations.geoAdd(key, POINT_CATANIA, member2).block(); - StepVerifier.create(geoOperations.geoDist(key, member1, member2)).consumeNextWith(actual -> { + StepVerifier.create(geoOperations.geoDist(key, member1, member2)) // + .consumeNextWith(actual -> { - assertThat(actual.getValue()).isCloseTo(DISTANCE_PALERMO_CATANIA_METERS, offset(0.005)); - assertThat(actual.getUnit()).isEqualTo("m"); - }).verifyComplete(); + assertThat(actual.getValue()).isCloseTo(DISTANCE_PALERMO_CATANIA_METERS, offset(0.005)); + assertThat(actual.getUnit()).isEqualTo("m"); + }) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -196,11 +203,13 @@ public class DefaultReactiveGeoOperationsIntegrationTests { geoOperations.geoAdd(key, POINT_PALERMO, member1).block(); geoOperations.geoAdd(key, POINT_CATANIA, member2).block(); - StepVerifier.create(geoOperations.geoDist(key, member1, member2, Metrics.KILOMETERS)).consumeNextWith(actual -> { + StepVerifier.create(geoOperations.geoDist(key, member1, member2, Metrics.KILOMETERS)) // + .consumeNextWith(actual -> { - assertThat(actual.getValue()).isCloseTo(DISTANCE_PALERMO_CATANIA_KILOMETERS, offset(0.005)); - assertThat(actual.getUnit()).isEqualTo("km"); - }).verifyComplete(); + assertThat(actual.getValue()).isCloseTo(DISTANCE_PALERMO_CATANIA_KILOMETERS, offset(0.005)); + assertThat(actual.getUnit()).isEqualTo("km"); + }) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -213,8 +222,7 @@ public class DefaultReactiveGeoOperationsIntegrationTests { StepVerifier.create(geoOperations.geoHash(key, v1)) // .expectNext("sqc8b49rny0") // - .expectComplete() // - .verify(); + .verifyComplete(); } @Test // DATAREDIS-602 @@ -230,8 +238,7 @@ public class DefaultReactiveGeoOperationsIntegrationTests { StepVerifier.create(geoOperations.geoHash(key, v1, v3, v2)) // .expectNext(Arrays.asList("sqc8b49rny0", null, "sqdtr74hyu0")) // - .expectComplete() // - .verify(); + .verifyComplete(); } @Test // DATAREDIS-602 @@ -247,8 +254,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests { assertThat(actual.getX()).isCloseTo(POINT_PALERMO.getX(), offset(0.005)); assertThat(actual.getY()).isCloseTo(POINT_PALERMO.getY(), offset(0.005)); - }).expectComplete() // - .verify(); + }) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -270,8 +277,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests { assertThat(actual.get(1)).isNull(); assertThat(actual.get(2)).isNotNull(); - }).expectComplete() // - .verify(); + }) // + .verifyComplete(); } @Test // DATAREDIS-438 @@ -284,8 +291,9 @@ public class DefaultReactiveGeoOperationsIntegrationTests { geoOperations.geoAdd(key, POINT_PALERMO, member1).block(); geoOperations.geoAdd(key, POINT_CATANIA, member2).block(); - StepVerifier.create(geoOperations.geoRadius(key, new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)))) - .consumeNextWith(actual -> assertThat(actual).hasSize(2)).verifyComplete(); + StepVerifier.create(geoOperations.geoRadius(key, new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)))) // + .expectNextCount(2) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -298,16 +306,20 @@ public class DefaultReactiveGeoOperationsIntegrationTests { geoOperations.geoAdd(key, POINT_PALERMO, member1).block(); geoOperations.geoAdd(key, POINT_CATANIA, member2).block(); - StepVerifier.create(geoOperations.geoRadius(key, new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), - newGeoRadiusArgs().includeDistance().sortDescending())).consumeNextWith(actual -> { - assertThat(actual).hasSize(2); + StepVerifier + .create(geoOperations.geoRadius(key, new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), + newGeoRadiusArgs().includeDistance().sortDescending())) // + .consumeNextWith(actual -> { - assertThat(actual.getContent().get(0).getDistance().getValue()).isCloseTo(190.4424d, offset(0.005)); - assertThat(actual.getContent().get(0).getContent().getName()).isEqualTo(member1); + assertThat(actual.getDistance().getValue()).isCloseTo(190.4424d, offset(0.005)); + assertThat(actual.getContent().getName()).isEqualTo(member1); + }) // + .consumeNextWith(actual -> { - assertThat(actual.getContent().get(1).getDistance().getValue()).isCloseTo(56.4413d, offset(0.005)); - assertThat(actual.getContent().get(1).getContent().getName()).isEqualTo(member2); - }).verifyComplete(); + assertThat(actual.getDistance().getValue()).isCloseTo(56.4413d, offset(0.005)); + assertThat(actual.getContent().getName()).isEqualTo(member2); + }) // + .verifyComplete(); } @Test // DATAREDIS-438 @@ -320,10 +332,9 @@ public class DefaultReactiveGeoOperationsIntegrationTests { geoOperations.geoAdd(key, POINT_PALERMO, member1).block(); geoOperations.geoAdd(key, POINT_CATANIA, member2).block(); - StepVerifier.create(geoOperations.geoRadius(key, new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)))) - .consumeNextWith(actual -> assertThat(actual).hasSize(2)) // - .expectComplete() // - .verify(); + StepVerifier.create(geoOperations.geoRadius(key, new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)))) // + .expectNextCount(2) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -340,14 +351,12 @@ public class DefaultReactiveGeoOperationsIntegrationTests { StepVerifier.create(geoOperations.geoRadiusByMember(key, member3, 100_000)) // .consumeNextWith(actual -> { - - assertThat(actual).hasSize(2); - - assertThat(actual.get(0).getName()).isEqualTo(member3); - assertThat(actual.get(1).getName()).isEqualTo(member1); + assertThat(actual.getContent().getName()).isEqualTo(member3); }) // - .expectComplete() // - .verify(); + .consumeNextWith(actual -> { + assertThat(actual.getContent().getName()).isEqualTo(member1); + }) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -362,14 +371,14 @@ public class DefaultReactiveGeoOperationsIntegrationTests { geoOperations.geoAdd(key, POINT_CATANIA, member2).block(); geoOperations.geoAdd(key, POINT_ARIGENTO, member3).block(); - StepVerifier.create(geoOperations.geoRadiusByMember(key, member3, new Distance(100D, KILOMETERS))) + StepVerifier.create(geoOperations.geoRadiusByMember(key, member3, new Distance(100D, KILOMETERS))) // .consumeNextWith(actual -> { - - assertThat(actual).hasSize(2); - - assertThat(actual.get(0).getName()).isEqualTo(member3); - assertThat(actual.get(1).getName()).isEqualTo(member1); - }).verifyComplete(); + assertThat(actual.getContent().getName()).isEqualTo(member3); + }) // + .consumeNextWith(actual -> { + assertThat(actual.getContent().getName()).isEqualTo(member1); + }) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -384,17 +393,20 @@ public class DefaultReactiveGeoOperationsIntegrationTests { geoOperations.geoAdd(key, POINT_CATANIA, member2).block(); geoOperations.geoAdd(key, POINT_ARIGENTO, member3).block(); - StepVerifier.create(geoOperations.geoRadiusByMember(key, member3, new Distance(100D, KILOMETERS), - newGeoRadiusArgs().includeDistance().sortDescending())).consumeNextWith(actual -> { + StepVerifier + .create(geoOperations.geoRadiusByMember(key, member3, new Distance(100D, KILOMETERS), + newGeoRadiusArgs().includeDistance().sortDescending())) // + .consumeNextWith(actual -> { - assertThat(actual).hasSize(2); + assertThat(actual.getDistance().getValue()).isCloseTo(90.9778, offset(0.005)); + assertThat(actual.getContent().getName()).isEqualTo(member1); + }) // + .consumeNextWith(actual -> { - assertThat(actual.getContent().get(0).getDistance().getValue()).isCloseTo(90.9778, offset(0.005)); - assertThat(actual.getContent().get(0).getContent().getName()).isEqualTo(member1); - - assertThat(actual.getContent().get(1).getDistance().getValue()).isCloseTo(0.0, offset(0.005)); - assertThat(actual.getContent().get(1).getContent().getName()).isEqualTo(member3); - }).verifyComplete(); + assertThat(actual.getDistance().getValue()).isCloseTo(0.0, offset(0.005)); + assertThat(actual.getContent().getName()).isEqualTo(member3); + }) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -407,8 +419,11 @@ public class DefaultReactiveGeoOperationsIntegrationTests { geoOperations.geoAdd(key, POINT_PALERMO, member1).block(); geoOperations.geoAdd(key, POINT_CATANIA, member2).block(); - StepVerifier.create(geoOperations.geoRemove(key, member1)).expectNext(1L).verifyComplete(); - StepVerifier.create(geoOperations.geoPos(key, member1)).verifyComplete(); + StepVerifier.create(geoOperations.geoRemove(key, member1)) // + .expectNext(1L) // + .verifyComplete(); + StepVerifier.create(geoOperations.geoPos(key, member1)) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -419,7 +434,10 @@ public class DefaultReactiveGeoOperationsIntegrationTests { geoOperations.geoAdd(key, POINT_PALERMO, member1).block(); - StepVerifier.create(geoOperations.delete(key)).expectNext(true).verifyComplete(); - StepVerifier.create(geoOperations.geoPos(key, member1)).verifyComplete(); + StepVerifier.create(geoOperations.delete(key)) // + .expectNext(true) // + .verifyComplete(); + StepVerifier.create(geoOperations.geoPos(key, member1)) // + .verifyComplete(); } } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveHashOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveHashOperationsIntegrationTests.java index 992436135..f2c2708b2 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveHashOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveHashOperationsIntegrationTests.java @@ -22,8 +22,10 @@ import reactor.test.StepVerifier; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import org.junit.AfterClass; import org.junit.Before; @@ -120,7 +122,10 @@ public class DefaultReactiveHashOperationsIntegrationTests { HV hashvalue2 = hashValueFactory.instance(); putAll(key, hashkey1, hashvalue1, hashkey2, hashvalue2); - StepVerifier.create(hashOperations.remove(key, hashkey1, hashkey2)).expectNext(2L).verifyComplete(); + + StepVerifier.create(hashOperations.remove(key, hashkey1, hashkey2)) // + .expectNext(2L) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -130,11 +135,17 @@ public class DefaultReactiveHashOperationsIntegrationTests { HK hashkey = hashKeyFactory.instance(); HV hashvalue = hashValueFactory.instance(); - StepVerifier.create(hashOperations.put(key, hashkey, hashvalue)).expectNext(true).verifyComplete(); + StepVerifier.create(hashOperations.put(key, hashkey, hashvalue)) // + .expectNext(true) // + .verifyComplete(); - StepVerifier.create(hashOperations.hasKey(key, hashkey)).expectNext(true).verifyComplete(); - StepVerifier.create(hashOperations.hasKey(key, hashKeyFactory.instance())).expectNext(false).expectComplete() - .verify(); + StepVerifier.create(hashOperations.hasKey(key, hashkey)) // + .expectNext(true) // + .verifyComplete(); + + StepVerifier.create(hashOperations.hasKey(key, hashKeyFactory.instance())) // + .expectNext(false) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -144,9 +155,13 @@ public class DefaultReactiveHashOperationsIntegrationTests { HK hashkey = hashKeyFactory.instance(); HV hashvalue = hashValueFactory.instance(); - StepVerifier.create(hashOperations.put(key, hashkey, hashvalue)).expectNext(true).verifyComplete(); + StepVerifier.create(hashOperations.put(key, hashkey, hashvalue)) // + .expectNext(true) // + .verifyComplete(); - StepVerifier.create(hashOperations.get(key, hashkey)).expectNextCount(1).verifyComplete(); + StepVerifier.create(hashOperations.get(key, hashkey)) // + .expectNextCount(1) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -163,9 +178,11 @@ public class DefaultReactiveHashOperationsIntegrationTests { putAll(key, hashkey1, hashvalue1, hashkey2, hashvalue2); - StepVerifier.create(hashOperations.multiGet(key, Arrays.asList(hashkey1, hashkey2))).consumeNextWith(actual -> { - assertThat(actual).hasSize(2).containsSequence(hashvalue1, hashvalue2); - }).verifyComplete(); + StepVerifier.create(hashOperations.multiGet(key, Arrays.asList(hashkey1, hashkey2))) // + .consumeNextWith(actual -> { + assertThat(actual).hasSize(2).containsSequence(hashvalue1, hashvalue2); + }) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -177,9 +194,17 @@ public class DefaultReactiveHashOperationsIntegrationTests { HK hashkey = hashKeyFactory.instance(); HV hashvalue = (HV) "1"; - StepVerifier.create(hashOperations.put(key, hashkey, hashvalue)).expectNext(true).verifyComplete(); - StepVerifier.create(hashOperations.increment(key, hashkey, 1L)).expectNext(2L).verifyComplete(); - StepVerifier.create(hashOperations.get(key, hashkey)).expectNext((HV) "2").verifyComplete(); + StepVerifier.create(hashOperations.put(key, hashkey, hashvalue)) // + .expectNext(true) // + .verifyComplete(); + + StepVerifier.create(hashOperations.increment(key, hashkey, 1L)) // + .expectNext(2L) // + .verifyComplete(); + + StepVerifier.create(hashOperations.get(key, hashkey)) // + .expectNext((HV) "2") // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -192,9 +217,17 @@ public class DefaultReactiveHashOperationsIntegrationTests { HK hashkey = hashKeyFactory.instance(); HV hashvalue = (HV) "1"; - StepVerifier.create(hashOperations.put(key, hashkey, hashvalue)).expectNext(true).verifyComplete(); - StepVerifier.create(hashOperations.increment(key, hashkey, 1.1d)).expectNext(2.1d).verifyComplete(); - StepVerifier.create(hashOperations.get(key, hashkey)).expectNext((HV) "2.1").verifyComplete(); + StepVerifier.create(hashOperations.put(key, hashkey, hashvalue)) // + .expectNext(true) // + .verifyComplete(); + + StepVerifier.create(hashOperations.increment(key, hashkey, 1.1d)) // + .expectNext(2.1d) // + .verifyComplete(); + + StepVerifier.create(hashOperations.get(key, hashkey)) // + .expectNext((HV) "2.1") // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -211,9 +244,9 @@ public class DefaultReactiveHashOperationsIntegrationTests { putAll(key, hashkey1, hashvalue1, hashkey2, hashvalue2); - StepVerifier.create(hashOperations.keys(key)).consumeNextWith(actual -> { - assertThat(actual).hasSize(2).contains(hashkey1, hashkey2); - }).verifyComplete(); + StepVerifier.create(hashOperations.keys(key).buffer(2)) // + .consumeNextWith(list -> assertThat(list).containsExactlyInAnyOrder(hashkey1, hashkey2)) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -228,7 +261,9 @@ public class DefaultReactiveHashOperationsIntegrationTests { putAll(key, hashkey1, hashvalue1, hashkey2, hashvalue2); - StepVerifier.create(hashOperations.size(key)).expectNext(2L).verifyComplete(); + StepVerifier.create(hashOperations.size(key)) // + .expectNext(2L) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -243,8 +278,13 @@ public class DefaultReactiveHashOperationsIntegrationTests { putAll(key, hashkey1, hashvalue1, hashkey2, hashvalue2); - StepVerifier.create(hashOperations.hasKey(key, hashkey1)).expectNext(true).verifyComplete(); - StepVerifier.create(hashOperations.hasKey(key, hashkey2)).expectNext(true).verifyComplete(); + StepVerifier.create(hashOperations.hasKey(key, hashkey1)) // + .expectNext(true) // + .verifyComplete(); + + StepVerifier.create(hashOperations.hasKey(key, hashkey2)) // + .expectNext(true) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -254,7 +294,9 @@ public class DefaultReactiveHashOperationsIntegrationTests { HK hashkey = hashKeyFactory.instance(); HV hashvalue = hashValueFactory.instance(); - StepVerifier.create(hashOperations.put(key, hashkey, hashvalue)).expectNext(true).verifyComplete(); + StepVerifier.create(hashOperations.put(key, hashkey, hashvalue)) // + .expectNext(true) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -265,9 +307,13 @@ public class DefaultReactiveHashOperationsIntegrationTests { HV hashvalue = hashValueFactory.instance(); HV hashvalue2 = hashValueFactory.instance(); - StepVerifier.create(hashOperations.putIfAbsent(key, hashkey, hashvalue)).expectNext(true).verifyComplete(); - StepVerifier.create(hashOperations.putIfAbsent(key, hashkey, hashvalue2)).expectNext(false).expectComplete() - .verify(); + StepVerifier.create(hashOperations.putIfAbsent(key, hashkey, hashvalue)) // + .expectNext(true) // + .verifyComplete(); + + StepVerifier.create(hashOperations.putIfAbsent(key, hashkey, hashvalue2)) // + .expectNext(false) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -284,9 +330,9 @@ public class DefaultReactiveHashOperationsIntegrationTests { putAll(key, hashkey1, hashvalue1, hashkey2, hashvalue2); - StepVerifier.create(hashOperations.values(key)).consumeNextWith(actual -> { - assertThat(actual).hasSize(2).contains(hashvalue1, hashvalue2); - }).verifyComplete(); + StepVerifier.create(hashOperations.values(key)) // + .expectNextCount(2) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -303,9 +349,15 @@ public class DefaultReactiveHashOperationsIntegrationTests { putAll(key, hashkey1, hashvalue1, hashkey2, hashvalue2); - StepVerifier.create(hashOperations.entries(key)).consumeNextWith(actual -> { - assertThat(actual).hasSize(2).containsEntry(hashkey1, hashvalue1).containsEntry(hashkey2, hashvalue2); - }).verifyComplete(); + StepVerifier.create(hashOperations.entries(key).buffer(2)) // + .consumeNextWith(list -> { + + Entry entry1 = Collections.singletonMap(hashkey1, hashvalue1).entrySet().iterator().next(); + Entry entry2 = Collections.singletonMap(hashkey2, hashvalue2).entrySet().iterator().next(); + + assertThat(list).containsExactlyInAnyOrder(entry1, entry2); + }) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -315,10 +367,17 @@ public class DefaultReactiveHashOperationsIntegrationTests { HK hashkey = hashKeyFactory.instance(); HV hashvalue = hashValueFactory.instance(); - StepVerifier.create(hashOperations.put(key, hashkey, hashvalue)).expectNext(true).verifyComplete(); - StepVerifier.create(hashOperations.delete(key)).expectNext(true).verifyComplete(); + StepVerifier.create(hashOperations.put(key, hashkey, hashvalue)) // + .expectNext(true) // + .verifyComplete(); - StepVerifier.create(hashOperations.size(key)).expectNext(0L).verifyComplete(); + StepVerifier.create(hashOperations.delete(key)) // + .expectNext(true) // + .verifyComplete(); + + StepVerifier.create(hashOperations.size(key)) // + .expectNext(0L) // + .verifyComplete(); } private void putAll(K key, HK hashkey1, HV hashvalue1, HK hashkey2, HV hashvalue2) { @@ -327,6 +386,8 @@ public class DefaultReactiveHashOperationsIntegrationTests { map.put(hashkey1, hashvalue1); map.put(hashkey2, hashvalue2); - StepVerifier.create(hashOperations.putAll(key, map)).expectNext(true).verifyComplete(); + StepVerifier.create(hashOperations.putAll(key, map)) // + .expectNext(true) // + .verifyComplete(); } } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveListOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveListOperationsIntegrationTests.java index ab07445ca..357512259 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveListOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveListOperationsIntegrationTests.java @@ -17,7 +17,6 @@ package org.springframework.data.redis.core; import static org.junit.Assume.*; -import reactor.core.publisher.Flux; import reactor.test.StepVerifier; import java.time.Duration; @@ -95,11 +94,17 @@ public class DefaultReactiveListOperationsIntegrationTests { V value1 = valueFactory.instance(); V value2 = valueFactory.instance(); - StepVerifier.create(listOperations.rightPushAll(key, value1, value2)).expectNext(2L).verifyComplete(); + StepVerifier.create(listOperations.rightPushAll(key, value1, value2)) // + .expectNext(2L) // + .verifyComplete(); - StepVerifier.create(listOperations.trim(key, 0, 0)).expectNext(true).verifyComplete(); + StepVerifier.create(listOperations.trim(key, 0, 0)) // + .expectNext(true) // + .verifyComplete(); - StepVerifier.create(listOperations.size(key)).expectNext(1L).verifyComplete(); + StepVerifier.create(listOperations.size(key)) // + .expectNext(1L) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -108,9 +113,17 @@ public class DefaultReactiveListOperationsIntegrationTests { K key = keyFactory.instance(); V value1 = valueFactory.instance(); - StepVerifier.create(listOperations.size(key)).expectNext(0L).verifyComplete(); - StepVerifier.create(listOperations.rightPush(key, value1)).expectNext(1L).verifyComplete(); - StepVerifier.create(listOperations.size(key)).expectNext(1L).verifyComplete(); + StepVerifier.create(listOperations.size(key)) // + .expectNext(0L) // + .verifyComplete(); + + StepVerifier.create(listOperations.rightPush(key, value1)) // + .expectNext(1L) // + .verifyComplete(); + + StepVerifier.create(listOperations.size(key)) // + .expectNext(1L) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -122,11 +135,18 @@ public class DefaultReactiveListOperationsIntegrationTests { V value1 = valueFactory.instance(); V value2 = valueFactory.instance(); - StepVerifier.create(listOperations.leftPush(key, value1)).expectNext(1L).verifyComplete(); - StepVerifier.create(listOperations.leftPush(key, value2)).expectNext(2L).verifyComplete(); + StepVerifier.create(listOperations.leftPush(key, value1)) // + .expectNext(1L) // + .verifyComplete(); - StepVerifier.create(listOperations.range(key, 0, -1).flatMapMany(Flux::fromIterable)).expectNext(value2) - .expectNext(value1).verifyComplete(); + StepVerifier.create(listOperations.leftPush(key, value2)) // + .expectNext(2L) // + .verifyComplete(); + + StepVerifier.create(listOperations.range(key, 0, -1)) // + .expectNext(value2) // + .expectNext(value1) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -138,10 +158,14 @@ public class DefaultReactiveListOperationsIntegrationTests { V value1 = valueFactory.instance(); V value2 = valueFactory.instance(); - StepVerifier.create(listOperations.leftPushAll(key, value1, value2)).expectNext(2L).verifyComplete(); + StepVerifier.create(listOperations.leftPushAll(key, value1, value2)) // + .expectNext(2L) // + .verifyComplete(); - StepVerifier.create(listOperations.range(key, 0, -1).flatMapMany(Flux::fromIterable)).expectNext(value2) - .expectNext(value1).verifyComplete(); + StepVerifier.create(listOperations.range(key, 0, -1)) // + .expectNext(value2) // + .expectNext(value1) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -151,9 +175,17 @@ public class DefaultReactiveListOperationsIntegrationTests { V value1 = valueFactory.instance(); V value2 = valueFactory.instance(); - StepVerifier.create(listOperations.leftPushIfPresent(key, value1)).expectNext(0L).verifyComplete(); - StepVerifier.create(listOperations.leftPush(key, value1)).expectNext(1L).verifyComplete(); - StepVerifier.create(listOperations.leftPushIfPresent(key, value2)).expectNext(2L).verifyComplete(); + StepVerifier.create(listOperations.leftPushIfPresent(key, value1)) // + .expectNext(0L) // + .verifyComplete(); + + StepVerifier.create(listOperations.leftPush(key, value1)) // + .expectNext(1L) // + .verifyComplete(); + + StepVerifier.create(listOperations.leftPushIfPresent(key, value2)) // + .expectNext(2L) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -166,12 +198,19 @@ public class DefaultReactiveListOperationsIntegrationTests { V value2 = valueFactory.instance(); V value3 = valueFactory.instance(); - StepVerifier.create(listOperations.leftPushAll(key, value1, value2)).expectNext(2L).verifyComplete(); + StepVerifier.create(listOperations.leftPushAll(key, value1, value2)) // + .expectNext(2L) // + .verifyComplete(); - StepVerifier.create(listOperations.leftPush(key, value1, value3)).expectNext(3L).verifyComplete(); + StepVerifier.create(listOperations.leftPush(key, value1, value3)) // + .expectNext(3L) // + .verifyComplete(); - StepVerifier.create(listOperations.range(key, 0, -1).flatMapMany(Flux::fromIterable)).expectNext(value2) - .expectNext(value3).expectNext(value1).verifyComplete(); + StepVerifier.create(listOperations.range(key, 0, -1)) // + .expectNext(value2) // + .expectNext(value3) // + .expectNext(value1) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -183,11 +222,17 @@ public class DefaultReactiveListOperationsIntegrationTests { V value1 = valueFactory.instance(); V value2 = valueFactory.instance(); - StepVerifier.create(listOperations.rightPush(key, value1)).expectNext(1L).verifyComplete(); - StepVerifier.create(listOperations.rightPush(key, value2)).expectNext(2L).verifyComplete(); + StepVerifier.create(listOperations.rightPush(key, value1)) // + .expectNext(1L) // + .verifyComplete(); + StepVerifier.create(listOperations.rightPush(key, value2)) // + .expectNext(2L) // + .verifyComplete(); - StepVerifier.create(listOperations.range(key, 0, -1).flatMapMany(Flux::fromIterable)).expectNext(value1) - .expectNext(value2).verifyComplete(); + StepVerifier.create(listOperations.range(key, 0, -1)) // + .expectNext(value1) // + .expectNext(value2) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -201,8 +246,10 @@ public class DefaultReactiveListOperationsIntegrationTests { StepVerifier.create(listOperations.rightPushAll(key, value1, value2)).expectNext(2L).verifyComplete(); - StepVerifier.create(listOperations.range(key, 0, -1).flatMapMany(Flux::fromIterable)).expectNext(value1) - .expectNext(value2).verifyComplete(); + StepVerifier.create(listOperations.range(key, 0, -1)) // + .expectNext(value1) // + .expectNext(value2) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -231,8 +278,11 @@ public class DefaultReactiveListOperationsIntegrationTests { StepVerifier.create(listOperations.rightPush(key, value1, value3)).expectNext(3L).verifyComplete(); - StepVerifier.create(listOperations.range(key, 0, -1).flatMapMany(Flux::fromIterable)).expectNext(value1) - .expectNext(value3).expectNext(value2).verifyComplete(); + StepVerifier.create(listOperations.range(key, 0, -1)) // + .expectNext(value1) // + .expectNext(value3) // + .expectNext(value2) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -248,8 +298,10 @@ public class DefaultReactiveListOperationsIntegrationTests { StepVerifier.create(listOperations.set(key, 1, value1)).expectNext(true).verifyComplete(); - StepVerifier.create(listOperations.range(key, 0, -1).flatMapMany(Flux::fromIterable)).expectNext(value1) - .expectNext(value1).verifyComplete(); + StepVerifier.create(listOperations.range(key, 0, -1)) // + .expectNext(value1) // + .expectNext(value1) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -265,7 +317,8 @@ public class DefaultReactiveListOperationsIntegrationTests { StepVerifier.create(listOperations.remove(key, 1, value1)).expectNext(1L).verifyComplete(); - StepVerifier.create(listOperations.range(key, 0, -1).flatMapMany(Flux::fromIterable)).expectNext(value2) + StepVerifier.create(listOperations.range(key, 0, -1)) // + .expectNext(value2) // .verifyComplete(); } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveSetOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveSetOperationsIntegrationTests.java index c577fe428..7ec3fff66 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveSetOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveSetOperationsIntegrationTests.java @@ -18,11 +18,13 @@ package org.springframework.data.redis.core; import static org.assertj.core.api.Assertions.*; import static org.junit.Assume.*; +import reactor.core.publisher.Flux; import reactor.test.StepVerifier; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; +import java.util.List; import org.junit.AfterClass; import org.junit.Before; @@ -173,9 +175,11 @@ public class DefaultReactiveSetOperationsIntegrationTests { StepVerifier.create(setOperations.add(key, onlyInKey, shared)).expectNext(2L).verifyComplete(); StepVerifier.create(setOperations.add(otherKey, onlyInOtherKey, shared)).expectNext(2L).verifyComplete(); - StepVerifier.create(setOperations.intersect(key, otherKey)).consumeNextWith(actual -> { - assertThat(actual).contains(shared); - }).verifyComplete(); + StepVerifier.create(setOperations.intersect(key, otherKey)) // + .consumeNextWith(actual -> { + assertThat(actual).isEqualTo(shared); + }) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -213,9 +217,11 @@ public class DefaultReactiveSetOperationsIntegrationTests { StepVerifier.create(setOperations.add(key, onlyInKey, shared)).expectNext(2L).verifyComplete(); StepVerifier.create(setOperations.add(otherKey, onlyInOtherKey, shared)).expectNext(2L).verifyComplete(); - StepVerifier.create(setOperations.difference(key, otherKey)).consumeNextWith(actual -> { - assertThat(actual).contains(onlyInKey); - }).verifyComplete(); + StepVerifier.create(setOperations.difference(key, otherKey)) // + .consumeNextWith(actual -> { + assertThat(actual).isEqualTo(onlyInKey); + }) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -253,9 +259,9 @@ public class DefaultReactiveSetOperationsIntegrationTests { StepVerifier.create(setOperations.add(key, onlyInKey, shared)).expectNext(2L).verifyComplete(); StepVerifier.create(setOperations.add(otherKey, onlyInOtherKey, shared)).expectNext(2L).verifyComplete(); - StepVerifier.create(setOperations.union(key, otherKey)).consumeNextWith(actual -> { - assertThat(actual).contains(onlyInKey, shared, onlyInOtherKey); - }).verifyComplete(); + StepVerifier.create(setOperations.union(key, otherKey)) // + .expectNextCount(3) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -289,8 +295,8 @@ public class DefaultReactiveSetOperationsIntegrationTests { V value2 = valueFactory.instance(); StepVerifier.create(setOperations.add(key, value1, value2)).expectNext(2L).verifyComplete(); - StepVerifier.create(setOperations.members(key)).expectNext(new HashSet(Arrays.asList(value1, value2))) - .verifyComplete(); + StepVerifier.create(setOperations.members(key)) // + .consumeNextWith(actual -> assertThat(actual).isIn(value1, value2)).expectNextCount(1).verifyComplete(); } @Test // DATAREDIS-602 @@ -320,9 +326,7 @@ public class DefaultReactiveSetOperationsIntegrationTests { StepVerifier.create(setOperations.add(key, value1, value2)).expectNext(2L).verifyComplete(); - StepVerifier.create(setOperations.randomMembers(key, 3)).consumeNextWith(actual -> { - assertThat(actual).hasSize(3); - }).verifyComplete(); + StepVerifier.create(setOperations.randomMembers(key, 3)).expectNextCount(3).verifyComplete(); } @Test // DATAREDIS-602 @@ -336,9 +340,9 @@ public class DefaultReactiveSetOperationsIntegrationTests { StepVerifier.create(setOperations.add(key, value1, value2)).expectNext(2L).verifyComplete(); - StepVerifier.create(setOperations.distinctRandomMembers(key, 2)).consumeNextWith(actual -> { - assertThat(actual).hasSize(2); - }).verifyComplete(); + StepVerifier.create(setOperations.distinctRandomMembers(key, 2)) // + .expectNextCount(2) // + .verifyComplete(); } @Test // DATAREDIS-602 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 b196f622c..d365a6974 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveZSetOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveZSetOperationsIntegrationTests.java @@ -15,7 +15,6 @@ */ package org.springframework.data.redis.core; -import static org.assertj.core.api.Assertions.*; import static org.junit.Assume.*; import reactor.test.StepVerifier; @@ -186,9 +185,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.add(key, value2, 10)).expectNext(true).verifyComplete(); StepVerifier.create(zSetOperations.range(key, new Range<>(0L, 0L))) // - .consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(value2); - }).verifyComplete(); + .expectNext(value2) // + .verifyComplete(); } @@ -205,9 +203,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.add(key, value2, 10)).expectNext(true).verifyComplete(); StepVerifier.create(zSetOperations.rangeWithScores(key, new Range<>(0L, 0L))) // - .consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(new DefaultTypedTuple<>(value2, 10d)); - }).verifyComplete(); + .expectNext(new DefaultTypedTuple<>(value2, 10d)) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -223,9 +220,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.add(key, value2, 10)).expectNext(true).verifyComplete(); StepVerifier.create(zSetOperations.rangeByScore(key, new Range<>(9d, 11d))) // - .consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(value2); - }).verifyComplete(); + .expectNext(value2) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -241,9 +237,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.add(key, value2, 10)).expectNext(true).verifyComplete(); StepVerifier.create(zSetOperations.rangeByScoreWithScores(key, new Range<>(9d, 11d))) // - .consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(new DefaultTypedTuple<>(value2, 10d)); - }).verifyComplete(); + .expectNext(new DefaultTypedTuple<>(value2, 10d)) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -261,9 +256,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier .create(zSetOperations.rangeByScore(key, new Range<>(0d, 100d), // Limit.limit().offset(1).count(10))) // - .consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(value1); - }).verifyComplete(); + .expectNext(value1) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -281,9 +275,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier .create(zSetOperations.rangeByScoreWithScores(key, new Range<>(0d, 100d), // Limit.limit().offset(1).count(10))) // - .consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(new DefaultTypedTuple<>(value1, 42.1)); - }).verifyComplete(); + .expectNext(new DefaultTypedTuple<>(value1, 42.1)) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -299,9 +292,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.add(key, value2, 10)).expectNext(true).verifyComplete(); StepVerifier.create(zSetOperations.reverseRange(key, new Range<>(0L, 0L))) // - .consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(value1); - }).verifyComplete(); + .expectNext(value1) // + .verifyComplete(); } @@ -318,9 +310,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.add(key, value2, 10)).expectNext(true).verifyComplete(); StepVerifier.create(zSetOperations.reverseRangeWithScores(key, new Range<>(0L, 0L))) // - .consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(new DefaultTypedTuple<>(value1, 42.1)); - }).verifyComplete(); + .expectNext(new DefaultTypedTuple<>(value1, 42.1)) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -336,9 +327,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.add(key, value2, 10)).expectNext(true).verifyComplete(); StepVerifier.create(zSetOperations.reverseRangeByScore(key, new Range<>(9d, 11d))) // - .consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(value2); - }).verifyComplete(); + .expectNext(value2) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -354,9 +344,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.add(key, value2, 10)).expectNext(true).verifyComplete(); StepVerifier.create(zSetOperations.reverseRangeByScoreWithScores(key, new Range<>(9d, 11d))) // - .consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(new DefaultTypedTuple(value2, 10d)); - }).verifyComplete(); + .expectNext(new DefaultTypedTuple(value2, 10d)) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -374,9 +363,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier .create(zSetOperations.reverseRangeByScore(key, new Range<>(0d, 100d), // Limit.limit().offset(1).count(10))) // - .consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(value2); - }).verifyComplete(); + .expectNext(value2) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -394,9 +382,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier .create(zSetOperations.reverseRangeByScoreWithScores(key, new Range<>(0d, 100d), // Limit.limit().offset(1).count(10))) // - .consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(new DefaultTypedTuple<>(value2, 10d)); - }).verifyComplete(); + .expectNext(new DefaultTypedTuple<>(value2, 10d)) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -454,9 +441,7 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.add(key, value2, 10)).expectNext(true).verifyComplete(); StepVerifier.create(zSetOperations.removeRange(key, new Range<>(0L, 0L))).expectNext(1L).verifyComplete(); - StepVerifier.create(zSetOperations.range(key, new Range<>(0L, 5L))).consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(value1); - }).verifyComplete(); + StepVerifier.create(zSetOperations.range(key, new Range<>(0L, 5L))).expectNext(value1).verifyComplete(); } @Test // DATAREDIS-602 @@ -473,9 +458,9 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.removeRangeByScore(key, new Range<>(9d, 11d))).expectNext(1L).expectComplete() .verify(); - StepVerifier.create(zSetOperations.range(key, new Range<>(0L, 5L))).consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(value1); - }).verifyComplete(); + StepVerifier.create(zSetOperations.range(key, new Range<>(0L, 5L))) // + .expectNext(value1) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -496,9 +481,7 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.add(otherKey, shared, 11)).expectNext(true).verifyComplete(); StepVerifier.create(zSetOperations.unionAndStore(key, otherKey, destKey)).expectNext(3L).verifyComplete(); - StepVerifier.create(zSetOperations.range(destKey, new Range<>(0L, 100L))).consumeNextWith(actual -> { - assertThat(actual).hasSize(3); - }).verifyComplete(); + StepVerifier.create(zSetOperations.range(destKey, new Range<>(0L, 100L))).expectNextCount(3).verifyComplete(); } @Test // DATAREDIS-602 @@ -520,9 +503,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.intersectAndStore(key, otherKey, destKey)).expectNext(1L).expectComplete() .verify(); - StepVerifier.create(zSetOperations.range(destKey, new Range<>(0L, 5L))).consumeNextWith(actual -> { - assertThat(actual).hasSize(1); - }).verifyComplete(); + + StepVerifier.create(zSetOperations.range(destKey, new Range<>(0L, 5L))) // + .expectNextCount(1) // + .verifyComplete(); } @@ -538,9 +522,9 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.add(key, a, 10)).expectNext(true).verifyComplete(); StepVerifier.create(zSetOperations.add(key, b, 11)).expectNext(true).verifyComplete(); - StepVerifier.create(zSetOperations.rangeByLex(key, new Range<>("a", "a"))).consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(a); - }).verifyComplete(); + StepVerifier.create(zSetOperations.rangeByLex(key, new Range<>("a", "a"))) // + .expectNext(a) // + .verifyComplete(); } @@ -556,15 +540,13 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.add(key, a, 10)).expectNext(true).verifyComplete(); StepVerifier.create(zSetOperations.add(key, b, 11)).expectNext(true).verifyComplete(); - StepVerifier.create(zSetOperations.rangeByLex(key, new Range<>("a", "z"), Limit.limit().offset(0).count(10))) - .consumeNextWith(actual -> { - assertThat(actual).hasSize(2).contains(a, b); - }).verifyComplete(); + StepVerifier.create(zSetOperations.rangeByLex(key, new Range<>("a", "z"), Limit.limit().offset(0).count(10))) // + .expectNext(a, b) // + .verifyComplete(); - StepVerifier.create(zSetOperations.rangeByLex(key, new Range<>("a", "z"), Limit.limit().offset(1).count(10))) - .consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(b); - }).verifyComplete(); + StepVerifier.create(zSetOperations.rangeByLex(key, new Range<>("a", "z"), Limit.limit().offset(1).count(10))) // + .expectNext(b) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -579,9 +561,9 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.add(key, a, 10)).expectNext(true).verifyComplete(); StepVerifier.create(zSetOperations.add(key, b, 11)).expectNext(true).verifyComplete(); - StepVerifier.create(zSetOperations.reverseRangeByLex(key, new Range<>("a", "a"))).consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(a); - }).verifyComplete(); + StepVerifier.create(zSetOperations.reverseRangeByLex(key, new Range<>("a", "a"))) // + .expectNext(a) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -596,15 +578,13 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.add(key, a, 10)).expectNext(true).verifyComplete(); StepVerifier.create(zSetOperations.add(key, b, 11)).expectNext(true).verifyComplete(); - StepVerifier.create(zSetOperations.reverseRangeByLex(key, new Range<>("a", "z"), Limit.limit().offset(0).count(10))) - .consumeNextWith(actual -> { - assertThat(actual).hasSize(2).contains(b, a); - }).verifyComplete(); + StepVerifier.create(zSetOperations.reverseRangeByLex(key, new Range<>("a", "z"), Limit.limit().offset(0).count(10))) // + .expectNext(b, a) // + .verifyComplete(); - StepVerifier.create(zSetOperations.reverseRangeByLex(key, new Range<>("a", "z"), Limit.limit().offset(1).count(10))) - .consumeNextWith(actual -> { - assertThat(actual).hasSize(1).contains(a); - }).verifyComplete(); + StepVerifier.create(zSetOperations.reverseRangeByLex(key, new Range<>("a", "z"), Limit.limit().offset(1).count(10))) // + .expectNext(a) // + .verifyComplete(); } @Test // DATAREDIS-602 @@ -617,6 +597,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests { StepVerifier.create(zSetOperations.delete(key)).expectNext(true).verifyComplete(); - StepVerifier.create(zSetOperations.size(key)).expectNext(0L).verifyComplete(); + StepVerifier.create(zSetOperations.size(key)) // + .expectNext(0L) // + .verifyComplete(); } }