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

Fix protocol version checking #2737

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion redis/asyncio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def __init__(

self.response_callbacks = CaseInsensitiveDict(self.__class__.RESPONSE_CALLBACKS)

if self.connection_pool.connection_kwargs.get("protocol") == "3":
if self.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it's cheaper to do:
if str(self.connection_pool.connection_kwargs.get("protocol")) == '3'

I think it would be, because this way there's no O(n) on the check. WDYT>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I checked it before, my approach is faster

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. Surprised.

For the PR curious at scale of 1M attempts these are the numbers:

conv : 1.6109482662217037e-07
conv : 4.0583412699501565e-08

The latter is @dvora-h implementation.

self.response_callbacks.update(self.__class__.RESP3_RESPONSE_CALLBACKS)

# If using a single connection client, we need to lock creation-of and use-of
Expand Down
2 changes: 1 addition & 1 deletion redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ def __init__(

self.response_callbacks = CaseInsensitiveDict(self.__class__.RESPONSE_CALLBACKS)

if self.connection_pool.connection_kwargs.get("protocol") == "3":
if self.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
self.response_callbacks.update(self.__class__.RESP3_RESPONSE_CALLBACKS)

def __repr__(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,4 @@ def is_resp2_connection(r):
protocol = r.connection_pool.connection_kwargs.get("protocol")
elif isinstance(r, redis.RedisCluster):
protocol = r.nodes_manager.connection_kwargs.get("protocol")
return protocol == "2" or protocol is None
return protocol in ["2", 2, None]