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

Define incr/decr as aliases of incrby/decrby #1874

Merged
merged 1 commit into from
Jan 16, 2022

Conversation

salty-horse
Copy link
Contributor

@salty-horse salty-horse commented Jan 11, 2022

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)?

(I would welcome some help on how to set up the CI tests on my forked repo, if this is necessary (it's already running in this PR). I couldn't figure it out, and the Contributing guide wasn't helpful)

Description of change

Currently, incr and decr are implemented as identical wrappers of the functions incrby and decrby.

Their documentation is also identical to the other functions, with the difference of linking to the original command's Redis reference. repr is documented as:

Increments the value of key by amount. If no key exists, the value will be initialized as amount
For more information check https://redis.io/commands/incr

This is incorrect and misleading, since Redis's documentation of incr contains no mention of amount.

This change sets up incr and decr as direct aliases of incrby and decrby by assignment. This also means they share docstrings, so that both will lead to incrby and decrby's original references. I think this makes more sense given the function signatures. (I checked the generated Sphinx documentation and it is identical, other than the Redis URLs).

I also removed the comment in incrby that claims it is an alias of incr. I think it's the other way around, and I don't think the comment is adding much. Perhaps it's more useful to document the fact that incr is an alias of incrby for backwards compatibility...?

@codecov-commenter
Copy link

codecov-commenter commented Jan 11, 2022

Codecov Report

Merging #1874 (487d559) into master (41cef47) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1874      +/-   ##
==========================================
+ Coverage   93.60%   93.63%   +0.02%     
==========================================
  Files          76       76              
  Lines       16268    16266       -2     
==========================================
+ Hits        15228    15230       +2     
+ Misses       1040     1036       -4     
Impacted Files Coverage Δ
redis/commands/core.py 89.92% <100.00%> (-0.02%) ⬇️
tests/test_cluster.py 98.41% <0.00%> (+0.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 41cef47...487d559. Read the comment docs.

@chayim chayim added the feature New feature label Jan 12, 2022
@chayim chayim requested a review from dvora-h January 13, 2022 08:06
@dvora-h
Copy link
Collaborator

dvora-h commented Jan 16, 2022

Hi @salty-horse, Thanks for the contribution!
Your suggestion could have been good if decr/incr and decrby/incrby really were the same but in fact decr/incr should always be 1 and has no option to get another amount (It’s a mistaka that it gets), so I suggest just deleting the amount from decr/incr, WDYT?

@salty-horse
Copy link
Contributor Author

I also found the identical API curious. I came across it when changing an incr call to incrby and finding out incr already supports it. But I don't know if it's a mistake - it could have been done intentionally for convenience.

Removing amount from incr/decr is a backwards incompatible change in the API that (from my limited experience) I don't see the benefit for, unless Redis's INCR x is more performant than INCRBY x 1, or there's another reason to allow redis-py to call it directly.

I don't oppose that change, but since it can affect the existing code of many users, maybe it should be discussed in a wider forum.

@dvora-h
Copy link
Collaborator

dvora-h commented Jan 16, 2022

Hi @salty-horse
You are right, it would be better not to do this so as not to break the API. I just checked the docs and they are not affected by this change, so I accept your PR.

@chayim chayim merged commit d846f52 into redis:master Jan 16, 2022
dvora-h pushed a commit to dvora-h/redis-py that referenced this pull request Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants