Predis-捕获连接错误

Ric*_*ett 3 php laravel predis

嗨,我有以下几点:

// Named array of connection parameters:
    $redis = new Predis\Client([
        'scheme' => 'tcp',
        'host'   => $host,
        'port'   => $port,
        'password'   => $auth,
    ]);

    try {
        // explicitly call Predis\Client::connect()
        $redis->connect();
    }
    catch (Exception $e) {
        return Redirect::to('profile')
                ->with('result', '<div class="col-lg-12"><div class="alert alert-danger alert-border-left alert-gradient alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <i class="fa fa-check pr10"></i>
                <strong>Error - '.$e.'</strong> Unable to connect to redis server, please double check your database detals.</div></div>');
    }
Run Code Online (Sandbox Code Playgroud)

但是,这并没有捕获诸如NOAUTH之类的错误。

有人可以指出我正确的方向吗?

And*_*ton 5

我广泛阅读了有关此问题的信息,尽管由于使用多个服务器,我的配置有所不同,并且我试图解决的问题是服务器出现故障,但这似乎对我来说是成功的:

 try {
      $client = new Predis\Client($params);
      $client->connect();
 } catch(Predis\Connection\ConnectionException $e) {
      echo $e->getMessage();
 }
Run Code Online (Sandbox Code Playgroud)

我尝试了许多变体,这似乎阻止了该应用程序的所有尖叫。在我的情况下,我传入了一组服务器,并尝试对其进行ping操作并删除发生故障的服务器。似乎有些大材小用,但是如果不这样做,我又如何知道服务器是否关闭?

另外,如果您不尝试连接,那么它将在其他地方失败,即连接是惰性的,并且在实际需要时会被调用-对我而言,这总是导致连接错误。在使用它之前我自己调用它使我可以捕获异常。然后,我不得不找出为什么异常不会发生的原因,不得不将其切换为Predis \ Connection \ ConnectionException。这比原本应该的难。