10
10
Generator ,
11
11
List ,
12
12
Mapping ,
13
+ MutableMapping ,
13
14
Optional ,
14
15
Type ,
15
16
TypeVar ,
25
26
parse_url ,
26
27
)
27
28
from redis .asyncio .parser import CommandsParser
28
- from redis .client import EMPTY_RESPONSE , NEVER_DECODE , AbstractRedis
29
+ from redis .client import EMPTY_RESPONSE , NEVER_DECODE , AbstractRedis , CaseInsensitiveDict
29
30
from redis .cluster import (
30
31
PIPELINE_BLOCKED_COMMANDS ,
31
32
PRIMARY ,
37
38
get_node_name ,
38
39
parse_cluster_slots ,
39
40
)
40
- from redis .commands import READ_COMMANDS , AsyncRedisClusterCommands
41
+ from redis .commands import READ_COMMANDS , AsyncRedisClusterCommands , AsyncRedisModuleCommands
41
42
from redis .crc import REDIS_CLUSTER_HASH_SLOTS , key_slot
42
43
from redis .exceptions import (
43
44
AskError ,
@@ -78,7 +79,7 @@ class ClusterParser(DefaultParser):
78
79
)
79
80
80
81
81
- class RedisCluster (AbstractRedis , AbstractRedisCluster , AsyncRedisClusterCommands ):
82
+ class RedisCluster (AbstractRedis , AbstractRedisCluster , AsyncRedisClusterCommands , AsyncRedisModuleCommands ):
82
83
"""
83
84
Create a new RedisCluster client.
84
85
@@ -152,6 +153,7 @@ class RedisCluster(AbstractRedis, AbstractRedisCluster, AsyncRedisClusterCommand
152
153
- none of the `host`/`port` & `startup_nodes` were provided
153
154
154
155
"""
156
+ response_callbacks : MutableMapping [Union [str , bytes ], ResponseCallbackT ]
155
157
156
158
@classmethod
157
159
def from_url (cls , url : str , ** kwargs : Any ) -> "RedisCluster" :
@@ -298,7 +300,10 @@ def __init__(
298
300
# Call our on_connect function to configure READONLY mode
299
301
kwargs ["redis_connect_func" ] = self .on_connect
300
302
301
- kwargs ["response_callbacks" ] = self .__class__ .RESPONSE_CALLBACKS .copy ()
303
+ kwargs ["cluster_response_callbacks" ] = CaseInsensitiveDict (self .__class__ .RESPONSE_CALLBACKS )
304
+ self .cluster_response_callbacks = CaseInsensitiveDict (
305
+ self .__class__ .CLUSTER_COMMANDS_RESPONSE_CALLBACKS
306
+ )
302
307
self .connection_kwargs = kwargs
303
308
304
309
if startup_nodes :
@@ -324,7 +329,7 @@ def __init__(
324
329
self .commands_parser = CommandsParser ()
325
330
self .node_flags = self .__class__ .NODE_FLAGS .copy ()
326
331
self .command_flags = self .__class__ .COMMAND_FLAGS .copy ()
327
- self .response_callbacks = kwargs ["response_callbacks " ]
332
+ self .cluster_response_callbacks = kwargs ["cluster_response_callbacks " ]
328
333
self .result_callbacks = self .__class__ .RESULT_CALLBACKS .copy ()
329
334
self .result_callbacks [
330
335
"CLUSTER SLOTS"
@@ -479,7 +484,7 @@ def get_connection_kwargs(self) -> Dict[str, Optional[Any]]:
479
484
480
485
def set_response_callback (self , command : str , callback : ResponseCallbackT ) -> None :
481
486
"""Set a custom response callback."""
482
- self .response_callbacks [command ] = callback
487
+ self .cluster_response_callbacks [command ] = callback
483
488
484
489
async def _determine_nodes (
485
490
self , command : str , * args : Any , node_flag : Optional [str ] = None
@@ -809,7 +814,7 @@ def __init__(
809
814
self .max_connections = max_connections
810
815
self .connection_class = connection_class
811
816
self .connection_kwargs = connection_kwargs
812
- self .response_callbacks = connection_kwargs .pop ("response_callbacks " , {})
817
+ self .response_callbacks = connection_kwargs .pop ("cluster_response_callbacks " , {})
813
818
814
819
self ._connections : List [Connection ] = []
815
820
self ._free : Deque [Connection ] = collections .deque (maxlen = self .max_connections )
@@ -1206,7 +1211,7 @@ async def close(self, attr: str = "nodes_cache") -> None:
1206
1211
)
1207
1212
1208
1213
1209
- class ClusterPipeline (AbstractRedis , AbstractRedisCluster , AsyncRedisClusterCommands ):
1214
+ class ClusterPipeline (RedisCluster ):
1210
1215
"""
1211
1216
Create a new ClusterPipeline object.
1212
1217
@@ -1245,9 +1250,21 @@ class ClusterPipeline(AbstractRedis, AbstractRedisCluster, AsyncRedisClusterComm
1245
1250
1246
1251
__slots__ = ("_command_stack" , "_client" )
1247
1252
1248
- def __init__ (self , client : RedisCluster ) -> None :
1253
+ def __init__ (
1254
+ self ,
1255
+ client : RedisCluster ,
1256
+ nodes_manager = None ,
1257
+ commands_parser = None ,
1258
+ result_callbacks = None ,
1259
+ startup_nodes = None ,
1260
+ read_from_replicas = False ,
1261
+ cluster_error_retry_attempts = 5 ,
1262
+ reinitialize_steps = 10 ,
1263
+ lock = None ,
1264
+ ** kwargs ,
1265
+ ) -> None :
1249
1266
self ._client = client
1250
-
1267
+ self . cluster_response_callbacks = self . RESPONSE_CALLBACKS
1251
1268
self ._command_stack : List ["PipelineCommand" ] = []
1252
1269
1253
1270
async def initialize (self ) -> "ClusterPipeline" :
0 commit comments