-
Notifications
You must be signed in to change notification settings - Fork 53
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
LCS + mset + msetnx #1698
Conversation
if (keyValueMap.isEmpty()) { | ||
throw new IllegalArgumentException("empty map"); | ||
} | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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);
}
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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/client/src/main/java/glide/api/commands/StringBaseCommands.java
Outdated
Show resolved
Hide resolved
if (keyValueMap.isEmpty()) { | ||
throw new IllegalArgumentException("empty map"); | ||
} | ||
|
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
java/client/src/main/java/glide/api/commands/StringBaseCommands.java
Outdated
Show resolved
Hide resolved
java/client/src/main/java/glide/api/commands/StringBaseCommands.java
Outdated
Show resolved
Hide resolved
…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
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @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))); |
There was a problem hiding this comment.
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
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.