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

update json().arrindex() default values #2611

Merged
merged 6 commits into from
Mar 15, 2023

Conversation

davemcphee
Copy link
Contributor

@davemcphee davemcphee commented Mar 13, 2023

Pull Request check-list

Please make sure to review and check all of these items:

  • Does $ tox pass with this change (including linting)?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?
  • Was the change added to CHANGES file?

NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.

Description of change

Refactor default start / stop values in the json().arrindex() function. Previously, if stop was unset, the stop value would default to -1. If the value being searched was the last element in an array, and stop was set to -1, the server would reply with -1 instead of the element's index.

eg.: given a json object myarr: {"l": ["a", "b", "c", "d"]}:

localhost:36379> JSON.ARRINDEX myarr $.l '"d"'            # no start or stop set
1) (integer) 3
localhost:36379> JSON.ARRINDEX myarr $.l '"d"' 0 10000    # stop set to some huge value
1) (integer) 3
localhost:36379> JSON.ARRINDEX myarr $.l '"d"' 0 -1       # stop set to -1
1) (integer) -1
localhost:36379> JSON.ARRINDEX myarr $.l '"d"' 0          # start set to 0, but stop omitted
1) (integer) 3

By only appending start and stop values to the JSON.ARRINDEX command if they're set, the python client more closely mimics redis' behaviour.

Fixes #2481

@codecov-commenter
Copy link

codecov-commenter commented Mar 13, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.07 ⚠️

Comparison is base (6c708c2) 92.31% compared to head (69ea3da) 92.25%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2611      +/-   ##
==========================================
- Coverage   92.31%   92.25%   -0.07%     
==========================================
  Files         115      115              
  Lines       29744    29760      +16     
==========================================
- Hits        27459    27455       -4     
- Misses       2285     2305      +20     
Impacted Files Coverage Δ
redis/commands/json/commands.py 89.51% <100.00%> (+0.44%) ⬆️
tests/test_asyncio/test_json.py 100.00% <100.00%> (ø)
tests/test_json.py 100.00% <100.00%> (ø)

... and 5 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.

Copy link
Collaborator

@dvora-h dvora-h left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

tests/test_json.py Outdated Show resolved Hide resolved
@davemcphee
Copy link
Contributor Author

Fixed the bool checks - forgot that 0 is falsey. Added a few more unit tests.

@dvora-h
Copy link
Collaborator

dvora-h commented Mar 14, 2023

@davemcphee Great, thank you! Can you add the tests also to the async test (in test_asyncio/test_json.py)?

@dvora-h dvora-h merged commit b546a9a into redis:master Mar 15, 2023
aksinha334 pushed a commit to aksinha334/redis-py that referenced this pull request Mar 15, 2023
* update json().arrindex() default values

* add unit test

* fix falsy checks

* more unit tests

* add asyncio tests

* fix lint line length

---------

Co-authored-by: Alex Schmitz <aschmitz@box.com>
@davemcphee davemcphee deleted the jsonArrindexStartStop branch March 15, 2023 19:40
dvora-h added a commit that referenced this pull request Mar 15, 2023
* Fixed issue #2598 - make Document class subscriptable

* Last time added older file, fixed it

* retrigger checks

* update json().arrindex() default values (#2611)

* update json().arrindex() default values

* add unit test

* fix falsy checks

* more unit tests

* add asyncio tests

* fix lint line length

---------

Co-authored-by: Alex Schmitz <aschmitz@box.com>

* Speeding up the protocol parsing (#2596)

* speeding up the protocol parser

* linting

* changes to ease

* Fixed CredentialsProvider examples (#2587)

Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com>

* ConnectionPool SSL example (#2605)

* [types] update return type of smismember to list[int] (#2617)

* update return type of smismember

* use Literal instead of int

* retrigger checks

* Added test for document subscriptable in tests/test_search.py

* Fixed linter issue

* retrigger checks

---------

Co-authored-by: Alex Schmitz <alex.schmitz@gmail.com>
Co-authored-by: Alex Schmitz <aschmitz@box.com>
Co-authored-by: Chayim <chayim@users.noreply.github.com>
Co-authored-by: Bar Shaul <88437685+barshaul@users.noreply.github.com>
Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com>
Co-authored-by: CrimsonGlory <CrimsonGlory@users.noreply.github.com>
Co-authored-by: Raymond Yin <raymond@tryevergreen.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

arrindex returns -1 when finding the last value in the array (and when start and stop are not specified)
3 participants