diff --git a/pom.xml b/pom.xml
index ddc3b5f38..9cc9bef7d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -122,11 +122,6 @@
true
-
- io.reactivex
- rxjava
- 1.1.1
-
diff --git a/src/main/asciidoc/new-features.adoc b/src/main/asciidoc/new-features.adoc
index 94b019f4c..5e02b6bb7 100644
--- a/src/main/asciidoc/new-features.adoc
+++ b/src/main/asciidoc/new-features.adoc
@@ -3,6 +3,14 @@
New and noteworthy in the latest releases.
+[[new-in-2.0.0]]
+== New in Spring Data Redis 2.0
+
+* Upgrade to Java 8.
+* Removed support for SRP and JRedis drivers.
+* Upgrade to `Lettuce` 5.0.
+* Reactive connection support using https://github.com/mp911de/lettuce[mp911de/lettuce]
+
[[new-in-1.8.0]]
== New in Spring Data Redis 1.8
diff --git a/src/main/java/org/springframework/data/redis/connection/ClusterSlotHashUtil.java b/src/main/java/org/springframework/data/redis/connection/ClusterSlotHashUtil.java
index cd8199daf..0d375d336 100644
--- a/src/main/java/org/springframework/data/redis/connection/ClusterSlotHashUtil.java
+++ b/src/main/java/org/springframework/data/redis/connection/ClusterSlotHashUtil.java
@@ -19,6 +19,7 @@ import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collection;
+import org.springframework.data.redis.util.ByteUtils;
import org.springframework.util.Assert;
/**
@@ -69,7 +70,10 @@ public final class ClusterSlotHashUtil {
return true;
}
- return isSameSlotForAllKeys((byte[][]) keys.stream().map(ByteBuffer::array).toArray(size -> new byte[size][]));
+ return isSameSlotForAllKeys((byte[][]) keys.stream() //
+ .map(ByteBuffer::duplicate) //
+ .map(ByteUtils::getBytes) //
+ .toArray(byte[][]::new));
}
/**
@@ -164,5 +168,4 @@ public final class ClusterSlotHashUtil {
}
return crc & 0xFFFF;
}
-
}
diff --git a/src/main/java/org/springframework/data/redis/connection/ClusterTopology.java b/src/main/java/org/springframework/data/redis/connection/ClusterTopology.java
index f37938642..b9d2a632f 100644
--- a/src/main/java/org/springframework/data/redis/connection/ClusterTopology.java
+++ b/src/main/java/org/springframework/data/redis/connection/ClusterTopology.java
@@ -168,7 +168,7 @@ public class ClusterTopology {
*/
public RedisClusterNode lookup(String nodeId) {
- Assert.notNull(nodeId, "NodeId must not be null");
+ Assert.notNull(nodeId, "NodeId must not be null!");
for (RedisClusterNode node : nodes) {
if (nodeId.equals(node.getId())) {
@@ -189,7 +189,7 @@ public class ClusterTopology {
*/
public RedisClusterNode lookup(RedisClusterNode node) {
- Assert.notNull(node, "RedisClusterNode must not be null");
+ Assert.notNull(node, "RedisClusterNode must not be null!");
if(nodes.contains(node) && StringUtils.hasText(node.getHost()) && StringUtils.hasText(node.getId())){
return node;
diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterGeoCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterGeoCommands.java
index b30b44940..3821d9d5a 100644
--- a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterGeoCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterGeoCommands.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.redis.connection;
/**
diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterHashCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterHashCommands.java
index 2ee203a94..382ff2176 100644
--- a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterHashCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterHashCommands.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.redis.connection;
/**
diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterHyperLogLogCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterHyperLogLogCommands.java
index 290bf742c..d9e876240 100644
--- a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterHyperLogLogCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterHyperLogLogCommands.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.redis.connection;
/**
diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterKeyCommands.java
index b933ab411..8ec8d5be1 100644
--- a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterKeyCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterKeyCommands.java
@@ -13,23 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-/*
- * Copyright 2016. the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
package org.springframework.data.redis.connection;
import java.nio.ByteBuffer;
@@ -59,5 +42,4 @@ public interface ReactiveClusterKeyCommands extends ReactiveKeyCommands {
* @return
*/
Mono randomKey(RedisClusterNode node);
-
}
diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterListCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterListCommands.java
index f5dbd4848..1beb312de 100644
--- a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterListCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterListCommands.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.redis.connection;
/**
diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterNumberCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterNumberCommands.java
index e923a72d1..4004b0a0e 100644
--- a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterNumberCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterNumberCommands.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.redis.connection;
/**
diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterSetCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterSetCommands.java
index 9aa35dd16..1c13c5b33 100644
--- a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterSetCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterSetCommands.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.redis.connection;
/**
diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterStringCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterStringCommands.java
index a36b119c3..3da9aa896 100644
--- a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterStringCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterStringCommands.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.redis.connection;
/**
diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterZSetCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterZSetCommands.java
index f3f4e147f..7ce705a43 100644
--- a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterZSetCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterZSetCommands.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.redis.connection;
/**
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 2e67557dc..c58e95c40 100644
--- a/src/main/java/org/springframework/data/redis/connection/ReactiveGeoCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/ReactiveGeoCommands.java
@@ -17,6 +17,7 @@ package org.springframework.data.redis.connection;
import java.nio.ByteBuffer;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@@ -27,6 +28,7 @@ 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;
@@ -44,40 +46,72 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
/**
+ * Redis Geo commands executed using reactive infrastructure.
+ *
* @author Christoph Strobl
+ * @author Mark Paluch
* @since 2.0
*/
public interface ReactiveGeoCommands {
/**
+ * {@code GEOADD} command parameters.
+ *
* @author Christoph Strobl
*/
class GeoAddCommand extends KeyCommand {
private final List> geoLocations;
- public GeoAddCommand(ByteBuffer key, List> geoLocations) {
+ private GeoAddCommand(ByteBuffer key, List> geoLocations) {
super(key);
+
this.geoLocations = geoLocations;
}
+ /**
+ * Creates a new {@link GeoAddCommand} given {@link GeoLocation}.
+ *
+ * @param geoLocation must not be {@literal null}.
+ * @return a new {@link GeoAddCommand} for {@link GeoLocation}.
+ */
public static GeoAddCommand location(GeoLocation geoLocation) {
+
+ Assert.notNull(geoLocation, "GeoLocation must not be null!");
+
return new GeoAddCommand(null, Collections.singletonList(geoLocation));
}
- public static GeoAddCommand locations(List> geoLocations) {
+ /**
+ * Creates a new {@link GeoAddCommand} given an {@literal index}.
+ *
+ * @param geoLocations must not be {@literal null}.
+ * @return a new {@link GeoAddCommand} for {@literal index}.
+ */
+ public static GeoAddCommand locations(Collection> geoLocations) {
+
+ Assert.notNull(geoLocations, "GeoLocations must not be null!");
+
return new GeoAddCommand(null, new ArrayList<>(geoLocations));
}
+ /**
+ * Applies the Geo set {@literal key}. Constructs a new command instance with all previously configured properties.
+ *
+ * @param key must not be {@literal null}.
+ * @return a new {@link GeoAddCommand} with {@literal key} applied.
+ */
public GeoAddCommand to(ByteBuffer key) {
return new GeoAddCommand(key, geoLocations);
}
+ /**
+ * @return
+ */
public List> getGeoLocations() {
return geoLocations;
}
-
}
/**
@@ -90,9 +124,9 @@ public interface ReactiveGeoCommands {
*/
default Mono geoAdd(ByteBuffer key, Point point, ByteBuffer member) {
- Assert.notNull(key, "key must not be null");
- Assert.notNull(point, "point must not be null");
- Assert.notNull(member, "member must not be null");
+ Assert.notNull(key, "Key must not be null!");
+ Assert.notNull(point, "Point must not be null!");
+ Assert.notNull(member, "Member must not be null!");
return geoAdd(key, new GeoLocation<>(member, point));
}
@@ -106,8 +140,8 @@ public interface ReactiveGeoCommands {
*/
default Mono geoAdd(ByteBuffer key, GeoLocation location) {
- Assert.notNull(key, "key must not be null");
- Assert.notNull(location, "location must not be null");
+ Assert.notNull(key, "Key must not be null!");
+ Assert.notNull(location, "Location must not be null!");
return geoAdd(key, Collections.singletonList(location));
}
@@ -119,10 +153,10 @@ public interface ReactiveGeoCommands {
* @param locations must not be {@literal null}.
* @return
*/
- default Mono geoAdd(ByteBuffer key, List> locations) {
+ default Mono geoAdd(ByteBuffer key, Collection> locations) {
- Assert.notNull(key, "key must not be null");
- Assert.notNull(locations, "locations must not be null");
+ Assert.notNull(key, "Key must not be null!");
+ Assert.notNull(locations, "Locations must not be null!");
return geoAdd(Mono.just(GeoAddCommand.locations(locations).to(key))).next().map(NumericResponse::getOutput);
}
@@ -136,6 +170,8 @@ public interface ReactiveGeoCommands {
Flux> geoAdd(Publisher commands);
/**
+ * {@code GEODIST} command parameters.
+ *
* @author Christoph Strobl
*/
class GeoDistCommand extends KeyCommand {
@@ -145,7 +181,9 @@ public interface ReactiveGeoCommands {
private final Metric metric;
private GeoDistCommand(ByteBuffer key, ByteBuffer from, ByteBuffer to, Metric metric) {
+
super(key);
+
this.from = from;
this.to = to;
this.metric = metric;
@@ -155,42 +193,99 @@ public interface ReactiveGeoCommands {
return new GeoDistCommand(null, null, null, unit);
}
+ /**
+ * Creates a new {@link GeoDistCommand} for {@link DistanceUnit#METERS}.
+ *
+ * @return a new {@link GeoDistCommand} for {@link DistanceUnit#METERS}.
+ */
public static GeoDistCommand meters() {
return units(DistanceUnit.METERS);
}
- public static GeoDistCommand kiometers() {
+ /**
+ * Creates a new {@link GeoDistCommand} for {@link DistanceUnit#KILOMETERS}.
+ *
+ * @return a new {@link GeoDistCommand} for {@link DistanceUnit#KILOMETERS}.
+ */
+ public static GeoDistCommand kilometers() {
return units(DistanceUnit.KILOMETERS);
}
+ /**
+ * Creates a new {@link GeoDistCommand} for {@link DistanceUnit#MILES}.
+ *
+ * @return a new {@link GeoDistCommand} for {@link DistanceUnit#MILES}.
+ */
public static GeoDistCommand miles() {
return units(DistanceUnit.MILES);
}
+ /**
+ * Creates a new {@link GeoDistCommand} for {@link DistanceUnit#FEET}.
+ *
+ * @return a new {@link GeoDistCommand} for {@link DistanceUnit#FEET}.
+ */
public static GeoDistCommand feet() {
return units(DistanceUnit.FEET);
}
+ /**
+ * Applies the {@literal from} member. Constructs a new command instance with all previously configured properties.
+ *
+ * @param from must not be {@literal null}.
+ * @return a new {@link GeoDistCommand} with {@literal from} applied.
+ */
public GeoDistCommand between(ByteBuffer from) {
+
+ Assert.notNull(from, "From member must not be null!");
+
return new GeoDistCommand(getKey(), from, to, metric);
}
+ /**
+ * Applies the {@literal to} member. Constructs a new command instance with all previously configured properties.
+ *
+ * @param to must not be {@literal null}.
+ * @return a new {@link GeoDistCommand} with {@literal to} applied.
+ */
public GeoDistCommand and(ByteBuffer to) {
+
+ Assert.notNull(to, "To member must not be null");
+
return new GeoDistCommand(getKey(), from, to, metric);
}
+ /**
+ * Applies the Geo set {@literal key} member. Constructs a new command instance with all previously configured
+ * properties.
+ *
+ * @param key must not be {@literal null}.
+ * @return a new {@link GeoDistCommand} with {@literal key} applied.
+ */
public GeoDistCommand forKey(ByteBuffer key) {
+
+ Assert.notNull(key, "Key must not be null!");
+
return new GeoDistCommand(key, from, to, metric);
}
+ /**
+ * @return
+ */
public ByteBuffer getFrom() {
return from;
}
+ /**
+ * @return
+ */
public ByteBuffer getTo() {
return to;
}
+ /**
+ * @return
+ */
public Optional getMetric() {
return Optional.ofNullable(metric);
}
@@ -219,11 +314,12 @@ public interface ReactiveGeoCommands {
*/
default Mono geoDist(ByteBuffer key, ByteBuffer from, ByteBuffer to, Metric metric) {
- Assert.notNull(key, "key must not be null");
- Assert.notNull(from, "from must not be null");
- Assert.notNull(to, "to must not be null");
+ Assert.notNull(key, "Key must not be null!");
+ Assert.notNull(from, "From must not be null!");
+ Assert.notNull(to, "To must not be null!");
- return geoDist(Mono.just(GeoDistCommand.units(metric).between(from).and(to).forKey(key))).next()
+ return geoDist(Mono.just(GeoDistCommand.units(metric).between(from).and(to).forKey(key))) //
+ .next() //
.map(CommandResponse::getOutput);
}
@@ -236,6 +332,8 @@ public interface ReactiveGeoCommands {
Flux> geoDist(Publisher commands);
/**
+ * {@code GEOHASH} command parameters.
+ *
* @author Christoph Strobl
*/
class GeoHashCommand extends KeyCommand {
@@ -245,21 +343,52 @@ public interface ReactiveGeoCommands {
private GeoHashCommand(ByteBuffer key, List members) {
super(key);
+
this.members = members;
}
+ /**
+ * Creates a new {@link GeoHashCommand} given a {@literal member}.
+ *
+ * @param member must not be {@literal null}.
+ * @return a new {@link GeoHashCommand} for a {@literal member}.
+ */
public static GeoHashCommand member(ByteBuffer member) {
+
+ Assert.notNull(member, "Member must not be null!");
+
return new GeoHashCommand(null, Collections.singletonList(member));
}
- public static GeoHashCommand members(List members) {
+ /**
+ * Creates a new {@link GeoHashCommand} given a {@link Collection} of values.
+ *
+ * @param members must not be {@literal null}.
+ * @return a new {@link GeoHashCommand} for a {@link Collection} of values.
+ */
+ public static GeoHashCommand members(Collection members) {
+
+ Assert.notNull(members, "Members must not be null!");
+
return new GeoHashCommand(null, new ArrayList<>(members));
}
+ /**
+ * Applies the Geo set {@literal key}. Constructs a new command instance with all previously configured properties.
+ *
+ * @param key must not be {@literal null}.
+ * @return a new {@link GeoHashCommand} with {@literal key} applied.
+ */
public GeoHashCommand of(ByteBuffer key) {
+
+ Assert.notNull(key, "Key must not be null!");
+
return new GeoHashCommand(key, members);
}
+ /**
+ * @return
+ */
public List getMembers() {
return members;
}
@@ -274,9 +403,10 @@ public interface ReactiveGeoCommands {
*/
default Mono geoHash(ByteBuffer key, ByteBuffer member) {
- Assert.notNull(member, "member must not be null");
+ Assert.notNull(member, "Member must not be null!");
- return geoHash(key, Collections.singletonList(member)).map(vals -> vals.isEmpty() ? null : vals.iterator().next());
+ return geoHash(key, Collections.singletonList(member)) //
+ .map(vals -> vals.isEmpty() ? null : vals.iterator().next());
}
/**
@@ -286,12 +416,14 @@ public interface ReactiveGeoCommands {
* @param members must not be {@literal null}.
* @return
*/
- default Mono> geoHash(ByteBuffer key, List members) {
+ default Mono> geoHash(ByteBuffer key, Collection members) {
- Assert.notNull(key, "key must not be null");
- Assert.notNull(members, "members must not be null");
+ Assert.notNull(key, "Key must not be null!");
+ Assert.notNull(members, "Members must not be null!");
- return geoHash(Mono.just(GeoHashCommand.members(members).of(key))).next().map(MultiValueResponse::getOutput);
+ return geoHash(Mono.just(GeoHashCommand.members(members).of(key))) //
+ .next() //
+ .map(MultiValueResponse::getOutput);
}
/**
@@ -303,6 +435,8 @@ public interface ReactiveGeoCommands {
Flux> geoHash(Publisher commands);
/**
+ * {@code GEOPOS} command parameters.
+ *
* @author Christoph Strobl
*/
class GeoPosCommand extends KeyCommand {
@@ -312,21 +446,52 @@ public interface ReactiveGeoCommands {
private GeoPosCommand(ByteBuffer key, List members) {
super(key);
+
this.members = members;
}
+ /**
+ * Creates a new {@link GeoPosCommand} given a {@literal member}.
+ *
+ * @param member must not be {@literal null}.
+ * @return a new {@link GeoPosCommand} for a {@literal member}.
+ */
public static GeoPosCommand member(ByteBuffer member) {
+
+ Assert.notNull(member, "Member must not be null!");
+
return new GeoPosCommand(null, Collections.singletonList(member));
}
- public static GeoPosCommand members(List members) {
+ /**
+ * Creates a new {@link GeoPosCommand} given a {@link Collection} of values.
+ *
+ * @param members must not be {@literal null}.
+ * @return a new {@link GeoPosCommand} for a {@link Collection} of values.
+ */
+ public static GeoPosCommand members(Collection members) {
+
+ Assert.notNull(members, "Members must not be null!");
+
return new GeoPosCommand(null, new ArrayList<>(members));
}
+ /**
+ * Applies the Geo set {@literal key}. Constructs a new command instance with all previously configured properties.
+ *
+ * @param key must not be {@literal null}.
+ * @return a new {@link GeoPosCommand} with {@literal key} applied.
+ */
public GeoPosCommand of(ByteBuffer key) {
+
+ Assert.notNull(key, "Key must not be null!");
+
return new GeoPosCommand(key, members);
}
+ /**
+ * @return
+ */
public List getMembers() {
return members;
}
@@ -341,7 +506,7 @@ public interface ReactiveGeoCommands {
*/
default Mono geoPos(ByteBuffer key, ByteBuffer member) {
- Assert.notNull(member, "member must not be null");
+ Assert.notNull(member, "Member must not be null!");
return geoPos(key, Collections.singletonList(member)).map(vals -> vals.isEmpty() ? null : vals.iterator().next());
}
@@ -353,10 +518,10 @@ public interface ReactiveGeoCommands {
* @param members must not be {@literal null}.
* @return
*/
- default Mono> geoPos(ByteBuffer key, List members) {
+ default Mono> geoPos(ByteBuffer key, Collection members) {
- Assert.notNull(key, "key must not be null");
- Assert.notNull(members, "members must not be null");
+ Assert.notNull(key, "Key must not be null!");
+ Assert.notNull(members, "Members must not be null!");
return geoPos(Mono.just(GeoPosCommand.members(members).of(key))).next().map(MultiValueResponse::getOutput);
}
@@ -370,6 +535,8 @@ public interface ReactiveGeoCommands {
Flux> geoPos(Publisher commands);
/**
+ * {@code GEORADIUS} command parameters.
+ *
* @author Christoph Strobl
*/
class GeoRadiusCommand extends KeyCommand {
@@ -382,7 +549,9 @@ public interface ReactiveGeoCommands {
private GeoRadiusCommand(ByteBuffer key, Point point, Distance distance, GeoRadiusCommandArgs args,
ByteBuffer store, ByteBuffer storeDist) {
+
super(key);
+
this.distance = distance;
this.point = point;
this.args = args == null ? GeoRadiusCommandArgs.newGeoRadiusArgs() : args;
@@ -390,81 +559,190 @@ public interface ReactiveGeoCommands {
this.storeDist = storeDist;
}
+ /**
+ * Creates a new {@link GeoRadiusCommand} given a {@link Distance}.
+ *
+ * @param distance must not be {@literal null}.
+ * @return a new {@link GeoRadiusCommand} for a {@link Distance}.
+ */
public static GeoRadiusCommand within(Distance distance) {
+
+ Assert.notNull(distance, "Distance must not be null!");
+
return new GeoRadiusCommand(null, null, distance, null, null, null);
}
- public static GeoRadiusCommand withinMeters(Double distance) {
+ /**
+ * Creates a new {@link GeoRadiusCommand} given a {@literal distance} in {@link DistanceUnit#METERS}.
+ *
+ * @param distance must not be {@literal null}.
+ * @return a new {@link GeoRadiusCommand} for a {@literal distance} in {@link DistanceUnit#METERS}.
+ */
+ public static GeoRadiusCommand withinMeters(double distance) {
return within(new Distance(distance, DistanceUnit.METERS));
}
- public static GeoRadiusCommand withinKiometers(Double distance) {
+ /**
+ * Creates a new {@link GeoRadiusCommand} given a {@literal distance} in {@link DistanceUnit#KILOMETERS}.
+ *
+ * @param distance must not be {@literal null}.
+ * @return a new {@link GeoRadiusCommand} for a {@literal distance} in {@link DistanceUnit#KILOMETERS}.
+ */
+ public static GeoRadiusCommand withinKilometers(double distance) {
return within(new Distance(distance, DistanceUnit.KILOMETERS));
}
- public static GeoRadiusCommand withinMiles(Double distance) {
+ /**
+ * Creates a new {@link GeoRadiusCommand} given a {@literal distance} in {@link DistanceUnit#MILES}.
+ *
+ * @param distance must not be {@literal null}.
+ * @return a new {@link GeoRadiusCommand} for a {@literal distance} in {@link DistanceUnit#MILES}.
+ */
+ public static GeoRadiusCommand withinMiles(double distance) {
return within(new Distance(distance, DistanceUnit.MILES));
}
- public static GeoRadiusCommand withinFeet(Double distance) {
+ /**
+ * Creates a new {@link GeoRadiusCommand} given a {@literal distance} in {@link DistanceUnit#FEET}.
+ *
+ * @param distance must not be {@literal null}.
+ * @return a new {@link GeoRadiusCommand} for a {@literal distance} in {@link DistanceUnit#FEET}.
+ */
+ public static GeoRadiusCommand withinFeet(double distance) {
return within(new Distance(distance, DistanceUnit.FEET));
}
+ /**
+ * Creates a new {@link GeoRadiusCommand} given a {@link Circle}.
+ *
+ * @param circle must not be {@literal null}.
+ * @return a new {@link GeoRadiusCommand} for a {@link Circle}.
+ */
public static GeoRadiusCommand within(Circle circle) {
+
+ Assert.notNull(circle, "Circle must not be null!");
+
return within(circle.getRadius()).from(circle.getCenter());
}
+ /**
+ * Sets the {@literal center} {@link Point}. Constructs a new command instance with all previously configured
+ * properties.
+ *
+ * @param center must not be {@literal null}.
+ * @return a new {@link GeoRadiusCommand} with {@link Point} applied.
+ */
public GeoRadiusCommand from(Point center) {
+
+ Assert.notNull(center, "Center point must not be null!");
+
return new GeoRadiusCommand(getKey(), center, distance, args, store, storeDist);
}
+ /**
+ * Applies command {@link Flag flags}. Constructs a new command instance with all previously configured properties.
+ *
+ * @param flag must not be {@literal null}.
+ * @return a new {@link GeoRadiusCommand} with {@link Flag} applied.
+ */
public GeoRadiusCommand withFlag(Flag flag) {
+ Assert.notNull(flag, "Flag must not be null!");
+
GeoRadiusCommandArgs args = cloneArgs();
args.flags.add(flag);
return new GeoRadiusCommand(getKey(), point, distance, args, store, storeDist);
}
+ /**
+ * Enables coordinate retrieval. Constructs a new command instance with all previously configured properties.
+ *
+ * @return a new {@link GeoRadiusCommand} with {@link Flag#WITHCOORD} applied.
+ */
public GeoRadiusCommand withCoord() {
return withFlag(Flag.WITHCOORD);
}
+ /**
+ * Enables distance retrieval. Constructs a new command instance with all previously configured properties.
+ *
+ * @return a new {@link GeoRadiusCommand} with {@link Flag#WITHDIST} applied.
+ */
public GeoRadiusCommand withDist() {
return withFlag(Flag.WITHDIST);
}
+ /**
+ * Applies command {@link GeoRadiusCommandArgs}. Constructs a new command instance with all previously configured
+ * properties.
+ *
+ * @param args can be {@literal null}.
+ * @return a new {@link GeoRadiusCommand} with {@link GeoRadiusCommandArgs} applied.
+ */
public GeoRadiusCommand withArgs(GeoRadiusCommandArgs args) {
return new GeoRadiusCommand(getKey(), point, distance, args, store, storeDist);
}
- public GeoRadiusCommand limitTo(Long limit) {
+ /**
+ * Applies the {@literal limit}. Constructs a new command instance with all previously configured properties.
+ *
+ * @param limit
+ * @return a new {@link GeoRadiusCommand} with {@literal limit} applied.
+ */
+ public GeoRadiusCommand limitTo(long limit) {
GeoRadiusCommandArgs args = cloneArgs();
- if (limit != null) {
- args = args.limit(limit);
- }
+ args = args.limit(limit);
return new GeoRadiusCommand(getKey(), point, distance, args, store, storeDist);
}
+ /**
+ * Applies the distance sort {@link Direction}. Constructs a new command instance with all previously configured
+ * properties.
+ *
+ * @param direction must not be {@literal null}.
+ * @return a new {@link GeoRadiusCommand} with sort {@link Direction} applied.
+ */
public GeoRadiusCommand sort(Direction direction) {
+ Assert.notNull(direction, "Direction must not be null!");
+
GeoRadiusCommandArgs args = cloneArgs();
args.sortDirection = direction;
return new GeoRadiusCommand(getKey(), point, distance, args, store, storeDist);
}
+ /**
+ * Applies ascending sort by distance. Constructs a new command instance with all previously configured properties.
+ *
+ * @return a new {@link GeoRadiusCommand} with sort {@link Direction#ASC} applied.
+ */
public GeoRadiusCommand orderByDistanceAsc() {
return sort(Direction.ASC);
}
+ /**
+ * Applies descending sort by distance. Constructs a new command instance with all previously configured properties.
+ *
+ * @return a new {@link GeoRadiusCommand} with sort {@link Direction#DESC} applied.
+ */
public GeoRadiusCommand orderByDistanceDesc() {
return sort(Direction.DESC);
}
+ /**
+ * Applies the Geo set {@literal key}. Constructs a new command instance with all previously configured properties.
+ *
+ * @param key must not be {@literal null}.
+ * @return a new {@link GeoRadiusCommand} with {@literal key} applied.
+ */
public GeoRadiusCommand forKey(ByteBuffer key) {
+
+ Assert.notNull(key, "Key must not be null!");
+
return new GeoRadiusCommand(key, point, distance, args, store, storeDist);
}
@@ -488,34 +766,58 @@ public interface ReactiveGeoCommands {
return new GeoRadiusCommand(getKey(), point, distance, args, store, key);
}
+ /**
+ * @return
+ */
public Optional getDirection() {
return Optional.ofNullable(args.getSortDirection());
}
+ /**
+ * @return
+ */
public Distance getDistance() {
return distance;
}
+ /**
+ * @return
+ */
public Set getFlags() {
return args.getFlags();
}
+ /**
+ * @return
+ */
public Optional getLimit() {
return Optional.ofNullable(args.getLimit());
}
+ /**
+ * @return
+ */
public Point getPoint() {
return point;
}
+ /**
+ * @return
+ */
public Optional getStore() {
return Optional.ofNullable(store);
}
+ /**
+ * @return
+ */
public Optional getStoreDist() {
return Optional.ofNullable(storeDist);
}
+ /**
+ * @return
+ */
public Optional getArgs() {
return Optional.ofNullable(args);
}
@@ -539,7 +841,7 @@ public interface ReactiveGeoCommands {
*/
default Mono>> geoRadius(ByteBuffer key, Circle circle) {
return geoRadius(key, circle, null)
- .map(res -> res.getContent().stream().map(val -> val.getContent()).collect(Collectors.toList()));
+ .map(res -> res.getContent().stream().map(GeoResult::getContent).collect(Collectors.toList()));
}
/**
@@ -553,8 +855,8 @@ public interface ReactiveGeoCommands {
default Mono>> geoRadius(ByteBuffer key, Circle circle,
GeoRadiusCommandArgs geoRadiusArgs) {
- Assert.notNull(key, "key must not be null");
- Assert.notNull(circle, "circle must not be null");
+ 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);
@@ -570,6 +872,8 @@ public interface ReactiveGeoCommands {
Publisher commands);
/**
+ * {@code GEORADIUSBYMEMBER} command parameters.
+ *
* @author Christoph Strobl
*/
class GeoRadiusByMemberCommand extends KeyCommand {
@@ -584,6 +888,7 @@ public interface ReactiveGeoCommands {
ByteBuffer store, ByteBuffer storeDist) {
super(key);
+
this.distance = distance;
this.member = member;
this.args = args == null ? GeoRadiusCommandArgs.newGeoRadiusArgs() : args;
@@ -591,76 +896,173 @@ public interface ReactiveGeoCommands {
this.storeDist = storeDist;
}
+ /**
+ * Creates a new {@link GeoRadiusByMemberCommand} given a {@link Distance}.
+ *
+ * @param distance must not be {@literal null}.
+ * @return a new {@link GeoRadiusByMemberCommand} for a {@link Distance}.
+ */
public static GeoRadiusByMemberCommand within(Distance distance) {
+
+ Assert.notNull(distance, "Distance must not be null!");
+
return new GeoRadiusByMemberCommand(null, null, distance, GeoRadiusCommandArgs.newGeoRadiusArgs(), null, null);
}
- public static GeoRadiusByMemberCommand withinMeters(Double distance) {
+ /**
+ * Creates a new {@link GeoRadiusByMemberCommand} given a {@literal distance} in {@link DistanceUnit#METERS}.
+ *
+ * @param distance must not be {@literal null}.
+ * @return a new {@link GeoRadiusByMemberCommand} for a {@literal distance} in {@link DistanceUnit#METERS}.
+ */
+ public static GeoRadiusByMemberCommand withinMeters(double distance) {
return within(new Distance(distance, DistanceUnit.METERS));
}
- public static GeoRadiusByMemberCommand withinKiometers(Double distance) {
+ /**
+ * Creates a new {@link GeoRadiusByMemberCommand} given a {@literal distance} in {@link DistanceUnit#KILOMETERS}.
+ *
+ * @param distance must not be {@literal null}.
+ * @return a new {@link GeoRadiusByMemberCommand} for a {@literal distance} in {@link DistanceUnit#KILOMETERS}.
+ */
+ public static GeoRadiusByMemberCommand withinKiometers(double distance) {
return within(new Distance(distance, DistanceUnit.KILOMETERS));
}
- public static GeoRadiusByMemberCommand withinMiles(Double distance) {
+ /**
+ * Creates a new {@link GeoRadiusByMemberCommand} given a {@literal distance} in {@link DistanceUnit#MILES}.
+ *
+ * @param distance must not be {@literal null}.
+ * @return a new {@link GeoRadiusByMemberCommand} for a {@literal distance} in {@link DistanceUnit#MILES}.
+ */
+ public static GeoRadiusByMemberCommand withinMiles(double distance) {
return within(new Distance(distance, DistanceUnit.MILES));
}
- public static GeoRadiusByMemberCommand withinFeet(Double distance) {
+ /**
+ * Creates a new {@link GeoRadiusByMemberCommand} given a {@literal distance} in {@link DistanceUnit#FEET}.
+ *
+ * @param distance must not be {@literal null}.
+ * @return a new {@link GeoRadiusByMemberCommand} for a {@literal distance} in {@link DistanceUnit#FEET}.
+ */
+ public static GeoRadiusByMemberCommand withinFeet(double distance) {
return within(new Distance(distance, DistanceUnit.FEET));
}
+ /**
+ * Sets the {@literal member}. Constructs a new command instance with all previously configured properties.
+ *
+ * @param member must not be {@literal null}.
+ * @return a new {@link GeoRadiusByMemberCommand} with {@literal member} applied.
+ */
public GeoRadiusByMemberCommand from(ByteBuffer member) {
+
+ Assert.notNull(member, "Member must not be null!");
+
return new GeoRadiusByMemberCommand(getKey(), member, distance, args, store, storeDist);
}
- public GeoRadiusByMemberCommand withArgs(GeoRadiusCommandArgs args) {
- return new GeoRadiusByMemberCommand(getKey(), member, distance, args, store, storeDist);
- }
-
+ /**
+ * Applies command {@link Flag flags}. Constructs a new command instance with all previously configured properties.
+ *
+ * @param flag must not be {@literal null}.
+ * @return a new {@link GeoRadiusByMemberCommand} with {@literal key} applied.
+ */
public GeoRadiusByMemberCommand withFlag(Flag flag) {
+ Assert.notNull(flag, "Flag must not be null!");
+
GeoRadiusCommandArgs args = cloneArgs();
args.flags.add(flag);
return new GeoRadiusByMemberCommand(getKey(), member, distance, args, store, storeDist);
}
+ /**
+ * Enables coordinate retrieval. Constructs a new command instance with all previously configured properties.
+ *
+ * @return a new {@link GeoRadiusByMemberCommand} with {@link Flag#WITHCOORD} applied.
+ */
public GeoRadiusByMemberCommand withCoord() {
return withFlag(Flag.WITHCOORD);
}
+ /**
+ * Enables distance retrieval. Constructs a new command instance with all previously configured properties.
+ *
+ * @return a new {@link GeoRadiusByMemberCommand} with {@link Flag#WITHDIST} applied.
+ */
public GeoRadiusByMemberCommand withDist() {
return withFlag(Flag.WITHDIST);
}
- public GeoRadiusByMemberCommand limitTo(Long limit) {
-
- GeoRadiusCommandArgs args = cloneArgs();
- if (limit != null) {
- args = args.limit(limit);
- }
+ /**
+ * Applies command {@link GeoRadiusCommandArgs}. Constructs a new command instance with all previously configured
+ * properties.
+ *
+ * @param args can be {@literal null}.
+ * @return a new {@link GeoRadiusByMemberCommand} with {@link GeoRadiusCommandArgs} applied.
+ */
+ public GeoRadiusByMemberCommand withArgs(GeoRadiusCommandArgs args) {
return new GeoRadiusByMemberCommand(getKey(), member, distance, args, store, storeDist);
}
+ /**
+ * Applies the {@literal limit}. Constructs a new command instance with all previously configured properties.
+ *
+ * @param limit
+ * @return a new {@link GeoRadiusByMemberCommand} with {@literal limit} applied.
+ */
+ public GeoRadiusByMemberCommand limitTo(long limit) {
+
+ GeoRadiusCommandArgs args = cloneArgs();
+ args.limit(limit);
+
+ return new GeoRadiusByMemberCommand(getKey(), member, distance, args, store, storeDist);
+ }
+
+ /**
+ * Applies the distance sort {@link Direction}. Constructs a new command instance with all previously configured
+ * properties.
+ *
+ * @param direction must not be {@literal null}.
+ * @return a new {@link GeoRadiusByMemberCommand} with sort {@link Direction} applied.
+ */
public GeoRadiusByMemberCommand sort(Direction direction) {
+ Assert.notNull(direction, "Direction must not be null!");
+
GeoRadiusCommandArgs args = cloneArgs();
args.sortDirection = direction;
return new GeoRadiusByMemberCommand(getKey(), member, distance, args, store, storeDist);
}
+ /**
+ * Applies ascending sort by distance. Constructs a new command instance with all previously configured properties.
+ *
+ * @return a new {@link GeoRadiusByMemberCommand} with sort {@link Direction#ASC} applied.
+ */
public GeoRadiusByMemberCommand orderByDistanceAsc() {
return sort(Direction.ASC);
}
+ /**
+ * Applies descending sort by distance. Constructs a new command instance with all previously configured properties.
+ *
+ * @return a new {@link GeoRadiusByMemberCommand} with sort {@link Direction#DESC} applied.
+ */
public GeoRadiusByMemberCommand orderByDistanceDesc() {
return sort(Direction.DESC);
}
+ /**
+ * Applies the Geo set {@literal key}. Constructs a new command instance with all previously configured properties.
+ *
+ * @param key must not be {@literal null}.
+ * @return a new {@link GeoRadiusByMemberCommand} with {@literal key} applied.
+ */
public GeoRadiusByMemberCommand forKey(ByteBuffer key) {
return new GeoRadiusByMemberCommand(key, member, distance, args, store, storeDist);
}
@@ -685,34 +1087,58 @@ public interface ReactiveGeoCommands {
return new GeoRadiusByMemberCommand(getKey(), member, distance, args, store, key);
}
+ /**
+ * @return
+ */
public Optional getDirection() {
return Optional.ofNullable(args.getSortDirection());
}
+ /**
+ * @return
+ */
public Distance getDistance() {
return distance;
}
+ /**
+ * @return
+ */
public Set getFlags() {
return args.getFlags();
}
+ /**
+ * @return
+ */
public Optional getLimit() {
return Optional.ofNullable(args.getLimit());
}
+ /**
+ * @return
+ */
public ByteBuffer getMember() {
return member;
}
+ /**
+ * @return
+ */
public Optional getStore() {
return Optional.ofNullable(store);
}
+ /**
+ * @return
+ */
public Optional getStoreDist() {
return Optional.ofNullable(storeDist);
}
+ /**
+ * @return
+ */
public Optional getArgs() {
return Optional.ofNullable(args);
}
@@ -725,7 +1151,6 @@ public interface ReactiveGeoCommands {
return args.clone();
}
-
}
/**
@@ -737,7 +1162,7 @@ public interface ReactiveGeoCommands {
*/
default Mono>> geoRadiusByMember(ByteBuffer key, ByteBuffer member, Distance distance) {
return geoRadiusByMember(key, member, distance, null)
- .map(res -> res.getContent().stream().map(val -> val.getContent()).collect(Collectors.toList()));
+ .map(res -> res.getContent().stream().map(GeoResult::getContent).collect(Collectors.toList()));
}
/**
@@ -751,9 +1176,9 @@ public interface ReactiveGeoCommands {
default Mono>> geoRadiusByMember(ByteBuffer key, ByteBuffer member,
Distance distance, GeoRadiusCommandArgs geoRadiusArgs) {
- Assert.notNull(key, "key must not be null");
- Assert.notNull(member, "member must not be null");
- Assert.notNull(distance, "distance must not be null");
+ 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 geoRadiusByMember(
Mono.just(GeoRadiusByMemberCommand.within(distance).from(member).forKey(key).withArgs(geoRadiusArgs))).next()
@@ -763,7 +1188,7 @@ public interface ReactiveGeoCommands {
/**
* Get the {@literal member}s within given {@link Distance} from {@literal member} applying given parameters.
*
- * @param commands
+ * @param commands must not be {@literal null}.
* @return
*/
Flux>>> geoRadiusByMember(
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 47969e569..988e6db6d 100644
--- a/src/main/java/org/springframework/data/redis/connection/ReactiveHashCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/ReactiveHashCommands.java
@@ -17,6 +17,7 @@ package org.springframework.data.redis.connection;
import java.nio.ByteBuffer;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -24,6 +25,7 @@ import java.util.Map;
import org.reactivestreams.Publisher;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.connection.ReactiveRedisConnection.BooleanResponse;
+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;
@@ -34,63 +36,115 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
/**
+ * Redis Hash commands executed using reactive infrastructure.
+ *
* @author Christoph Strobl
+ * @author Mark Paluch
* @since 2.0
*/
public interface ReactiveHashCommands {
/**
+ * {@literal HSET} {@link Command}.
+ *
* @author Christoph Strobl
*/
class HSetCommand extends KeyCommand {
private static final ByteBuffer SINGLE_VALUE_KEY = ByteBuffer.allocate(0);
private final Map fieldValueMap;
- private final Boolean upsert;
+ private final boolean upsert;
- private HSetCommand(ByteBuffer key, Map keyValueMap, Boolean upsert) {
+ private HSetCommand(ByteBuffer key, Map keyValueMap, boolean upsert) {
super(key);
+
this.fieldValueMap = keyValueMap;
this.upsert = upsert;
}
+ /**
+ * Creates a new {@link HSetCommand} given a {@link ByteBuffer key}.
+ *
+ * @param value must not be {@literal null}.
+ * @return a new {@link HSetCommand} for {@link ByteBuffer key}.
+ */
public static HSetCommand value(ByteBuffer value) {
+
+ Assert.notNull(value, "Value must not be null!");
+
return new HSetCommand(null, Collections.singletonMap(SINGLE_VALUE_KEY, value), Boolean.TRUE);
}
+ /**
+ * Creates a new {@link HSetCommand} given a {@link Map} of field values.
+ *
+ * @param fieldValueMap must not be {@literal null}.
+ * @return a new {@link HSetCommand} for a {@link Map} of field values.
+ */
public static HSetCommand fieldValues(Map fieldValueMap) {
+
+ Assert.notNull(fieldValueMap, "Field values map must not be null!");
+
return new HSetCommand(null, fieldValueMap, Boolean.TRUE);
}
+ /**
+ * Applies a field. Constructs a new command instance with all previously configured properties.
+ *
+ * @param field must not be {@literal null}.
+ * @return a new {@link HSetCommand} with {@literal field} applied.
+ */
public HSetCommand ofField(ByteBuffer field) {
if (!fieldValueMap.containsKey(SINGLE_VALUE_KEY)) {
throw new InvalidDataAccessApiUsageException("Value has not been set.");
}
+ Assert.notNull(field, "Field not be null!");
+
return new HSetCommand(getKey(), Collections.singletonMap(field, fieldValueMap.get(SINGLE_VALUE_KEY)), upsert);
}
+ /**
+ * Applies the {@literal key}. Constructs a new command instance with all previously configured properties.
+ *
+ * @param key must not be {@literal null}.
+ * @return a new {@link HSetCommand} with {@literal key} applied.
+ */
public HSetCommand forKey(ByteBuffer key) {
+
+ Assert.notNull(key, "Key not be null!");
+
return new HSetCommand(key, fieldValueMap, upsert);
}
+ /**
+ * Disable upsert. Constructs a new command instance with all previously configured properties.
+ *
+ * @return a new {@link HSetCommand} with upsert disabled.
+ */
public HSetCommand ifValueNotExists() {
return new HSetCommand(getKey(), fieldValueMap, Boolean.FALSE);
}
- public Boolean isUpsert() {
+ /**
+ * @return
+ */
+ public boolean isUpsert() {
return upsert;
}
+ /**
+ * @return
+ */
public Map getFieldValueMap() {
return fieldValueMap;
}
}
/**
- * Set the {@code value} of a hash {@code field}.
+ * Set the {@literal value} of a hash {@literal field}.
*
* @param key must not be {@literal null}.
* @param field must not be {@literal null}.
@@ -99,15 +153,15 @@ public interface ReactiveHashCommands {
*/
default Mono hSet(ByteBuffer key, ByteBuffer field, ByteBuffer value) {
- Assert.notNull(key, "key must not be null");
- Assert.notNull(field, "field must not be null");
- Assert.notNull(value, "value must not be null");
+ Assert.notNull(key, "Key must not be null!");
+ Assert.notNull(field, "Field must not be null!");
+ Assert.notNull(value, "Value must not be null!");
return hSet(Mono.just(HSetCommand.value(value).ofField(field).forKey(key))).next().map(BooleanResponse::getOutput);
}
/**
- * Set the {@code value} of a hash {@code field}.
+ * Set the {@literal value} of a hash {@literal field}.
*
* @param key must not be {@literal null}.
* @param field must not be {@literal null}.
@@ -116,16 +170,16 @@ public interface ReactiveHashCommands {
*/
default Mono hSetNX(ByteBuffer key, ByteBuffer field, ByteBuffer value) {
- Assert.notNull(key, "key must not be null");
- Assert.notNull(field, "field must not be null");
- Assert.notNull(value, "value must not be null");
+ Assert.notNull(key, "Key must not be null!");
+ Assert.notNull(field, "Field must not be null!");
+ Assert.notNull(value, "Value must not be null!");
return hSet(Mono.just(HSetCommand.value(value).ofField(field).forKey(key).ifValueNotExists())).next()
.map(BooleanResponse::getOutput);
}
/**
- * Set multiple hash fields to multiple values using data provided in {@code fieldValueMap}.
+ * Set multiple hash fields to multiple values using data provided in {@literal fieldValueMap}.
*
* @param key must not be {@literal null}.
* @param fieldValueMap must not be {@literal null}.
@@ -133,15 +187,15 @@ public interface ReactiveHashCommands {
*/
default Mono hMSet(ByteBuffer key, Map fieldValueMap) {
- Assert.notNull(key, "key must not be null");
- Assert.notNull(fieldValueMap, "field must not be null");
+ Assert.notNull(key, "Key must not be null!");
+ Assert.notNull(fieldValueMap, "Field must not be null!");
return hSet(Mono.just(HSetCommand.fieldValues(fieldValueMap).forKey(key).ifValueNotExists())).next()
.map(BooleanResponse::getOutput);
}
/**
- * Set the {@code value} of a hash {@code field}.
+ * Set the {@literal value} of a hash {@literal field}.
*
* @param commands must not be {@literal null}.
* @return
@@ -149,6 +203,8 @@ public interface ReactiveHashCommands {
Flux> hSet(Publisher commands);
/**
+ * {@literal HGET} {@link Command}.
+ *
* @author Christoph Strobl
*/
class HGetCommand extends KeyCommand {
@@ -158,28 +214,59 @@ public interface ReactiveHashCommands {
private HGetCommand(ByteBuffer key, List fields) {
super(key);
+
this.fields = fields;
}
+ /**
+ * Creates a new {@link HGetCommand} given a {@link ByteBuffer field name}.
+ *
+ * @param field must not be {@literal null}.
+ * @return a new {@link HGetCommand} for a {@link ByteBuffer field name}.
+ */
public static HGetCommand field(ByteBuffer field) {
+
+ Assert.notNull(field, "Field must not be null!");
+
return new HGetCommand(null, Collections.singletonList(field));
}
- public static HGetCommand fields(List fields) {
+ /**
+ * Creates a new {@link HGetCommand} given a {@link Collection} of field names.
+ *
+ * @param fields must not be {@literal null}.
+ * @return a new {@link HGetCommand} for a {@link Collection} of field names.
+ */
+ public static HGetCommand fields(Collection fields) {
+
+ Assert.notNull(fields, "Fields must not be null!");
+
return new HGetCommand(null, new ArrayList<>(fields));
}
+ /**
+ * Applies the hash {@literal key}. Constructs a new command instance with all previously configured properties.
+ *
+ * @param key must not be {@literal null}.
+ * @return a new {@link HGetCommand} with {@literal key} applied.
+ */
public HGetCommand from(ByteBuffer key) {
+
+ Assert.notNull(key, "Key must not be null!");
+
return new HGetCommand(key, fields);
}
+ /**
+ * @return
+ */
public List getFields() {
return fields;
}
}
/**
- * Get value for given {@code field} from hash at {@code key}.
+ * Get value for given {@literal field} from hash at {@literal key}.
*
* @param key must not be {@literal null}.
* @param field must not be {@literal null}.
@@ -190,22 +277,22 @@ public interface ReactiveHashCommands {
}
/**
- * Get values for given {@code fields} from hash at {@code key}.
+ * Get values for given {@literal fields} from hash at {@literal key}.
*
* @param key must not be {@literal null}.
* @param fields must not be {@literal null}.
* @return
*/
- default Mono> hMGet(ByteBuffer key, List fields) {
+ default Mono> hMGet(ByteBuffer key, Collection fields) {
- Assert.notNull(key, "key must not be null");
- Assert.notNull(fields, "fields must not be null");
+ Assert.notNull(key, "Key must not be null!");
+ Assert.notNull(fields, "Fields must not be null!");
return hMGet(Mono.just(HGetCommand.fields(fields).from(key))).next().map(MultiValueResponse::getOutput);
}
/**
- * Get values for given {@code fields} from hash at {@code key}.
+ * Get values for given {@literal fields} from hash at {@literal key}.
*
* @param commands must not be {@literal null}.
* @return
@@ -213,6 +300,8 @@ public interface ReactiveHashCommands {
Flux> hMGet(Publisher commands);
/**
+ * {@literal HEXISTS} {@link Command}.
+ *
* @author Christoph Strobl
*/
class HExistsCommand extends KeyCommand {
@@ -222,24 +311,46 @@ public interface ReactiveHashCommands {
private HExistsCommand(ByteBuffer key, ByteBuffer field) {
super(key);
+
this.field = field;
}
+ /**
+ * Creates a new {@link HExistsCommand} given a {@link ByteBuffer field name}.
+ *
+ * @param field must not be {@literal null}.
+ * @return a new {@link HExistsCommand} for a {@link ByteBuffer field name}.
+ */
public static HExistsCommand field(ByteBuffer field) {
+
+ Assert.notNull(field, "Field must not be null!");
+
return new HExistsCommand(null, field);
}
+ /**
+ * Applies the hash {@literal key}. Constructs a new command instance with all previously configured properties.
+ *
+ * @param key must not be {@literal null}.
+ * @return a new {@link HExistsCommand} with {@literal key} applied.
+ */
public HExistsCommand in(ByteBuffer key) {
+
+ Assert.notNull(key, "Key must not be null!");
+
return new HExistsCommand(key, field);
}
+ /**
+ * @return
+ */
public ByteBuffer getField() {
return field;
}
}
/**
- * Determine if given hash {@code field} exists.
+ * Determine if given hash {@literal field} exists.
*
* @param key must not be {@literal null}.
* @param field must not be {@literal null}.
@@ -247,14 +358,14 @@ public interface ReactiveHashCommands {
*/
default Mono hExists(ByteBuffer key, ByteBuffer field) {
- Assert.notNull(key, "key must not be null");
- Assert.notNull(field, "field must not be null");
+ Assert.notNull(key, "Key must not be null!");
+ Assert.notNull(field, "Field must not be null!");
return hExists(Mono.just(HExistsCommand.field(field).in(key))).next().map(BooleanResponse::getOutput);
}
/**
- * Determine if given hash {@code field} exists.
+ * Determine if given hash {@literal field} exists.
*
* @param commands
* @return
@@ -269,29 +380,61 @@ public interface ReactiveHashCommands {
private final List fields;
private HDelCommand(ByteBuffer key, List fields) {
+
super(key);
+
this.fields = fields;
}
+ /**
+ * Creates a new {@link HDelCommand} given a {@link ByteBuffer field name}.
+ *
+ * @param field must not be {@literal null}.
+ * @return a new {@link HDelCommand} for a {@link ByteBuffer field name}.
+ */
public static HDelCommand field(ByteBuffer field) {
+
+ Assert.notNull(field, "Field must not be null!");
+
return new HDelCommand(null, Collections.singletonList(field));
}
- public static HDelCommand fields(List fields) {
+ /**
+ * Creates a new {@link HDelCommand} given a {@link Collection} of field names.
+ *
+ * @param fields must not be {@literal null}.
+ * @return a new {@link HDelCommand} for a {@link Collection} of field names.
+ */
+ public static HDelCommand fields(Collection fields) {
+
+ Assert.notNull(fields, "Fields must not be null!");
+
return new HDelCommand(null, new ArrayList<>(fields));
}
+ /**
+ * Applies the hash {@literal key}. Constructs a new command instance with all previously configured properties.
+ *
+ * @param key must not be {@literal null}.
+ * @return a new {@link HDelCommand} with {@literal key} applied.
+ */
public HDelCommand from(ByteBuffer key) {
+
+ Assert.notNull(key, "Key must not be null!");
+
return new HDelCommand(key, fields);
}
+ /**
+ * @return
+ */
public List getFields() {
return fields;
}
}
/**
- * Delete given hash {@code field}.
+ * Delete given hash {@literal field}.
*
* @param key must not be {@literal null}.
* @param field must not be {@literal null}.
@@ -299,28 +442,28 @@ public interface ReactiveHashCommands {
*/
default Mono hDel(ByteBuffer key, ByteBuffer field) {
- Assert.notNull(field, "field must not be null");
+ Assert.notNull(field, "Field must not be null!");
return hDel(key, Collections.singletonList(field)).map(val -> val > 0 ? Boolean.TRUE : Boolean.FALSE);
}
/**
- * Delete given hash {@code fields}.
+ * Delete given hash {@literal fields}.
*
* @param key must not be {@literal null}.
* @param fields must not be {@literal null}.
* @return
*/
- default Mono hDel(ByteBuffer key, List fields) {
+ default Mono hDel(ByteBuffer key, Collection fields) {
- Assert.notNull(key, "key must not be null");
- Assert.notNull(fields, "fields must not be null");
+ Assert.notNull(key, "Key must not be null!");
+ Assert.notNull(fields, "Fields must not be null!");
return hDel(Mono.just(HDelCommand.fields(fields).from(key))).next().map(NumericResponse::getOutput);
}
/**
- * Delete given hash {@code fields}.
+ * Delete given hash {@literal fields}.
*
* @param commands must not be {@literal null}.
* @return
@@ -328,20 +471,20 @@ public interface ReactiveHashCommands {
Flux> hDel(Publisher commands);
/**
- * Get size of hash at {@code key}.
+ * Get size of hash at {@literal key}.
*
* @param key must not be {@literal null}.
* @return
*/
default Mono hLen(ByteBuffer key) {
- Assert.notNull(key, "key must not be null");
+ Assert.notNull(key, "Key must not be null!");
return hLen(Mono.just(new KeyCommand(key))).next().map(NumericResponse::getOutput);
}
/**
- * Get size of hash at {@code key}.
+ * Get size of hash at {@literal key}.
*
* @param commands must not be {@literal null}.
* @return
@@ -349,20 +492,20 @@ public interface ReactiveHashCommands {
Flux> hLen(Publisher commands);
/**
- * Get key set (fields) of hash at {@code key}.
+ * Get key set (fields) of hash at {@literal key}.
*
* @param key must not be {@literal null}.
* @return
*/
default Mono> hKeys(ByteBuffer key) {
- Assert.notNull(key, "key must not be null");
+ Assert.notNull(key, "Key must not be null!");
return hKeys(Mono.just(new KeyCommand(key))).next().map(MultiValueResponse::getOutput);
}
/**
- * Get key set (fields) of hash at {@code key}.
+ * Get key set (fields) of hash at {@literal key}.
*
* @param commands must not be {@literal null}.
* @return
@@ -370,20 +513,20 @@ public interface ReactiveHashCommands {
Flux> hKeys(Publisher commands);
/**
- * Get entry set (values) of hash at {@code key}.
+ * Get entry set (values) of hash at {@literal key}.
*
* @param key must not be {@literal null}.
* @return
*/
default Mono> hVals(ByteBuffer key) {
- Assert.notNull(key, "key must not be null");
+ Assert.notNull(key, "Key must not be null!");
return hVals(Mono.just(new KeyCommand(key))).next().map(MultiValueResponse::getOutput);
}
/**
- * Get entry set (values) of hash at {@code key}.
+ * Get entry set (values) of hash at {@literal key}.
*
* @param commands must not be {@literal null}.
* @return
@@ -391,24 +534,23 @@ public interface ReactiveHashCommands {
Flux> hVals(Publisher commands);
/**
- * Get entire hash stored at {@code key}.
+ * Get entire hash stored at {@literal key}.
*
* @param key must not be {@literal null}.
* @return
*/
default Mono