Skip to content

Commit

Permalink
Add NOSCORES option to ZSCAN & NOVALUES option to HSCAN (valkey-io#2174)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Shoham Elias <shohame@amazon.com>
  • Loading branch information
shohamazon authored and janhavigupta007 committed Sep 11, 2024
1 parent 39f88e7 commit d0cced4
Show file tree
Hide file tree
Showing 19 changed files with 617 additions and 90 deletions.
14 changes: 10 additions & 4 deletions java/client/src/main/java/glide/api/commands/HashBaseCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import glide.api.models.GlideString;
import glide.api.models.commands.scan.HScanOptions;
import glide.api.models.commands.scan.HScanOptions.HScanOptionsBuilder;
import glide.api.models.commands.scan.HScanOptionsBinary;
import glide.api.models.commands.scan.HScanOptionsBinary.HScanOptionsBinaryBuilder;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -695,8 +697,10 @@ public interface HashBaseCommands {
* cursor</code> for the next iteration of results. <code>"0"</code> will be the <code>cursor
* </code> returned on the last iteration of the result. The second element is always an
* <code>Array</code> of the subset of the hash held in <code>key</code>. The array in the
* second element is always a flattened series of <code>String</code> pairs, where the key is
* at even indices and the value is at odd indices.
* second element is a flattened series of <code>String</code> pairs, where the key is at even
* indices and the value is at odd indices. If {@link HScanOptionsBuilder#noValues} is set to
* <code>true
* </code>, the second element will only contain the fields without the values.
* @example
* <pre>{@code
* // Assume key contains a set with 200 member-score pairs
Expand Down Expand Up @@ -731,8 +735,10 @@ public interface HashBaseCommands {
* cursor</code> for the next iteration of results. <code>"0"</code> will be the <code>cursor
* </code> returned on the last iteration of the result. The second element is always an
* <code>Array</code> of the subset of the hash held in <code>key</code>. The array in the
* second element is always a flattened series of <code>String</code> pairs, where the key is
* at even indices and the value is at odd indices.
* second element is a flattened series of <code>String</code> pairs, where the key is at even
* indices and the value is at odd indices. If {@link HScanOptionsBinaryBuilder#noValues} is
* set to <code>true
* </code>, the second element will only contain the fields without the values.
* @example
* <pre>{@code
* // Assume key contains a set with 200 member-score pairs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import glide.api.models.commands.WeightAggregateOptions.WeightedKeys;
import glide.api.models.commands.ZAddOptions;
import glide.api.models.commands.scan.ZScanOptions;
import glide.api.models.commands.scan.ZScanOptions.ZScanOptionsBuilder;
import glide.api.models.commands.scan.ZScanOptionsBinary;
import glide.api.models.commands.scan.ZScanOptionsBinary.ZScanOptionsBinaryBuilder;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -2789,8 +2791,10 @@ CompletableFuture<Map<GlideString, Double>> zinterWithScores(
* </code> returned on the last iteration of the sorted set. The second element is always an
* <code>
* Array</code> of the subset of the sorted set held in <code>key</code>. The array in the
* second element is always a flattened series of <code>String</code> pairs, where the value
* is at even indices and the score is at odd indices.
* second element is a flattened series of <code>String</code> pairs, where the value is at
* even indices and the score is at odd indices. If {@link ZScanOptionsBuilder#noScores} is to
* <code>true
* </code>, the second element will only contain the members without scores.
* @example
* <pre>{@code
* // Assume key contains a set with 200 member-score pairs
Expand Down Expand Up @@ -2826,8 +2830,10 @@ CompletableFuture<Map<GlideString, Double>> zinterWithScores(
* </code> returned on the last iteration of the sorted set. The second element is always an
* <code>
* Array</code> of the subset of the sorted set held in <code>key</code>. The array in the
* second element is always a flattened series of <code>String</code> pairs, where the value
* is at even indices and the score is at odd indices.
* second element is a flattened series of <code>String</code> pairs, where the value is at
* even indices and the score is at odd indices. If {@link ZScanOptionsBinaryBuilder#noScores}
* is to <code>true
* </code>, the second element will only contain the members without scores.
* @example
* <pre>{@code
* // Assume key contains a set with 200 member-score pairs
Expand Down
14 changes: 10 additions & 4 deletions java/client/src/main/java/glide/api/models/BaseTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,10 @@
import glide.api.models.commands.geospatial.GeoUnit;
import glide.api.models.commands.geospatial.GeospatialData;
import glide.api.models.commands.scan.HScanOptions;
import glide.api.models.commands.scan.HScanOptions.HScanOptionsBuilder;
import glide.api.models.commands.scan.SScanOptions;
import glide.api.models.commands.scan.ZScanOptions;
import glide.api.models.commands.scan.ZScanOptions.ZScanOptionsBuilder;
import glide.api.models.commands.stream.StreamAddOptions;
import glide.api.models.commands.stream.StreamAddOptions.StreamAddOptionsBuilder;
import glide.api.models.commands.stream.StreamClaimOptions;
Expand Down Expand Up @@ -7054,8 +7056,10 @@ public <ArgType> T zscan(@NonNull ArgType key, @NonNull ArgType cursor) {
* always the <code>cursor</code> for the next iteration of results. <code>"0"</code> will be
* the <code>cursor</code> returned on the last iteration of the sorted set. The second
* element is always an <code>Array</code> of the subset of the sorted set held in <code>key
* </code>. The array in the second element is always a flattened series of <code>String
* </code> pairs, where the value is at even indices and the score is at odd indices.
* </code>. The array in the second element is a flattened series of <code>String
* </code> pairs, where the value is at even indices and the score is at odd indices. If
* {@link ZScanOptionsBuilder#noScores} is to <code>true</code>, the second element will only
* contain the members without scores.
*/
public <ArgType> T zscan(
@NonNull ArgType key, @NonNull ArgType cursor, @NonNull ZScanOptions zScanOptions) {
Expand Down Expand Up @@ -7101,8 +7105,10 @@ public <ArgType> T hscan(@NonNull ArgType key, @NonNull ArgType cursor) {
* always the <code>cursor</code> for the next iteration of results. <code>"0"</code> will be
* the <code>cursor</code> returned on the last iteration of the result. The second element is
* always an <code>Array</code> of the subset of the hash held in <code>key</code>. The array
* in the second element is always a flattened series of <code>String</code> pairs, where the
* key is at even indices and the value is at odd indices.
* in the second element is a flattened series of <code>String</code> pairs, where the key is
* at even indices and the value is at odd indices. If {@link HScanOptionsBuilder#noValues} is
* set to <code>true</code>, the second element will only contain the fields without the
* values.
*/
public <ArgType> T hscan(
@NonNull ArgType key, @NonNull ArgType cursor, @NonNull HScanOptions hScanOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
package glide.api.models.commands.scan;

import glide.api.commands.HashBaseCommands;
import glide.api.models.GlideString;
import glide.utils.ArgsBuilder;
import java.util.Arrays;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;

/**
Expand All @@ -10,4 +15,43 @@
* @see <a href="https://valkey.io/commands/hscan/">valkey.io</a>
*/
@SuperBuilder
public class HScanOptions extends BaseScanOptions {}
@EqualsAndHashCode(callSuper = false)
public class HScanOptions extends BaseScanOptions {

/** Option string to include in the HSCAN command when values are not included. */
public static final String NO_VALUES_API = "NOVALUES";

/**
* When set to true, the command will not include values in the results. This option is available
* from Valkey version 8.0.0 and above.
*/
@Builder.Default protected boolean noValues = false;

@Override
public String[] toArgs() {
return Arrays.stream(toGlideStringArgs()).map(GlideString::getString).toArray(String[]::new);
}

/**
* Creates the arguments to be used in <code>HSCAN</code> commands.
*
* @return a GlideString array that holds the options and their arguments.
*/
@Override
public GlideString[] toGlideStringArgs() {
ArgsBuilder builder = new ArgsBuilder();

// Add options from the superclass
GlideString[] superArgs = super.toGlideStringArgs();
for (GlideString arg : superArgs) {
builder.add(arg);
}

// Add the noValues option if applicable
if (noValues) {
builder.add(NO_VALUES_API);
}

return builder.toArray();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.api.models.commands.scan;

import static glide.api.models.GlideString.gs;

import glide.api.commands.HashBaseCommands;
import glide.api.models.GlideString;
import glide.utils.ArgsBuilder;
import java.util.Arrays;
import lombok.Builder;
import lombok.experimental.SuperBuilder;

/**
Expand All @@ -11,4 +17,36 @@
* @see <a href="https://valkey.io/commands/hscan/">valkey.io</a>
*/
@SuperBuilder
public class HScanOptionsBinary extends BaseScanOptionsBinary {}
public class HScanOptionsBinary extends BaseScanOptionsBinary {
/** Option string to include in the HSCAN command when values are not included. */
public static final GlideString NO_VALUES_API = gs("NOVALUES");

/**
* When set to true, the command will not include values in the results. This option is available
* from Valkey version 8.0.0 and above.
*/
@Builder.Default protected boolean noValues = false;

/**
* Creates the arguments to be used in <code>ZSCAN</code> commands.
*
* @return a String array that holds the options and their arguments.
*/
@Override
public String[] toArgs() {
ArgsBuilder builder = new ArgsBuilder();

// Add options from the superclass
String[] superArgs = super.toArgs();
for (String arg : superArgs) {
builder.add(arg);
}

// Add the noValues option if applicable
if (noValues) {
builder.add(NO_VALUES_API.toString());
}

return Arrays.stream(builder.toArray()).map(GlideString::getString).toArray(String[]::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
package glide.api.models.commands.scan;

import glide.api.commands.SortedSetBaseCommands;
import glide.api.models.GlideString;
import glide.utils.ArgsBuilder;
import java.util.Arrays;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;

/**
Expand All @@ -10,4 +15,43 @@
* @see <a href="https://valkey.io/commands/zscan/">valkey.io</a>
*/
@SuperBuilder
public class ZScanOptions extends BaseScanOptions {}
@EqualsAndHashCode(callSuper = false)
public class ZScanOptions extends BaseScanOptions {

/** Option string to include in the ZSCAN command when scores are not included. */
public static final String NO_SCORES_API = "NOSCORES";

/**
* When set to true, the command will not include scores in the results. This option is available
* from Valkey version 8.0.0 and above.
*/
@Builder.Default protected boolean noScores = false;

@Override
public String[] toArgs() {
return Arrays.stream(toGlideStringArgs()).map(GlideString::getString).toArray(String[]::new);
}

/**
* Creates the arguments to be used in <code>ZSCAN</code> commands.
*
* @return a GlideString array that holds the options and their arguments.
*/
@Override
public GlideString[] toGlideStringArgs() {
ArgsBuilder builder = new ArgsBuilder();

// Add options from the superclass
GlideString[] superArgs = super.toGlideStringArgs();
for (GlideString arg : superArgs) {
builder.add(arg);
}

// Add the noScores option if applicable
if (noScores) {
builder.add(NO_SCORES_API);
}

return builder.toArray();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.api.models.commands.scan;

import static glide.api.models.GlideString.gs;

import glide.api.commands.SortedSetBaseCommands;
import glide.api.models.GlideString;
import glide.utils.ArgsBuilder;
import java.util.Arrays;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;

/**
Expand All @@ -11,4 +18,37 @@
* @see <a href="https://valkey.io/commands/zscan/">valkey.io</a>
*/
@SuperBuilder
public class ZScanOptionsBinary extends BaseScanOptionsBinary {}
@EqualsAndHashCode(callSuper = false)
public class ZScanOptionsBinary extends BaseScanOptionsBinary {
/** Option string to include in the ZSCAN command when scores are not included. */
public static final GlideString NO_SCORES_API = gs("NOSCORES");

/**
* When set to true, the command will not include scores in the results. This option is available
* from Redis version 8.0.0 and above.
*/
@Builder.Default protected boolean noScores = false;

/**
* Creates the arguments to be used in <code>ZSCAN</code> commands.
*
* @return a String array that holds the options and their arguments.
*/
@Override
public String[] toArgs() {
ArgsBuilder builder = new ArgsBuilder();

// Add options from the superclass
String[] superArgs = super.toArgs();
for (String arg : superArgs) {
builder.add(arg);
}

// Add the noScores option if applicable
if (noScores) {
builder.add(NO_SCORES_API.toString());
}

return Arrays.stream(builder.toArray()).map(GlideString::getString).toArray(String[]::new);
}
}
Loading

0 comments on commit d0cced4

Please sign in to comment.