Skip to content

Commit 9a7b52f

Browse files
committed
Moved ClusterParser exceptions to BaseParser class
1 parent 9dfaeae commit 9a7b52f

File tree

4 files changed

+9
-33
lines changed

4 files changed

+9
-33
lines changed

docs/clustering.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Nodes <#specifying-target-nodes>`__ \| `Multi-key
1717
Commands <#multi-key-commands>`__ \| `Known PubSub
1818
Limitations <#known-pubsub-limitations>`__
1919

20-
Creating clusters
21-
-----------------
20+
Connecting to cluster
21+
---------------------
2222

2323
Connecting redis-py to a Redis Cluster instance(s) requires at a minimum
2424
a single node for cluster discovery. There are multiple ways in which a

redis/_parsers/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
OutOfMemoryError,
2121
ReadOnlyError,
2222
RedisError,
23-
ResponseError,
23+
ResponseError, AskError, TryAgainError, MovedError, ClusterDownError, ClusterCrossSlotError, MasterDownError,
2424
)
2525
from ..typing import EncodableT
2626
from .encoders import Encoder
@@ -72,6 +72,12 @@ class BaseParser(ABC):
7272
"READONLY": ReadOnlyError,
7373
"NOAUTH": AuthenticationError,
7474
"NOPERM": NoPermissionError,
75+
"ASK": AskError,
76+
"TRYAGAIN": TryAgainError,
77+
"MOVED": MovedError,
78+
"CLUSTERDOWN": ClusterDownError,
79+
"CROSSSLOT": ClusterCrossSlotError,
80+
"MASTERDOWN": MasterDownError,
7581
}
7682

7783
@classmethod

redis/asyncio/cluster.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,6 @@
7979
)
8080

8181

82-
class ClusterParser(DefaultParser):
83-
EXCEPTION_CLASSES = dict_merge(
84-
DefaultParser.EXCEPTION_CLASSES,
85-
{
86-
"ASK": AskError,
87-
"CLUSTERDOWN": ClusterDownError,
88-
"CROSSSLOT": ClusterCrossSlotError,
89-
"MASTERDOWN": MasterDownError,
90-
"MOVED": MovedError,
91-
"TRYAGAIN": TryAgainError,
92-
},
93-
)
94-
95-
9682
class RedisCluster(AbstractRedis, AbstractRedisCluster, AsyncRedisClusterCommands):
9783
"""
9884
Create a new RedisCluster client.
@@ -297,7 +283,6 @@ def __init__(
297283
kwargs: Dict[str, Any] = {
298284
"max_connections": max_connections,
299285
"connection_class": Connection,
300-
"parser_class": ClusterParser,
301286
# Client related kwargs
302287
"credential_provider": credential_provider,
303288
"username": username,

redis/cluster.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,6 @@ def cleanup_kwargs(**kwargs):
193193
return connection_kwargs
194194

195195

196-
class ClusterParser(DefaultParser):
197-
EXCEPTION_CLASSES = dict_merge(
198-
DefaultParser.EXCEPTION_CLASSES,
199-
{
200-
"ASK": AskError,
201-
"TRYAGAIN": TryAgainError,
202-
"MOVED": MovedError,
203-
"CLUSTERDOWN": ClusterDownError,
204-
"CROSSSLOT": ClusterCrossSlotError,
205-
"MASTERDOWN": MasterDownError,
206-
},
207-
)
208-
209-
210196
class AbstractRedisCluster:
211197
RedisClusterRequestTTL = 16
212198

@@ -692,7 +678,6 @@ def on_connect(self, connection):
692678
Initialize the connection, authenticate and select a database and send
693679
READONLY if it is set during object initialization.
694680
"""
695-
connection.set_parser(ClusterParser)
696681
connection.on_connect()
697682

698683
if self.read_from_replicas:

0 commit comments

Comments
 (0)