title: Laravel: How to Check Redis Availability?
body: <p>How can i check the availability of Redis connection in <strong>Laravel 5.4</strong>. I tried below code, but getting an exception with ping line. How can i do, if Redis is not connected than do something else to avoid exception?</p>
  
  <blockquote>
    <p>No connection could be made because the target machine actively
    refused it. [tcp://127.0.0.1:6379]</p>
  </blockquote>
  
  <pre><code>use Redis;
  
  class SocketController extends Controller
  {
      public function sendMessage(){
          $redis = Redis::connection();
  
          if($redis-&gt;ping()){
              print_r("expression");
          }
          else{
              print_r("expression2");
          }
      }
  }
  </code></pre>
  
  <p>Also tried this:</p>
  
  <pre><code>$redis = Redis::connection();
          try{
              $redis-&gt;ping();
          } catch (Exception $e){
              $e-&gt;getMessage();
          }
  </code></pre>
  
  <p>But unable to catch exception</p>