nodes: 0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, identifier:key; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, expression_statement; 15, if_statement; 16, expression_statement; 17, if_statement; 18, if_statement; 19, if_statement; 20, if_statement; 21, if_statement; 22, if_statement; 23, return_statement; 24, identifier:by; 25, None; 26, identifier:external; 27, None; 28, identifier:offset; 29, integer:0; 30, identifier:limit; 31, None; 32, identifier:order; 33, None; 34, identifier:alpha; 35, False; 36, identifier:store_as; 37, None; 38, comment:"""Returns or stores the elements contained in the list, set or sorted
          set at key. By default, sorting is numeric and elements are compared by
          their value interpreted as double precision floating point number.
  
          The ``external`` parameter is used to specify the
          `GET <http://redis.io/commands/sort#retrieving-external-keys>_`
          parameter for retrieving external keys. It can be a single string
          or a list of strings.
  
          .. note::
  
             **Time complexity**: ``O(N+M*log(M))`` where ``N`` is the number of
             elements in the list or set to sort, and ``M`` the number of
             returned elements. When the elements are not sorted, complexity is
             currently ``O(N)`` as there is a copy step that will be avoided in
             next releases.
  
          :param key: The key to get the refcount for
          :type key: :class:`str`, :class:`bytes`
  
          :param by: The optional pattern for external sorting keys
          :type by: :class:`str`, :class:`bytes`
          :param external: Pattern or list of patterns to return external keys
          :type external: :class:`str`, :class:`bytes`, list
          :param int offset: The starting offset when using limit
          :param int limit: The number of elements to return
          :param order: The sort order - one of ``ASC`` or ``DESC``
          :type order: :class:`str`, :class:`bytes`
          :param bool alpha: Sort the results lexicographically
          :param store_as: When specified, the key to store the results as
          :type store_as: :class:`str`, :class:`bytes`, None
          :rtype: list|int
          :raises: :exc:`~tredis.exceptions.RedisError`
          :raises: :exc:`ValueError`
  
          """; 39, boolean_operator; 40, block; 41, assignment; 42, identifier:by; 43, block; 44, boolean_operator; 45, block; 46, elif_clause; 47, identifier:limit; 48, block; 49, identifier:order; 50, block; 51, comparison_operator:alpha is True; 52, block; 53, identifier:store_as; 54, block; 55, call; 56, identifier:order; 57, comparison_operator:order not in [b'ASC', b'DESC', 'ASC', 'DESC']; 58, raise_statement; 59, identifier:command; 60, list; 61, expression_statement; 62, identifier:external; 63, call; 64, for_statement; 65, identifier:external; 66, block; 67, expression_statement; 68, expression_statement; 69, identifier:alpha; 70, True; 71, expression_statement; 72, expression_statement; 73, attribute; 74, argument_list; 75, identifier:order; 76, list; 77, call; 78, string; 79, identifier:key; 80, augmented_assignment; 81, identifier:isinstance; 82, argument_list; 83, identifier:entry; 84, identifier:external; 85, block; 86, expression_statement; 87, augmented_assignment; 88, call; 89, call; 90, augmented_assignment; 91, identifier:self; 92, identifier:_execute; 93, identifier:command; 94, string; 95, string; 96, string; 97, string; 98, identifier:ValueError; 99, argument_list; 100, string_content:SORT; 101, identifier:command; 102, list; 103, identifier:external; 104, identifier:list; 105, expression_statement; 106, augmented_assignment; 107, identifier:command; 108, list; 109, attribute; 110, argument_list; 111, attribute; 112, argument_list; 113, identifier:command; 114, list; 115, string_content:ASC; 116, string_content:DESC; 117, string_content:ASC; 118, string_content:DESC; 119, call; 120, string; 121, identifier:by; 122, augmented_assignment; 123, identifier:command; 124, list; 125, string; 126, call; 127, call; 128, identifier:command; 129, identifier:append; 130, identifier:order; 131, identifier:command; 132, identifier:append; 133, string; 134, string; 135, identifier:store_as; 136, attribute; 137, argument_list; 138, string_content:BY; 139, identifier:command; 140, list; 141, string; 142, identifier:external; 143, string_content:LIMIT; 144, attribute; 145, argument_list; 146, attribute; 147, argument_list; 148, string_content:ALPHA; 149, string_content:STORE; 150, string:'invalid sort order "{}"'; 151, identifier:format; 152, identifier:order; 153, string; 154, identifier:entry; 155, string_content:GET; 156, call; 157, identifier:encode; 158, string; 159, call; 160, identifier:encode; 161, string; 162, string_content:GET; 163, identifier:ascii; 164, argument_list; 165, string_content:utf-8; 166, identifier:ascii; 167, argument_list; 168, string_content:utf-8; 169, identifier:offset; 170, identifier:limit
code: def sort(self,
               key,
               by=None,
               external=None,
               offset=0,
               limit=None,
               order=None,
               alpha=False,
               store_as=None):
          """Returns or stores the elements contained in the list, set or sorted
          set at key. By default, sorting is numeric and elements are compared by
          their value interpreted as double precision floating point number.
  
          The ``external`` parameter is used to specify the
          `GET <http://redis.io/commands/sort#retrieving-external-keys>_`
          parameter for retrieving external keys. It can be a single string
          or a list of strings.
  
          .. note::
  
             **Time complexity**: ``O(N+M*log(M))`` where ``N`` is the number of
             elements in the list or set to sort, and ``M`` the number of
             returned elements. When the elements are not sorted, complexity is
             currently ``O(N)`` as there is a copy step that will be avoided in
             next releases.
  
          :param key: The key to get the refcount for
          :type key: :class:`str`, :class:`bytes`
  
          :param by: The optional pattern for external sorting keys
          :type by: :class:`str`, :class:`bytes`
          :param external: Pattern or list of patterns to return external keys
          :type external: :class:`str`, :class:`bytes`, list
          :param int offset: The starting offset when using limit
          :param int limit: The number of elements to return
          :param order: The sort order - one of ``ASC`` or ``DESC``
          :type order: :class:`str`, :class:`bytes`
          :param bool alpha: Sort the results lexicographically
          :param store_as: When specified, the key to store the results as
          :type store_as: :class:`str`, :class:`bytes`, None
          :rtype: list|int
          :raises: :exc:`~tredis.exceptions.RedisError`
          :raises: :exc:`ValueError`
  
          """
          if order and order not in [b'ASC', b'DESC', 'ASC', 'DESC']:
              raise ValueError('invalid sort order "{}"'.format(order))
  
          command = [b'SORT', key]
          if by:
              command += [b'BY', by]
          if external and isinstance(external, list):
              for entry in external:
                  command += [b'GET', entry]
          elif external:
              command += [b'GET', external]
          if limit:
              command += [
                  b'LIMIT',
                  ascii(offset).encode('utf-8'),
                  ascii(limit).encode('utf-8')
              ]
          if order:
              command.append(order)
          if alpha is True:
              command.append(b'ALPHA')
          if store_as:
              command += [b'STORE', store_as]
  
          return self._execute(command)