Skip to content

Commit

Permalink
Java: Update ClusterValue javadocs (valkey-io#921)
Browse files Browse the repository at this point in the history
* Java: Update ClusterValue javadocs

Signed-off-by: Andrew Carbonetto <[email protected]>

* Java: Update ClusterValue javadocs

Signed-off-by: Andrew Carbonetto <[email protected]>

* Java: Update ClusterValue javadocs

Signed-off-by: Andrew Carbonetto <[email protected]>

---------

Signed-off-by: Andrew Carbonetto <[email protected]>
  • Loading branch information
acarbonetto authored Feb 8, 2024
1 parent fa8403e commit 898fe67
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions java/client/src/main/java/glide/api/models/ClusterValue.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.api.models;

import glide.api.models.configuration.RequestRoutingConfiguration.Route;
import java.util.Map;

/**
* union-like type which can store single-value or multi-value retrieved from Redis. The
* multi-value, if defined, contains the routed value as a Map<String, Object> containing a cluster
* node address to cluster node value.
* Represents a returned value object from a Redis server with cluster-mode enabled. The response
* type may depend on the submitted {@link Route}.
*
* @param <T> The wrapped data type
* @remark ClusterValue stores values in a union-like object. It contains a single-value or
* multi-value response from Redis. If the command's routing is to a single node use {@link
* #getSingleValue()} to return a response of type <code>T</code>. Otherwise, use {@link
* #getMultiValue()} to return a <code>Map</code> of <code>address: nodeResponse</code> where
* <code>address</code> is of type <code>string</code> and <code>nodeResponse</code> is of type
* <code>T</code>.
* @see <a href="https://redis.io/docs/reference/cluster-spec/">Redis cluster specification</a>
* @param <T> The wrapped response type
*/
public class ClusterValue<T> {
private Map<String, T> multiValue = null;
Expand All @@ -19,7 +26,7 @@ private ClusterValue() {}

/**
* Get per-node value.<br>
* Check with {@link #hasMultiData()} prior to accessing the data.
* Asserts if {@link #hasMultiData()} is false.
*/
public Map<String, T> getMultiValue() {
assert hasMultiData() : "No multi value stored";
Expand All @@ -28,7 +35,7 @@ public Map<String, T> getMultiValue() {

/**
* Get the single value.<br>
* Check with {@link #hasSingleData()} ()} prior to accessing the data.
* Asserts if {@link #hasSingleData()} is false.
*/
public T getSingleValue() {
assert hasSingleData() : "No single value stored";
Expand Down Expand Up @@ -61,12 +68,18 @@ public static <T> ClusterValue<T> ofMultiValue(Map<String, T> data) {
return res;
}

/** Check that multi-value is stored in this object. Use it prior to accessing the data. */
/**
* Check that multi-value is stored in this object. Should be called prior to {@link
* #getMultiValue()}.
*/
public boolean hasMultiData() {
return multiValue != null;
}

/** Check that single-value is stored in this object. Use it prior to accessing the data. */
/**
* Check that single-value is stored in this object. Should be called prior to {@link
* #getSingleValue()}.
*/
public boolean hasSingleData() {
return !hasMultiData();
}
Expand Down

0 comments on commit 898fe67

Please sign in to comment.