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

LCS + mset + msetnx #1698

Closed
wants to merge 13 commits into from
Closed

Conversation

aws-talbenjo
Copy link
Contributor

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@aws-talbenjo aws-talbenjo requested a review from a team as a code owner June 27, 2024 15:56
Comment on lines +637 to +640
if (keyValueMap.isEmpty()) {
throw new IllegalArgumentException("empty map");
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can omit this. We have tests where intentionally send to redis an empty map

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I follow. This isn't for testing purpose, if we remove this and get an empty map with mset we'll recieve
NoSuchElementException so isn't his necessary?

Copy link
Collaborator

Choose a reason for hiding this comment

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

if map is empty - submit command with 0 args. But track arg type to avoid issues.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Yury-Fridlyand so basically you want the below code to be enclosed within:

if (!keyValueMap.isEmpty()) {
  ArgType firstValue = keyValueMap.keySet().iterator().next();
  ..
} else {
  // submit empty array
  return commandManager.submitNewCommand(MSet, new String[] {}, this::handleStringResponse);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes

public CompletableFuture<String> mset(@NonNull Map<String, String> keyValueMap) {
String[] args = convertMapToKeyValueStringArray(keyValueMap);
return commandManager.submitNewCommand(MSet, args, this::handleStringResponse);
public <ArgType> CompletableFuture<String> mset(@NonNull Map<ArgType, ArgType> keyValueMap) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better to duplicate code - as I understand, all APIs with String would be removed later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the functions signature differ only in template input Java doesn't allow such overload. I.E this kind of overloading isn't permitted:
someType foo(Map<String,String> ...);
someType foo(Map<GlideString,GlideString> ...);

That's why i had to resort to templating.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, Java's "type erasure" thingi

@@ -263,7 +263,7 @@ public interface StringBaseCommands {
* assert result.equals("OK"));
* }</pre>
*/
CompletableFuture<String> mset(Map<String, String> keyValueMap);
<ArgType> CompletableFuture<String> mset(Map<ArgType , ArgType> keyValueMap);
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand Jun 28, 2024

Choose a reason for hiding this comment

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

If you decide to not duplicate - describe what is ArgType in the doc.
But this will be inconsistend with all other APIs

Copy link
Contributor

@eifrah-aws eifrah-aws Jul 4, 2024

Choose a reason for hiding this comment

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

IIUC, we can't really duplicate these functions. Java's type erasure does not differentiate between:

void foo(Map<GlideString, GlideString> m)

and

void foo(Map<String, String> m)

Both have the same signature of void foo(Map)
The options are:

  • Add custom method name msetBinary or
  • Generalize the method (we could also be using Map<?, ?>

With the second approach, the user gets the "feel" of overloading: he can still call the method with either Map<String, String> or Map<GlideString, GlideString> (anything else will throw)

return commandManager.submitNewCommand(
MSet, (GlideString[]) args, this::handleStringResponse);
} else {
throw new IllegalArgumentException("Expected String or GlideString");
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you decide to not duplicate - add a test for this case

java/integTest/src/test/java/glide/SharedCommandTests.java Outdated Show resolved Hide resolved
@aws-talbenjo aws-talbenjo changed the title LCS + mset LCS + mset + msetnx Jun 30, 2024
@Yury-Fridlyand Yury-Fridlyand added the java issues and fixes related to the java client label Jun 30, 2024
Comment on lines +637 to +640
if (keyValueMap.isEmpty()) {
throw new IllegalArgumentException("empty map");
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

if map is empty - submit command with 0 args. But track arg type to avoid issues.

String[] args = convertMapToKeyValueStringArray(keyValueMap);
return commandManager.submitNewCommand(MSetNX, args, this::handleBooleanResponse);
public <ArgType> CompletableFuture<Boolean> msetnx(@NonNull Map<ArgType, ArgType> keyValueMap) {
if (keyValueMap.isEmpty()) {
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

Ubuntu and others added 5 commits July 1, 2024 09:03
…io#1693)

* Added support for decr decrby del hdel pfadd pfcount pfmerge

---------

Co-authored-by: Ubuntu <ubuntu@ip-172-31-26-174.us-west-2.compute.internal>
- Java transaction: Hash + List commands are now binary compatible + using the leaked ptr approach if required
- Code cleanup
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand left a comment

Choose a reason for hiding this comment

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

Can't approve nor reject.
You're lucky that jacoco is still disabled. It will alert for non-100% code coverage by tests.

@@ -272,15 +274,17 @@ public interface StringBaseCommands {
* @apiNote When in cluster mode, all keys in <code>keyValueMap</code> must map to the same hash
* slot.
* @see <a href="https://redis.io/commands/msetnx/">redis.io</a> for details.
* @param keyValueMap A key-value map consisting of keys and their respective values to set.
* @param keyValueMap A key-value map consisting of keys and their respective values to set. Note
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
* @param keyValueMap A key-value map consisting of keys and their respective values to set. Note
* @param keyValueMap A key-value map consisting of keys and their respective values to set.

@@ -336,8 +332,7 @@ public boolean isBinarySafeOutput() {
* }</pre>
*/
public <ArgType> T customCommand(ArgType[] args) {
ArgsArray commandArgs = buildArgs(args);
protobufTransaction.addCommands(buildCommand(CustomCommand, commandArgs));
protobufTransaction.addCommands(buildCommand(CustomCommand, newArgsBuilder().add(args)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rebase issue? PLease clean up branch before merging

@aws-talbenjo aws-talbenjo marked this pull request as draft July 4, 2024 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
java issues and fixes related to the java client
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

4 participants