original_docstring: 
          Send a command to a node in the cluster
          
docstring: Send a command to a node in the cluster
docstring_tokens: Send a command to a node in the cluster
code: def execute_command(self, *args, **kwargs):
          """
          Send a command to a node in the cluster
          """
          if not args:
              raise RedisClusterException("Unable to determine command to use")
  
          command = args[0]
  
          node = self.determine_node(*args, **kwargs)
          if node:
              return self._execute_command_on_nodes(node, *args, **kwargs)
  
          # If set externally we must update it before calling any commands
          if self.refresh_table_asap:
              self.connection_pool.nodes.initialize()
              self.refresh_table_asap = False
  
          redirect_addr = None
          asking = False
  
          try_random_node = False
          slot = self._determine_slot(*args)
          ttl = int(self.RedisClusterRequestTTL)
  
          while ttl > 0:
              ttl -= 1
  
              if asking:
                  node = self.connection_pool.nodes.nodes[redirect_addr]
                  r = self.connection_pool.get_connection_by_node(node)
              elif try_random_node:
                  r = self.connection_pool.get_random_connection()
                  try_random_node = False
              else:
                  if self.refresh_table_asap:
                      # MOVED
                      node = self.connection_pool.get_master_node_by_slot(slot)
                  else:
                      node = self.connection_pool.get_node_by_slot(slot)
                  r = self.connection_pool.get_connection_by_node(node)
  
              try:
                  if asking:
                      r.send_command('ASKING')
                      self.parse_response(r, "ASKING", **kwargs)
                      asking = False
  
                  r.send_command(*args)
                  return self.parse_response(r, command, **kwargs)
              except (RedisClusterException, BusyLoadingError):
                  raise
              except (ConnectionError, TimeoutError):
                  try_random_node = True
  
                  if ttl < self.RedisClusterRequestTTL / 2:
                      time.sleep(0.1)
              except ClusterDownError as e:
                  self.connection_pool.disconnect()
                  self.connection_pool.reset()
                  self.refresh_table_asap = True
  
                  raise e
              except MovedError as e:
                  # Reinitialize on ever x number of MovedError.
                  # This counter will increase faster when the same client object
                  # is shared between multiple threads. To reduce the frequency you
                  # can set the variable 'reinitialize_steps' in the constructor.
                  self.reinitialize_counter += 1
                  if self.reinitialize_counter % self.reinitialize_steps == 0:
                      self.refresh_table_asap = True
  
                  node = self.connection_pool.nodes.set_node(e.host, e.port, server_type='master')
                  self.connection_pool.nodes.slots[e.slot_id][0] = node
              except TryAgainError as e:
                  if ttl < self.COMMAND_TTL / 2:
                      time.sleep(0.05)
              except AskError as e:
                  redirect_addr, asking = "{0}:{1}".format(e.host, e.port), True
              finally:
                  self.connection_pool.release(r)
  
          raise ClusterError('TTL exhausted.')
code_tokens: def execute_command ( self , * args , ** kwargs ) : if not args : raise RedisClusterException ( "Unable to determine command to use" ) command = args [ 0 ] node = self . determine_node ( * args , ** kwargs ) if node : return self . _execute_command_on_nodes ( node , * args , ** kwargs ) if self . refresh_table_asap : self . connection_pool . nodes . initialize ( ) self . refresh_table_asap = False redirect_addr = None asking = False try_random_node = False slot = self . _determine_slot ( * args ) ttl = int ( self . RedisClusterRequestTTL ) while ttl > 0 : ttl -= 1 if asking : node = self . connection_pool . nodes . nodes [ redirect_addr ] r = self . connection_pool . get_connection_by_node ( node ) elif try_random_node : r = self . connection_pool . get_random_connection ( ) try_random_node = False else : if self . refresh_table_asap : node = self . connection_pool . get_master_node_by_slot ( slot ) else : node = self . connection_pool . get_node_by_slot ( slot ) r = self . connection_pool . get_connection_by_node ( node ) try : if asking : r . send_command ( 'ASKING' ) self . parse_response ( r , "ASKING" , ** kwargs ) asking = False r . send_command ( * args ) return self . parse_response ( r , command , ** kwargs ) except ( RedisClusterException , BusyLoadingError ) : raise except ( ConnectionError , TimeoutError ) : try_random_node = True if ttl < self . RedisClusterRequestTTL / 2 : time . sleep ( 0.1 ) except ClusterDownError as e : self . connection_pool . disconnect ( ) self . connection_pool . reset ( ) self . refresh_table_asap = True raise e except MovedError as e : self . reinitialize_counter += 1 if self . reinitialize_counter % self . reinitialize_steps == 0 : self . refresh_table_asap = True node = self . connection_pool . nodes . set_node ( e . host , e . port , server_type = 'master' ) self . connection_pool . nodes . slots [ e . slot_id ] [ 0 ] = node except TryAgainError as e : if ttl < self . COMMAND_TTL / 2 : time . sleep ( 0.05 ) except AskError as e : redirect_addr , asking = "{0}:{1}" . format ( e . host , e . port ) , True finally : self . connection_pool . release ( r ) raise ClusterError ( 'TTL exhausted.' )
short_docstring: Send a command to a node in the cluster
short_docstring_tokens: Send a command to a node in the cluster
comment: """
          Send a command to a node in the cluster
          """$SEP$# If set externally we must update it before calling any commands$SEP$# MOVED$SEP$# Reinitialize on ever x number of MovedError.$SEP$# This counter will increase faster when the same client object$SEP$# is shared between multiple threads. To reduce the frequency you$SEP$# can set the variable 'reinitialize_steps' in the constructor.