@@ -92,6 +92,26 @@ def fix_server(*args):
92
92
return slots
93
93
94
94
95
+ def parse_cluster_shards (resp , ** options ):
96
+ """
97
+ Parse CLUSTER SHARDS response.
98
+ """
99
+ shards = []
100
+ for x in resp :
101
+ shard = {"slots" : [], "nodes" : []}
102
+ for i in range (0 , len (x [1 ]), 2 ):
103
+ shard ["slots" ].append ((x [1 ][i ], (x [1 ][i + 1 ])))
104
+ nodes = x [3 ]
105
+ for node in nodes :
106
+ dict_node = {}
107
+ for i in range (0 , len (node ), 2 ):
108
+ dict_node [node [i ]] = node [i + 1 ]
109
+ shard ["nodes" ].append (dict_node )
110
+ shards .append (shard )
111
+
112
+ return shards
113
+
114
+
95
115
PRIMARY = "primary"
96
116
REPLICA = "replica"
97
117
SLOT_ID = "slot-id"
@@ -274,6 +294,7 @@ class AbstractRedisCluster:
274
294
"CLUSTER RESET" ,
275
295
"CLUSTER SET-CONFIG-EPOCH" ,
276
296
"CLUSTER SLOTS" ,
297
+ "CLUSTER SHARDS" ,
277
298
"CLUSTER COUNT-FAILURE-REPORTS" ,
278
299
"CLUSTER KEYSLOT" ,
279
300
"COMMAND" ,
@@ -354,7 +375,10 @@ class AbstractRedisCluster:
354
375
],
355
376
)
356
377
357
- CLUSTER_COMMANDS_RESPONSE_CALLBACKS = {"CLUSTER SLOTS" : parse_cluster_slots }
378
+ CLUSTER_COMMANDS_RESPONSE_CALLBACKS = {
379
+ "CLUSTER SLOTS" : parse_cluster_slots ,
380
+ "CLUSTER SHARDS" : parse_cluster_shards ,
381
+ }
358
382
359
383
RESULT_CALLBACKS = dict_merge (
360
384
list_keys_to_dict (["PUBSUB NUMSUB" ], parse_pubsub_numsub ),
0 commit comments