@@ -92,6 +92,26 @@ def fix_server(*args):
9292 return  slots 
9393
9494
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+ 
95115PRIMARY  =  "primary" 
96116REPLICA  =  "replica" 
97117SLOT_ID  =  "slot-id" 
@@ -274,6 +294,7 @@ class AbstractRedisCluster:
274294 "CLUSTER RESET" ,
275295 "CLUSTER SET-CONFIG-EPOCH" ,
276296 "CLUSTER SLOTS" ,
297+  "CLUSTER SHARDS" ,
277298 "CLUSTER COUNT-FAILURE-REPORTS" ,
278299 "CLUSTER KEYSLOT" ,
279300 "COMMAND" ,
@@ -354,7 +375,10 @@ class AbstractRedisCluster:
354375 ],
355376 )
356377
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+  }
358382
359383 RESULT_CALLBACKS  =  dict_merge (
360384 list_keys_to_dict (["PUBSUB NUMSUB" ], parse_pubsub_numsub ),
0 commit comments