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

Add JSON.MSET #944

Merged
merged 11 commits into from Apr 24, 2023
Merged

Add JSON.MSET #944

merged 11 commits into from Apr 24, 2023

Conversation

gkorland
Copy link
Contributor

No description provided.

@gkorland gkorland requested a review from oshadmi March 21, 2023 15:59
src/commands.rs Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 21, 2023

Codecov Report

Patch coverage: 93.54% and project coverage change: +0.07 🎉

Comparison is base (7361ad4) 81.45% compared to head (a8fc4e4) 81.53%.

❗ Current head a8fc4e4 differs from pull request most recent head 879c295. Consider uploading reports for the commit 879c295 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #944      +/-   ##
==========================================
+ Coverage   81.45%   81.53%   +0.07%     
==========================================
  Files          15       15              
  Lines        3894     3954      +60     
==========================================
+ Hits         3172     3224      +52     
- Misses        722      730       +8     
Impacted Files Coverage Δ
src/lib.rs 86.53% <ø> (ø)
src/commands.rs 95.68% <93.54%> (+<0.01%) ⬆️

... and 2 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

src/commands.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@MeirShpilraien MeirShpilraien left a comment

Choose a reason for hiding this comment

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

Some small comments.

src/commands.rs Outdated Show resolved Hide resolved
src/commands.rs Outdated Show resolved Hide resolved
src/commands.rs Outdated Show resolved Hide resolved
REDIS_OK
}

fn apply_updates<M: Manager>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to make sure, you just extracted the code above into a function right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

one change, the for ui in update_info now doesn't stop on the first error

Copy link
Collaborator

Choose a reason for hiding this comment

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

@gkorland

the for ui in update_info now doesn't stop on the first error

Consider testing that a specific change, which cannot be done, does not prevent apply_changes for previously done changes, e.g., once first change is done, second cannot be done, but third should be done as well.

json.set a $ '{"x": {"y":[10,20], "z":[30,40]}}'
json.set b $ '{"x": 60}'

json.mset a $.x '{}' a '$.x.z[1]' '50' b $.x '70'

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe also on the same key

json.mset a $.x '{}' a '$.x.z[1]' '50' a $.u '70'

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since it is also fixed for json_set - now it may notify on a similar scenario with multi-value (using wildcards, etc.) , while it did not notify before - could affect RediSearch results for example, but this would be a progression and is not considered a breaking change.
Agree?

Copy link
Collaborator

Choose a reason for hiding this comment

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

fixes #821

Copy link
Collaborator

Choose a reason for hiding this comment

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

An example for the problem with a single json.set (using RediSearch as a subscriber for keyspace notifications)

127.0.0.1:6379> json.set k1 $ '{"x":{"x":{"y":[4,5,6]}}}'
OK
127.0.0.1:6379> ft.create idx on json schema '$..y[*]' as y numeric
OK
127.0.0.1:6379> ft.search idx '@y:[4 5]'
1) (integer) 1
2) "k1"
3) 1) "$"
   2) "{\"x\":{\"x\":{\"y\":[4,5,6]}}}"

The following json.set was failing in the middle and not notifying on changes, so the index was not being updated causing search to return a stale result:

127.0.0.1:6379> json.set k1 '$..x' '1'
(nil)
127.0.0.1:6379> json.get k1 $
"[{\"x\":1}]"
127.0.0.1:6379> ft.search idx '@y:[4 5]'
1) (integer) 1
2) "k1"
3) 1) "$"
   2) "{\"x\":1}"

With this PR it should be fixed ☝🏼 (search should return an empty result)
And once RediSearch/RediSearch#3507 is merged, it should also work with json.mset, e.g.,

json.mset k1 $ '{"x":{"x":{"y":[4,5,6]}}}' k1 '$..x' '1'

And then ft.search idx '@y:[4 5]' should return an empty result
And with

json.mset k1 $ '{"x":{"x":{"y":[4,5,6]}}}' k1 '$..x' '1' k1 '$.y' '[4, 5, 6]'

The same search should return k1.


I suppose such tests should be added to RediSearch/RediSearch#3507

Copy link
Collaborator

Choose a reason for hiding this comment

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

@gkorland Keyspace notification can also be tested in this PR (without RediSearch) as in

def test_keyspace_set(env):

src/commands.rs Outdated
!update_info.is_empty() && apply_updates::<M>(&mut redis_key, value, update_info)
} else {
// In case it is a root path
redis_key.set_value(Vec::new(), value).unwrap()
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
redis_key.set_value(Vec::new(), value).unwrap()
redis_key.set_value(Vec::new(), value).expect("<Some informative message>")

Copy link
Contributor Author

@gkorland gkorland Apr 20, 2023

Choose a reason for hiding this comment

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

I replaced it with a fold so if one fails an error will be returned

tests/pytest/test.py Outdated Show resolved Hide resolved
tests/pytest/test.py Outdated Show resolved Hide resolved
tests/pytest/test.py Outdated Show resolved Hide resolved
oshadmi
oshadmi previously approved these changes Apr 23, 2023
@@ -30,6 +30,12 @@ def test_keyspace_set(env):
assert_msg(env, pubsub.get_message(timeout=1), 'pmessage', 'json.set')
assert_msg(env, pubsub.get_message(timeout=1), 'pmessage', 'test_key')

env.assertEqual('OK', r.execute_command('JSON.MSET', 'test_key', '$.foo', '"gogo"', 'test_key{test_key}', '$', '{"a":"fufu"}'))
Copy link

Choose a reason for hiding this comment

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

1% of developers fix this issue

E501: line too long (135 > 79 characters)


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

assert_msg(env, pubsub.get_message(timeout=1), 'pmessage', 'json.mset')
assert_msg(env, pubsub.get_message(timeout=1), 'pmessage', 'test_key')
assert_msg(env, pubsub.get_message(timeout=1), 'pmessage', 'json.mset')
assert_msg(env, pubsub.get_message(timeout=1), 'pmessage', 'test_key{test_key}')
Copy link

Choose a reason for hiding this comment

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

1% of developers fix this issue

E501: line too long (88 > 79 characters)


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

@gkorland gkorland merged commit 47e05e4 into master Apr 24, 2023
11 of 12 checks passed
@gkorland gkorland deleted the gkorland-mset branch April 24, 2023 06:14
@gkorland gkorland changed the title add json.mset Add JSON.MSET May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Review the code in fn json_set when updating a doc - can apply_changes be missed?
3 participants