-
Notifications
You must be signed in to change notification settings - Fork 59
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
Java: Add GET & SET commands #919
Java: Add GET & SET commands #919
Conversation
0a10654
to
65c893a
Compare
@@ -31,6 +31,6 @@ public static CompletableFuture<RedisClient> CreateClient(RedisClientConfigurati | |||
|
|||
@Override | |||
public CompletableFuture<Object> customCommand(String[] args) { | |||
return commandManager.submitNewCommand(CustomCommand, args, this::handleObjectResponse); | |||
return commandManager.submitNewCommand(CustomCommand, args, this::handleObjectOrNullResponse); |
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.
Renamed function handleObjectOrNullResponse()
to be consistent with how sometimes we allow for null and sometimes not.
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
e17fec0
to
b445dc6
Compare
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
* If <code>conditionalSet</code> is not set the value will be set regardless of prior value | ||
* existence. If value isn't set because of the condition, command will return <code>null</code>. | ||
*/ | ||
private final ConditionalSet conditionalSet; |
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.
this should be an optional, in order to properly represent that this value can be not set.
It's better to make types explicit than rely on enum being null, which is a (weird) language specific ability.
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.
Objects in the @Builder
pattern are all optional unless defaulted (@Builder.Default
). If not set, the value will be null
. I dislike using null
s, but as part of a Builder, we can contain the pattern and trust Lombok.
Unfortunately, Lombok doesn't play well with Optional
s (actually, the Lombok developers actively dislike the Optional pattern). We would have to create our own Builders to work with Optional
s, or we can stick with what Lombok provides and use nulls if the value isn't set prior.
private final boolean returnOldValue; | ||
|
||
/** If not set, no expiry time will be set for the value. */ | ||
private final Expiry expiry; |
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
* The amount of time to live before the key expires. Ignored when {@link | ||
* ExpiryType#KEEP_EXISTING} type is set. | ||
*/ | ||
private Long count; |
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.
wouldn't a Duration type be more representative of the data?
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.
Generally, yes. This object is not being used to calculate duration, but to map to string for a Set command.
But this just a map to the Set command (which takes a number/Integer). Documentation says "Integer", but Bar commented that Long is more appropriate.
see: https://redis.io/commands/set/
* @param value The value to store with the given <code>key</code>. | ||
* @return Response from Redis containing <code>"OK"</code>. | ||
*/ | ||
CompletableFuture<String> set(String key, String value); |
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.
shouldn't the arguments be marked with @NonNull
?
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.
The annotation is an implementation detail. It doesn't do anything in the interface.
I can add it for "documentation" purposes?
@ParameterizedTest | ||
@MethodSource("getClients") | ||
public void set_requires_a_value(BaseClient client) { | ||
assertThrows(NullPointerException.class, () -> client.set("SET", null)); |
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.
minor - the null exception tests can be in UTs, not ITs.
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.
San can move these to the next PR?
Signed-off-by: Andrew Carbonetto <[email protected]>
Issue #, if available:
Description of changes:
This PR is dependent on: #917
This PR adds get/set/ping/info calls to the standalone, and cluster-mode:
Examples:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.