Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NOSCORES option to ZSCAN & NOVALUES option to HSCAN #2174

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this

    public static class HScanOptionsBuilder {

        /** copy doc here. */
        public HScanOptionsBuilder noValues() {
            return noValues(true);
        }
    }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add same for zscan options

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you can do noValuesOptions (or so) class, which would be inherited by hscan opts and zscan opts, so you can avoid code duplicating

@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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class add nothing new comparing to HScanOptions. You can delete it and use HScanOptions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am leaving it for consistency, and it might change in the future

/** 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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

/** 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* from Redis version 8.0.0 and above.
* from Valkey 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
Loading