diff --git a/CHANGELOG b/CHANGELOG index d8df77c5..4a412fea 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +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 + desynchronization errors (ISSUE #20). + v0.6.4 (2011-02-12) * Various performance improvements (15% ~ 25%) especially when dealing with long multibulk replies or when using clustered connections. diff --git a/lib/Predis.php b/lib/Predis.php index 97afcf66..4f8efa16 100644 --- a/lib/Predis.php +++ b/lib/Predis.php @@ -578,7 +578,7 @@ class ResponseBulkHandler implements IResponseHandler { )); } if ($length >= 0) { - return $length > 0 ? substr($connection->readBytes($length + 2), 0, -2) : ''; + return substr($connection->readBytes($length + 2), 0, -2); } if ($length == -1) { return null; diff --git a/test/PredisClientFeatures.php b/test/PredisClientFeatures.php index 847ca68b..a9880d04 100644 --- a/test/PredisClientFeatures.php +++ b/test/PredisClientFeatures.php @@ -381,6 +381,12 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase { }); } + function testResponseReader_EmptyBulkResponse() { + $this->assertTrue($this->redis->set('foo', '')); + $this->assertEquals('', $this->redis->get('foo')); + $this->assertEquals('', $this->redis->get('foo')); + } + /* Client + CommandPipeline */ diff --git a/test/RedisCommandsTest.php b/test/RedisCommandsTest.php index 926d40d5..3accc03b 100644 --- a/test/RedisCommandsTest.php +++ b/test/RedisCommandsTest.php @@ -89,8 +89,11 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase { function testGet() { $this->redis->set('foo', 'bar'); - $this->assertEquals('bar', $this->redis->get('foo')); + + $this->assertTrue($this->redis->set('foo', '')); + $this->assertEquals('', $this->redis->get('foo')); + $this->assertNull($this->redis->get('fooDoesNotExist')); // should throw an exception when trying to do a GET on non-string types