Skip to content

Commit

Permalink
RESP3 response-callbacks cleanup (#2841)
Browse files Browse the repository at this point in the history
* cluenup

* sentinel callbacks

* move callbacks

* fix async cluster tests

* _parsers and import fix in tests

* linters

* make modules callbacks private

* fix async search

* fix

---------

Co-authored-by: Chayim I. Kirshen <[email protected]>
  • Loading branch information
dvora-h and chayim authored Jul 13, 2023
1 parent f2f8c34 commit fb10367
Show file tree
Hide file tree
Showing 33 changed files with 1,460 additions and 1,131 deletions.
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 (
BaseParser,
Encoder,
_AsyncHiredisParser,
Expand Down
Loading

0 comments on commit fb10367

Please sign in to comment.