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

RESP3 response-callbacks cleanup #2841

Merged
merged 9 commits into from
Jul 13, 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
851 changes: 851 additions & 0 deletions redis/_parsers/helpers.py

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 9 additions & 4 deletions redis/asyncio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
cast,
)

from redis._parsers.helpers import (
_RedisCallbacks,
_RedisCallbacksRESP2,
_RedisCallbacksRESP3,
bool_ok,
)
from redis.asyncio.connection import (
Connection,
ConnectionPool,
Expand All @@ -37,7 +43,6 @@
NEVER_DECODE,
AbstractRedis,
CaseInsensitiveDict,
bool_ok,
)
from redis.commands import (
AsyncCoreCommands,
Expand Down Expand Up @@ -257,12 +262,12 @@ def __init__(
self.single_connection_client = single_connection_client
self.connection: Optional[Connection] = None

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

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

# If using a single connection client, we need to lock creation-of and use-of
# the client in order to avoid race conditions such as using asyncio.gather
Expand Down
13 changes: 9 additions & 4 deletions redis/asyncio/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
Union,
)

from redis._parsers import AsyncCommandsParser, Encoder
from redis._parsers.helpers import (
_RedisCallbacks,
_RedisCallbacksRESP2,
_RedisCallbacksRESP3,
)
from redis.asyncio.client import ResponseCallbackT
from redis.asyncio.connection import Connection, DefaultParser, SSLConnection, parse_url
from redis.asyncio.lock import Lock
Expand Down Expand Up @@ -55,7 +61,6 @@
TimeoutError,
TryAgainError,
)
from redis.parsers import AsyncCommandsParser, Encoder
from redis.typing import AnyKeyT, EncodableT, KeyT
from redis.utils import dict_merge, safe_str, str_if_bytes

Expand Down Expand Up @@ -327,11 +332,11 @@ def __init__(
self.retry.update_supported_errors(retry_on_error)
kwargs.update({"retry": self.retry})

kwargs["response_callbacks"] = self.__class__.RESPONSE_CALLBACKS.copy()
kwargs["response_callbacks"] = _RedisCallbacks.copy()
if kwargs.get("protocol") in ["3", 3]:
kwargs["response_callbacks"].update(self.__class__.RESP3_RESPONSE_CALLBACKS)
kwargs["response_callbacks"].update(_RedisCallbacksRESP3)
else:
kwargs["response_callbacks"].update(self.__class__.RESP2_RESPONSE_CALLBACKS)
kwargs["response_callbacks"].update(_RedisCallbacksRESP2)
self.connection_kwargs = kwargs

if startup_nodes:
Expand Down
2 changes: 1 addition & 1 deletion redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from redis.typing import EncodableT
from redis.utils import HIREDIS_AVAILABLE, str_if_bytes

from ..parsers import (
from .._parsers import (
dvora-h marked this conversation as resolved.
Show resolved Hide resolved
BaseParser,
Encoder,
_AsyncHiredisParser,
Expand Down
Loading
Loading