What function/method can I use to redirect users to a different page? In Drupal 7, I use the following code.

function my_goto($path) { 
  drupal_goto($path, array(), 301);
}


What code should I use in Drupal 8?
This is the code that should be used in Drupal 8. See change Record for more info.

use Symfony\Component\HttpFoundation\RedirectResponse;

function my_goto($path) { 
  $response = new RedirectResponse($path);
  $response-&gt;send();
  return;
}