Skip to content

Commit 753018e

Browse files
dvora-hchayim
andauthored
Reorganizing the parsers code, and add support for RESP3 (#2574)
* Reorganizing the parsers code * fix build package * fix imports * fix flake8 * add resp to Connection class * core commands * python resp3 parser * pipeline * async resp3 parser * some asymc tests * resp3 parser for async cluster * async commands tests * linters * linters * linters * fix ModuleNotFoundError * fix tests * fix assert_resp_response_in * fix command_getkeys in cluster * fail-fast false * version --------- Co-authored-by: Chayim I. Kirshen <[email protected]>
1 parent 66a4d6b commit 753018e

36 files changed

+1987
-1349
lines changed

.github/workflows/integration.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
timeout-minutes: 30
5252
strategy:
5353
max-parallel: 15
54+
fail-fast: false
5455
matrix:
5556
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', 'pypy-3.7', 'pypy-3.8', 'pypy-3.9']
5657
test-type: ['standalone', 'cluster']
@@ -108,6 +109,7 @@ jobs:
108109
name: Install package from commit hash
109110
runs-on: ubuntu-latest
110111
strategy:
112+
fail-fast: false
111113
matrix:
112114
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', 'pypy-3.7', 'pypy-3.8', 'pypy-3.9']
113115
steps:

benchmarks/socket_read_size.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from base import Benchmark
22

3-
from redis.connection import HiredisParser, PythonParser
3+
from redis.connection import PythonParser, _HiredisParser
44

55

66
class SocketReadBenchmark(Benchmark):
77

88
ARGUMENTS = (
9-
{"name": "parser", "values": [PythonParser, HiredisParser]},
9+
{"name": "parser", "values": [PythonParser, _HiredisParser]},
1010
{
1111
"name": "value_size",
1212
"values": [10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000],

redis/asyncio/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
SSLConnection,
88
UnixDomainSocketConnection,
99
)
10-
from redis.asyncio.parser import CommandsParser
1110
from redis.asyncio.sentinel import (
1211
Sentinel,
1312
SentinelConnectionPool,
@@ -38,7 +37,6 @@
3837
"BlockingConnectionPool",
3938
"BusyLoadingError",
4039
"ChildDeadlockedError",
41-
"CommandsParser",
4240
"Connection",
4341
"ConnectionError",
4442
"ConnectionPool",

redis/asyncio/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ def __init__(
253253

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

256+
if self.connection_pool.connection_kwargs.get("protocol") == "3":
257+
self.response_callbacks.update(self.__class__.RESP3_RESPONSE_CALLBACKS)
258+
256259
# If using a single connection client, we need to lock creation-of and use-of
257260
# the client in order to avoid race conditions such as using asyncio.gather
258261
# on a set of redis commands

redis/asyncio/cluster.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,8 @@
1717
)
1818

1919
from redis.asyncio.client import ResponseCallbackT
20-
from redis.asyncio.connection import (
21-
Connection,
22-
DefaultParser,
23-
Encoder,
24-
SSLConnection,
25-
parse_url,
26-
)
20+
from redis.asyncio.connection import Connection, DefaultParser, SSLConnection, parse_url
2721
from redis.asyncio.lock import Lock
28-
from redis.asyncio.parser import CommandsParser
2922
from redis.asyncio.retry import Retry
3023
from redis.backoff import default_backoff
3124
from redis.client import EMPTY_RESPONSE, NEVER_DECODE, AbstractRedis
@@ -60,6 +53,7 @@
6053
TimeoutError,
6154
TryAgainError,
6255
)
56+
from redis.parsers import AsyncCommandsParser, Encoder
6357
from redis.typing import AnyKeyT, EncodableT, KeyT
6458
from redis.utils import dict_merge, safe_str, str_if_bytes
6559

@@ -250,6 +244,7 @@ def __init__(
250244
ssl_certfile: Optional[str] = None,
251245
ssl_check_hostname: bool = False,
252246
ssl_keyfile: Optional[str] = None,
247+
protocol: Optional[int] = 2,
253248
) -> None:
254249
if db:
255250
raise RedisClusterException(
@@ -290,6 +285,7 @@ def __init__(
290285
"socket_keepalive_options": socket_keepalive_options,
291286
"socket_timeout": socket_timeout,
292287
"retry": retry,
288+
"protocol": protocol,
293289
}
294290

295291
if ssl:
@@ -344,7 +340,7 @@ def __init__(
344340
self.cluster_error_retry_attempts = cluster_error_retry_attempts
345341
self.connection_error_retry_attempts = connection_error_retry_attempts
346342
self.reinitialize_counter = 0
347-
self.commands_parser = CommandsParser()
343+
self.commands_parser = AsyncCommandsParser()
348344
self.node_flags = self.__class__.NODE_FLAGS.copy()
349345
self.command_flags = self.__class__.COMMAND_FLAGS.copy()
350346
self.response_callbacks = kwargs["response_callbacks"]

0 commit comments

Comments
 (0)