How do I retrieve the query parameters from a path? How do I retrieve the query parameters from a path. Here's my path:

/search?keys=hello

Here is what I've tried:
$test1 = \Drupal::request()-&gt;request-&gt;get('name');
$test2 = \Drupal::request()-&gt;query-&gt;get('name');
$test3 = \Drupal::service('path.current')-&gt;getPath();
$test4 = \Drupal::request()-&gt;server-&gt;get('REQUEST_METHOD');
$test5 = \Drupal::request()-&gt;query-&gt;get('q');
$test6 = \Drupal::request()-&gt;request-&gt;get('keys');
$test7 = \Drupal::request()-&gt;query-&gt;get('keys');
$test8 = \Drupal::request()-&gt;query-&gt;get('destination');
$test9 = \Drupal::request()-&gt;request-&gt;all();
$test10 = \Drupal::request()-&gt;getRequestUri();

Here are the results:

Test 1: NULL
Test 2: NULL
Test 3: '/search'
Test 4: 'GET'
Test 5: NULL
Test 6: NULL
Test 7: NULL
Test 8: NULL
Test 9: array ( )
Test 10: '/search'

Why is this not working?
The problem was the block was cached.  See Clive's comment:

public function build() {
  $test = \Drupal::request()-&gt;query-&gt;get('keys');
  return array(
    '#markup' =&gt; $test,
    '#cache' =&gt; array(
      'contexts' =&gt; array(
        'url.query_args:keys',
      ),
    ),
  );
}