Browse Source

Change Predis\Connection in order to disable read/write timeouts when the value of 'read_write_timeout' is also equal to 0.

Daniele Alessandri 14 năm trước cách đây
mục cha
commit
e700061cc0
3 tập tin đã thay đổi với 9 bổ sung3 xóa
  1. 4 0
      CHANGELOG
  2. 1 1
      examples/PubSubContext.php
  3. 4 2
      lib/Predis.php

+ 4 - 0
CHANGELOG

@@ -4,6 +4,10 @@ v0.6.6 (2011-xx-xx)
   * ZUNIONSTORE and ZINTERSTORE can accept an array to specify a list of the 
     source keys to be used to populate the destination key.
 
+  * The "read_write_timeout" connection parameter can now be set to 0 or false 
+    to disable read and write timeouts on connections. The old behaviour of -1 
+    is still intact.
+
 v0.6.5 (2011-02-12)
   * FIX: due to an untested internal change introduced in v0.6.4, a wrong 
     handling of bulk reads of zero-length values was producing protocol 

+ 1 - 1
examples/PubSubContext.php

@@ -5,7 +5,7 @@ require_once 'SharedConfigurations.php';
 // events published on certain channels (PUBSUB).
 
 // Create a client and disable r/w timeout on the socket
-$redis  = new Predis\Client($single_server + array('read_write_timeout' => -1));
+$redis  = new Predis\Client($single_server + array('read_write_timeout' => 0));
 
 // Initialize a new pubsub context
 $pubsub = $redis->pubSubContext();

+ 4 - 2
lib/Predis.php

@@ -1377,9 +1377,11 @@ class Connection implements IConnection {
         }
 
         if (isset($parameters->read_write_timeout)) {
+            $rwtimeout = $parameters->read_write_timeout;
+            $rwtimeout = $rwtimeout > 0 ? $rwtimeout : -1;
             $timeoutSeconds  = floor($parameters->read_write_timeout);
-            $timeoutUSeconds = ($parameters->read_write_timeout - $timeoutSeconds) * 1000000;
-            stream_set_timeout($socket, $timeoutSeconds, $timeoutUSeconds);
+            $timeoutUSeconds = ($rwtimeout - $timeoutSeconds) * 1000000;
+            stream_set_timeout($socket, $rwtimeout, $timeoutUSeconds);
         }
         return $socket;
     }