From 0546f743742f4c6cd15b7e7a58c02ede8a68b749 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 12 Feb 2011 21:55:22 +0100 Subject: [PATCH] Backported changes from the mainline library to the PHP 5.2 branch (up to commit f76d616) --- CHANGELOG | 5 +++++ VERSION | 2 +- lib/Predis.php | 2 +- test/PredisClientFeatures.php | 6 ++++++ test/RedisCommandsTest.php | 5 ++++- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1d5c1dcd..95e1edc2 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/VERSION b/VERSION index d2b13eb6..ef5e4454 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.6.4 +0.6.5 diff --git a/lib/Predis.php b/lib/Predis.php index 62c4dd0a..ac73d6c6 100644 --- a/lib/Predis.php +++ b/lib/Predis.php @@ -585,7 +585,7 @@ class Predis_ResponseBulkHandler implements Predis_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 861d8035..50bdb9ce 100644 --- a/test/PredisClientFeatures.php +++ b/test/PredisClientFeatures.php @@ -401,6 +401,12 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase { $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $thrownException->getMessage()); } + 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 a06f2b23..5dee7ed2 100644 --- a/test/RedisCommandsTest.php +++ b/test/RedisCommandsTest.php @@ -90,8 +90,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