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

Enable AsyncIO cluster mode lock #2446

Merged
merged 2 commits into from Nov 9, 2022
Merged

Conversation

KMilhan
Copy link
Contributor

@KMilhan KMilhan commented Nov 6, 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)? -> Couldn't configure my fork's Action -> CI here passed
  • 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?

Description of change

Enable AsyncIO cluster mode lock. AsyncIO Cluster mode has not been providing Lock, due to the fact that the core.py trying to find the connection_pool attribute where it's not provided in the AsyncIO cluster client. This change will try to find get_encoder in the client if connection_pool is unavailable.

Also, this change copies the lock method of AsyncIO client (please let me know if this is not appropriate), providing the same API to the users whether they are using non-cluster or cluster.

An example is not added as there is no currently available cluster-mode-only example for asyncio Redis.

Closes: #2420

@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2022

Codecov Report

Base: 92.05% // Head: 92.03% // Decreases project coverage by -0.02% ⚠️

Coverage data is based on head (81a8d41) compared to base (16270e4).
Patch coverage: 72.72% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2446      +/-   ##
==========================================
- Coverage   92.05%   92.03%   -0.03%     
==========================================
  Files         110      110              
  Lines       28705    28721      +16     
==========================================
+ Hits        26425    26433       +8     
- Misses       2280     2288       +8     
Impacted Files Coverage Δ
tests/test_asyncio/test_lock.py 100.00% <ø> (ø)
redis/commands/core.py 82.06% <50.00%> (-0.11%) ⬇️
redis/asyncio/cluster.py 90.70% <80.00%> (+0.41%) ⬆️
redis/asyncio/lock.py 99.13% <88.88%> (+0.04%) ⬆️
tests/test_cluster.py 96.85% <0.00%> (-0.24%) ⬇️
tests/test_asyncio/test_pubsub.py 99.37% <0.00%> (-0.16%) ⬇️
tests/test_asyncio/test_cluster.py 97.29% <0.00%> (-0.14%) ⬇️

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 at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@KMilhan
Copy link
Contributor Author

KMilhan commented Nov 6, 2022

Maybe we can simplify my change by using [registered_client|redis].get_encoder() only in Async[Cluster]?
Below is from redis/asyncio/client.py

    def get_encoder(self):
        """Get the connection pool's encoder"""
        return self.connection_pool.get_encoder()

and redis/commands/core.py

    def get_encoder(self):
        """Get the encoder to encode string scripts into bytes."""
        try:
            return self.registered_client.get_encoder()
        except AttributeError:
            # DEPRECATED
            # In version <=4.1.2, this was the code we used to get the encoder.
            # However, after 4.1.2 we added support for scripting in clustered
            # redis. ClusteredRedis doesn't have a `.connection_pool` attribute
            # so we changed the Script class to use
            # `self.registered_client.get_encoder` (see above).
            # However, that is technically a breaking change, as consumers who
            # use Scripts directly might inject a `registered_client` that
            # doesn't have a `.get_encoder` field. This try/except prevents us
            # from breaking backward-compatibility. Ideally, it would be
            # removed in the next major release.
            return self.registered_client.connection_pool.get_encoder()

@KMilhan

This comment was marked as outdated.

@chayim chayim added the feature New feature label Nov 7, 2022
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.

LGTM!

@dvora-h dvora-h merged commit 772079f into redis:master Nov 9, 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.

AsyncIO Cluster Mode Lock doesn't work
5 participants