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 support for RedisJSON #657
Conversation
added extra newline Replaced json_mget with condition in json_get removed call to std::mem::replace in the macro, it wasn't doing anything and all tests still passs added newlines Add a Discord badge to README hid internal function from docs formatted
added extra newline Replaced json_mget with condition in json_get removed call to std::mem::replace in the macro, it wasn't doing anything and all tests still passs added newlines Add a Discord badge to README hid internal function from docs formatted Ran cargo fmt Add a Discord badge to README
Add a Discord badge to README
Add a Discord badge to README
Json support to local main
merging from redis-rs/redis-rs#main into d3rpp/redis-rs-tokio-drift#main
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.
Here's an initial round of review, this is looking much better.
- Updated README to use correct module import - Normalized spelling of Serialization - implemented `From<serde_json::Error> for RedisError` to make implementation of some commands, cleaner. - updated command names to be more readable (json_strappend -> json_str_append, etc.)
Co-authored-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
removing extra "s" due to me misreading the redis docs Co-authored-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
updated comment TODO: RE-ADD START + STOP Co-authored-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
updated comments for `json_arr_insert` Co-authored-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
Co-authored-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
Co-authored-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
Co-authored-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
lol whoops |
Still todo: add I know there is a trait somewhere where you can take edit: it's |
…ss` to make it cleaner
I will admit it is not the worlds cleanest solution but its cleaner than json_arr_index("key", "path", &json!({"hello": "world"}), None, None)
// or
json_arr_index("key", "path", &json!({"hello": "world"}), 0, 0) |
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.
I don't remember, why did we want to have the JSON commands in separate traits (JsonCommands
, AsyncJsonCommands
) anyway?
redis/src/commands/json.rs
Outdated
|
||
/// Append the JSON `value` to the array at `path` after the last element in it. | ||
fn json_arr_append<K: ToRedisArgs, P: ToRedisArgs, V: Serialize>(key: K, path: P, value: &'a V) { | ||
Ok::<Cmd, RedisError>( |
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 rewrite it like this:
let mut cmd = cmd("JSON.ARRAPPEND");
cmd.arg(key)
.arg(path)
.arg(serde_json::to_string(value)?);
Ok::<_, RedisError>(cmd)
I think you no longer need arg_take()
? (Also note that we don't need to specify the Cmd
type in the Ok
turbofish.)
Also while looking this I noticed all the indentation in this file is tabs instead of spaces, should fix that up (VS Code has a Convert Indentation to Spaces
thing.)
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.
I'll do some investigation into this, I think I tried something like this, but I may be wrong
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.
I tried it for one command and it seemed to work? But maybe I got it wrong...
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.
I tried it for one command and it seemed to work? But maybe I got it wrong...
sorry, I've been busy with a hackathon over the weekend, will look into this asap
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.
No hurry from my side! Hope you had fun at the hackathon.
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 rewrite it like this:
let mut cmd = cmd("JSON.ARRAPPEND"); cmd.arg(key) .arg(path) .arg(serde_json::to_string(value)?); Ok::<_, RedisError>(cmd)I think you no longer need
arg_take()
? (Also note that we don't need to specify theCmd
type in theOk
turbofish.)Also while looking this I noticed all the indentation in this file is tabs instead of spaces, should fix that up (VS Code has a
Convert Indentation to Spaces
thing.)
let mut cmd = cmd("JSON.ARRAPPEND");
cmd.arg(key)
.arg(path)
.arg(serde_json::to_string(value)?);
Ok::<_, RedisError>(cmd)
Does indeed seem to work, ill update the rest of them
I've run the command to use spaces instead of tabs
If we don't it's 2 Separate traits with the same name so If you import both of them the compiler complains unless you alias one of them. |
I meant, why can't we make these available as part of the normal command traits (but subject to the Cargo feature flag)? |
That's what I did in the First PR (#644) which lead to the creation of separate modules, and to import them at the same time, it needs a different name. |
Okay, let's keep the additional trait for now. |
removed `arg_take`
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.
Some spit and polish, but I think this is almost ready to merge!
Moved json macro declaration to json.rs Renamed RedisJson and RedisModule to Json and Module respectfully
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.
Alright, nice work! @jaymell did you want to take another look at this?
It looks good to me, though @d3rpp I'm going to request that if possible you squash this down to one commit and give it a nice commit message to save me a bit of work merging 😁 (and of course resolve conflicts) |
oooooh last time I tried that it was absolutely painful, is there not a squash checkbox next to the merge button? |
Yeah, I just squashed it at merge. @d3rpp thanks for persisting in getting this merged! |
Co-authored-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
Co-authored-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
Co-authored-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
Part 2 of #650
Changes over previous editions:
To take on board some of the feedback in #650 (specifically the result variant), I needed to make a few changes
Custom implementer macro:
This was done because the redisjson functions in implementation now return results that get unwrapped before the query, following the following structure
Result::Err
withErrorKind::Serialize
(only active withjson
feature) and a description given by theserde_json
error messagesThis change will only affect some RedisJson Commands, the core commands are untouched by this
There will likely be debate over the removed call to
::std::mem::replace
; however, this is only because since the items are now wrapped inResult
's, the value is limited to the scope of the initial function, and when I try to use the main macrorustc
complains that the value doesn't live long enough.This also called for the introduction of the
arg_take
function onCmd
, which added a function that takes the value by value and returns the value (instead of&mut Cmd
fromarg
.Tests
It has all the same tests as the previous one except with an extra one to test that the
serde_json
errors are being handled correctly (at the top oftest_json.rs
); this attempts to serialise one of the few cases whereserde_json
fails to serialise a struct. (When a HashMap does NOT have astring-ifiable
key (Strings and Numbers only)I thought I added more but upon review I did not