-
Notifications
You must be signed in to change notification settings - Fork 65
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: JSON.MGET
.
#2514
Java: JSON.MGET
.
#2514
Conversation
Signed-off-by: Yury-Fridlyand <[email protected]>
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.
see comments inline
Dropping these comments, becase GLIDE core changes were done in #2587
Signed-off-by: Yury-Fridlyand <[email protected]>
…son.mget-valkey-447 Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
@NonNull BaseClient client, @NonNull String[] keys, @NonNull String path) { | ||
return Json.<Object[]>executeCommand( | ||
client, concatenateArrays(new String[] {JSON_MGET}, keys, new String[] {path})) | ||
.thenApply(res -> castArray(res, String.class)); |
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.
A bit of confusion here. So 3 things:
- the
thenApply()
call here on line 452 - the
<Object[]>
type hint before invokingexecuteCommand()
on line 450 - the final convertion in
executeCommand()
, which will convert to whatever the method return type is (.thenApply(r -> (T) r)
) on line 2709 (formget()
,T
isString[]
)
Not sure why all 3 are needed here. Isn't 3
alone good enough?
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.
lib.rs
returns an arbitrary Object[]
, it cannot be casted to String[]
, so we have to use castArray
.
So what happens here:
- libglide returns
Object[]
customCommand
returnsObject
(which is actually array, yes)- with
Json.<Object[]>
prefix we instruct that we expectObject[]
- with
.thenApply(r -> (T) r)
we safely cast thisObject
toObject[]
- with
castArray
we convertObject[]
toString[]
So in total there is a chained Object
-> Object[]
-> String[]
conversion distrubuted over multiple places of code 🤷
I'd like to refactor this if you give me an idea.
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.
Also note: we kind of have to go through Object -> Object[] -> String[].
This is because castArray requires the Object[] type. We cannot cast Object[] to String[] directly, but we need to cast all inner elements (thank you Java).
java/client/src/main/java/glide/api/commands/servermodules/Json.java
Outdated
Show resolved
Hide resolved
…n.java Co-authored-by: James Xin <[email protected]> Signed-off-by: Yury-Fridlyand <[email protected]>
java/client/src/main/java/glide/api/commands/servermodules/Json.java
Outdated
Show resolved
Hide resolved
@NonNull BaseClient client, @NonNull String[] keys, @NonNull String path) { | ||
return Json.<Object[]>executeCommand( | ||
client, concatenateArrays(new String[] {JSON_MGET}, keys, new String[] {path})) | ||
.thenApply(res -> castArray(res, String.class)); |
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.
Also note: we kind of have to go through Object -> Object[] -> String[].
This is because castArray requires the Object[] type. We cannot cast Object[] to String[] directly, but we need to cast all inner elements (thank you Java).
…n.java Co-authored-by: Andrew Carbonetto <[email protected]> Signed-off-by: Yury-Fridlyand <[email protected]>
* `JSON.MGET`. Signed-off-by: Yury-Fridlyand <[email protected]> Co-authored-by: James Xin <[email protected]> Co-authored-by: Andrew Carbonetto <[email protected]>
Issue link
#2430
Checklist
Before submitting the PR make sure the following are checked: