Skip to content

Commit fb10367

Browse files
dvora-hchayim
andauthored
RESP3 response-callbacks cleanup (#2841)
* 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 <c@kirshen.com>
1 parent f2f8c34 commit fb10367

33 files changed

+1460
-1131
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: redis/_parsers/helpers.py

+851
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: redis/asyncio/client.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
cast,
2525
)
2626

27+
from redis._parsers.helpers import (
28+
_RedisCallbacks,
29+
_RedisCallbacksRESP2,
30+
_RedisCallbacksRESP3,
31+
bool_ok,
32+
)
2733
from redis.asyncio.connection import (
2834
Connection,
2935
ConnectionPool,
@@ -37,7 +43,6 @@
3743
NEVER_DECODE,
3844
AbstractRedis,
3945
CaseInsensitiveDict,
40-
bool_ok,
4146
)
4247
from redis.commands import (
4348
AsyncCoreCommands,
@@ -257,12 +262,12 @@ def __init__(
257262
self.single_connection_client = single_connection_client
258263
self.connection: Optional[Connection] = None
259264

260-
self.response_callbacks = CaseInsensitiveDict(self.__class__.RESPONSE_CALLBACKS)
265+
self.response_callbacks = CaseInsensitiveDict(_RedisCallbacks)
261266

262267
if self.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
263-
self.response_callbacks.update(self.__class__.RESP3_RESPONSE_CALLBACKS)
268+
self.response_callbacks.update(_RedisCallbacksRESP3)
264269
else:
265-
self.response_callbacks.update(self.__class__.RESP2_RESPONSE_CALLBACKS)
270+
self.response_callbacks.update(_RedisCallbacksRESP2)
266271

267272
# If using a single connection client, we need to lock creation-of and use-of
268273
# the client in order to avoid race conditions such as using asyncio.gather

Diff for: redis/asyncio/cluster.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
Union,
1919
)
2020

21+
from redis._parsers import AsyncCommandsParser, Encoder
22+
from redis._parsers.helpers import (
23+
_RedisCallbacks,
24+
_RedisCallbacksRESP2,
25+
_RedisCallbacksRESP3,
26+
)
2127
from redis.asyncio.client import ResponseCallbackT
2228
from redis.asyncio.connection import Connection, DefaultParser, SSLConnection, parse_url
2329
from redis.asyncio.lock import Lock
@@ -55,7 +61,6 @@
5561
TimeoutError,
5662
TryAgainError,
5763
)
58-
from redis.parsers import AsyncCommandsParser, Encoder
5964
from redis.typing import AnyKeyT, EncodableT, KeyT
6065
from redis.utils import dict_merge, safe_str, str_if_bytes
6166

@@ -327,11 +332,11 @@ def __init__(
327332
self.retry.update_supported_errors(retry_on_error)
328333
kwargs.update({"retry": self.retry})
329334

330-
kwargs["response_callbacks"] = self.__class__.RESPONSE_CALLBACKS.copy()
335+
kwargs["response_callbacks"] = _RedisCallbacks.copy()
331336
if kwargs.get("protocol") in ["3", 3]:
332-
kwargs["response_callbacks"].update(self.__class__.RESP3_RESPONSE_CALLBACKS)
337+
kwargs["response_callbacks"].update(_RedisCallbacksRESP3)
333338
else:
334-
kwargs["response_callbacks"].update(self.__class__.RESP2_RESPONSE_CALLBACKS)
339+
kwargs["response_callbacks"].update(_RedisCallbacksRESP2)
335340
self.connection_kwargs = kwargs
336341

337342
if startup_nodes:

Diff for: redis/asyncio/connection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
from redis.typing import EncodableT
5252
from redis.utils import HIREDIS_AVAILABLE, str_if_bytes
5353

54-
from ..parsers import (
54+
from .._parsers import (
5555
BaseParser,
5656
Encoder,
5757
_AsyncHiredisParser,

0 commit comments

Comments
 (0)