def METHOD_NAME(vm, port=MEMCACHED_PORT):
  """Block until the memcached server is up and responsive.
  Will timeout after 5 minutes, and raise an exception. Before the timeout
  expires any exceptions are caught and the status check is retried.
  We check the status of the server by issuing a 'stats' command. This should
  return many lines of form 'STAT <name> <value>' if the server is up and
  running.
  Args:
    vm: VirtualMachine memcached has been installed on.
    port: int. Memcached port to use.
  Raises:
    errors.Resource.RetryableCreationError when response is not as expected or
      if there is an error connecting to the port or otherwise running the
      remote check command.
  """
  address = vm.internal_ip
  logging.info('Trying to connect to memcached at %s:%s', address, port)
  try:
    out, _ = vm.RemoteCommand(
        '(echo -e "stats\n")| netcat -q 1 %s %s' % (address, port))
    if out.startswith('STAT '):
      logging.info('memcached server stats received. Server up and running.')
      return
  except errors.VirtualMachine.RemoteCommandError as e:
    raise errors.Resource.RetryableCreationError(
        'memcached server not up yet: %s.' % str(e))
  else:
    raise errors.Resource.RetryableCreationError(
        'memcached server not up yet. Expected "STAT" but got "%s".' % out)