title: Connection timed out [tcp://127.0.0.1:6379] using redis on linux server
body: <p>I have an Lumen API in my server, it was working fine. Actually this API will be calling every seconds from another server and update stock rates and store into redis. In this api I'm comparing the received data(request body) and stored data from redis and update the difference rate of current and previous values as response and also I will send current date time in redis  to show last rate update time of stock rates.
  I have the following code in my lumen api,</p>
  
  <pre><code>use Illuminate\Support\Facades\Redis;
  public function updatebaserate(Request $request)
  {
          $request_data = array();
          parse_str($request, $request_data);
          if (app('redis')-&gt;get("BaseRates")) {
              if(json_decode(app('redis')-&gt;get("BaseRates"),true) === json_decode($request-&gt;getContent(), true)){
                  $this-&gt;createrates();
                  return app('redis')-&gt;get("BaseRatesUpdated");
              }else{
                  $receivedrates = json_decode($request-&gt;getContent(), true);
                  $rate_valid = true;
                  if($rate_valid){
                      app('redis')-&gt;set("BaseRatesUpdated", Carbon::createFromFormat('d-m-Y H:i:s', date('d-m-Y H:i:s')));
                      app('redis')-&gt;set("BaseRates", $request-&gt;getContent());
                  }
              }
          } else {
              app('redis')-&gt;set("BaseRates", $request-&gt;getContent());
              app('redis')-&gt;set("BaseRatesUpdated", Carbon::createFromFormat('d-m-Y H:i:s', date('d-m-Y H:i:s')));
          }
          $this-&gt;createrates();
          return app('redis')-&gt;get("BaseRatesUpdated");
  }
  </code></pre>
  
  <p>This get and set of redis operation working continuously for every second 2 api request will call from another server. Whether it will cause any issue.
  In my lumen .env settings as </p>
  
  <pre><code>BROADCAST_DRIVER=redis
  
  CACHE_DRIVER=redis
  QUEUE_DRIVER=redis
  
  REDIS_HOST=127.0.0.1
  REDIS_PORT=6379
  </code></pre>
  
  <p>In server redis info showing following details,</p>
  
  <pre><code># Server
  redis_version:3.2.10
  tcp_port:6379
  
  # Clients
  connected_clients:13
  client_longest_output_list:0
  client_biggest_input_buf:0
  blocked_clients:0
  
  # Memory
  used_memory:1802320
  used_memory_human:1.72M
  used_memory_rss:2387968
  used_memory_rss_human:2.28M
  used_memory_peak:2200392
  used_memory_peak_human:2.10M
  total_system_memory:4026261504
  total_system_memory_human:3.75G
  used_memory_lua:39936
  used_memory_lua_human:39.00K
  maxmemory:0
  
  # Stats
  total_connections_received:302107
  total_commands_processed:30017647
  instantaneous_ops_per_sec:302
  total_net_input_bytes:6532076041
  total_net_output_bytes:67794026721
  instantaneous_input_kbps:59.68
  instantaneous_output_kbps:642.24
  rejected_connections:0
  </code></pre>
  
  <p>Is there any issue on continuously read and write keys in redis for every second. And also I have set redis timeout value  </p>
  
  <pre><code>127.0.0.1:6379&gt; config get timeout
  1) "timeout"
  2) "100"
  </code></pre>
  
  <p>Is there any way to open and close connection in lumen api for redis. I have often receiving the error in error log like</p>
  
  <pre><code>[2020-03-17 17:17:29] production.ERROR: Predis\Connection\ConnectionException: Connection timed out [tcp://127.0.0.1:6379] in /home/public_html/winapi/vendor/predis/predis/src/Connection/AbstractConnection.php:155
  Stack trace:
  #0 /home/public_html/winapi/vendor/predis/predis/src/Connection/StreamConnection.php(128): Predis\Connection\AbstractConnection-&gt;onConnectionError('Connection time...', 110)
  #1 /home/public_html/winapi/vendor/predis/predis/src/Connection/StreamConnection.php(178): Predis\Connection\StreamConnection-&gt;createStreamSocket(Object(Predis\Connection\Parameters), 'tcp://127.0.0.1...', 4)
  #2 /home/public_html/winapi/vendor/predis/predis/src/Connection/StreamConnection.php(100): Predis\Connection\StreamConnection-&gt;tcpStreamInitializer(Object(Predis\Connection\Parameters))
  </code></pre>
  
  <p>Please help any one to resolve the issue. </p>