From 21acb300a7131916d06e4164be29f6f8f9a44914 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 23 Jan 2010 12:28:39 +0100 Subject: [PATCH 1/6] The command ListPopLastPushHead (RPOPLPUSH) is now defined as an inline command instead of bulk after a change in Redis 1.2.1. The old bulk RPOPLPUSH has been preserved and renamed in ListPopLastPushHeadBulk, so that you can override the current server profile if you need the old (and uncorrect) behaviour when connecting to a Redis 1.2.0 instance. --- lib/Predis.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Predis.php b/lib/Predis.php index 0b9d9529..e4d7b1cc 100644 --- a/lib/Predis.php +++ b/lib/Predis.php @@ -1262,7 +1262,11 @@ class ListRemove extends \Predis\BulkCommand { public function getCommandId() { return 'LREM'; } } -class ListPopLastPushHead extends \Predis\BulkCommand { +class ListPopLastPushHead extends \Predis\InlineCommand { + public function getCommandId() { return 'RPOPLPUSH'; } +} + +class ListPopLastPushHeadBulk extends \Predis\BulkCommand { public function getCommandId() { return 'RPOPLPUSH'; } } From 8622dd8b0545c8b1a303a2e81faf13194ead2403 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 23 Jan 2010 12:41:45 +0100 Subject: [PATCH 2/6] Added the CHANGELOG file. --- CHANGELOG | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 CHANGELOG diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 00000000..fd27edaf --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,9 @@ +v0.5.1 + * RPOPLPUSH has been changed from bulk command to inline command in Redis + 1.2.1, so ListPopLastPushHead now extends InlineCommand. The old RPOPLPUSH + behavior is still available via the ListPopLastPushHeadBulk class so that + you can override the server profile if you need the old (and uncorrect) + behaviour when connecting to a Redis 1.2.0 instance. + +v0.5.0 + * First versioned release of Predis From 6cb9663539f236dcc0459e3c9cb5f11b1e9e5f14 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 23 Jan 2010 12:54:58 +0100 Subject: [PATCH 3/6] Added missing support for BGREWRITEAOF for Redis >= 1.2.0 --- CHANGELOG | 2 ++ lib/Predis.php | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index fd27edaf..2cbc929d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,5 +5,7 @@ v0.5.1 you can override the server profile if you need the old (and uncorrect) behaviour when connecting to a Redis 1.2.0 instance. + * Added missing support for BGREWRITEAOF for Redis >= 1.2.0 + v0.5.0 * First versioned release of Predis diff --git a/lib/Predis.php b/lib/Predis.php index e4d7b1cc..a46208eb 100644 --- a/lib/Predis.php +++ b/lib/Predis.php @@ -1003,6 +1003,10 @@ class RedisServer_v1_2 extends RedisServer_v1_0 { 'zsetScore' => '\Predis\Commands\ZSetScore', 'zremrangebyscore' => '\Predis\Commands\ZSetRemoveRangeByScore', 'zsetRemoveRangeByScore' => '\Predis\Commands\ZSetRemoveRangeByScore', + + /* persistence control commands */ + 'bgrewriteaof' => '\Predis\Commands\BackgroundRewriteAppendOnlyFile', + 'backgroundRewriteAppendOnlyFile' => '\Predis\Commands\BackgroundRewriteAppendOnlyFile', )); } } @@ -1474,6 +1478,14 @@ class BackgroundSave extends \Predis\InlineCommand { } } +class BackgroundRewriteAppendOnlyFile extends \Predis\InlineCommand { + public function canBeHashed() { return false; } + public function getCommandId() { return 'BGREWRITEAOF'; } + public function parseResponse($data) { + return $data == 'Background append only file rewriting started'; + } +} + class LastSave extends \Predis\InlineCommand { public function canBeHashed() { return false; } public function getCommandId() { return 'LASTSAVE'; } From afdc79f97f334fab4ac1dacf2b82ce64ba32faaf Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 23 Jan 2010 15:31:53 +0100 Subject: [PATCH 4/6] Added tests for BGREWRITEAOF. --- test/RedisCommandsTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/RedisCommandsTest.php b/test/RedisCommandsTest.php index 31615eea..3cd44db4 100644 --- a/test/RedisCommandsTest.php +++ b/test/RedisCommandsTest.php @@ -1337,6 +1337,10 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase { $this->assertTrue($this->redis->backgroundSave()); } + function testBackgroundRewriteAppendOnlyFile() { + $this->assertTrue($this->redis->backgroundRewriteAppendOnlyFile()); + } + function testLastSave() { $this->assertGreaterThan(0, $this->redis->lastSave()); } From 7fa935f8272926285d7c3521a4bd0d0c8ddb3513 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 23 Jan 2010 15:55:34 +0100 Subject: [PATCH 5/6] Implemented a factory method for creating server profiles instances. --- lib/Predis.php | 25 ++++++++++++++++++++++--- test/PredisShared.php | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/Predis.php b/lib/Predis.php index a46208eb..8604e301 100644 --- a/lib/Predis.php +++ b/lib/Predis.php @@ -770,7 +770,7 @@ class ConnectionCluster implements IConnection, \IteratorAggregate { /* ------------------------------------------------------------------------- */ abstract class RedisServerProfile { - const DEFAULT_SERVER_PROFILE = '\Predis\RedisServer_v1_2'; + private static $_serverProfiles; private $_registeredCommands; public function __construct() { @@ -782,8 +782,27 @@ abstract class RedisServerProfile { protected abstract function getSupportedCommands(); public static function getDefault() { - $defaultProfile = self::DEFAULT_SERVER_PROFILE; - return new $defaultProfile(); + return self::get('default'); + } + + private static function predisServerProfiles() { + return array( + '1.0' => '\Predis\RedisServer_v1_0', + '1.2' => '\Predis\RedisServer_v1_2', + 'default' => '\Predis\RedisServer_v1_2', + 'dev' => '\Predis\RedisServer_vNext', + ); + } + + public static function get($version) { + if (!isset(self::$_serverProfiles)) { + self::$_serverProfiles = self::predisServerProfiles(); + } + if (!isset(self::$_serverProfiles[$version])) { + throw new ClientException("Unknown server profile: $version"); + } + $profile = self::$_serverProfiles[$version]; + return new $profile(); } public function compareWith($version, $operator = null) { diff --git a/test/PredisShared.php b/test/PredisShared.php index fc513477..2eb2bbe9 100644 --- a/test/PredisShared.php +++ b/test/PredisShared.php @@ -26,7 +26,7 @@ class RC { private static $_connection; private static function createConnection() { - $serverProfile = new Predis\RedisServer_vNext(); + $serverProfile = Predis\RedisServerProfile::get('dev'); $connection = new Predis\Client(array('host' => RC::SERVER_HOST, 'port' => RC::SERVER_PORT), $serverProfile); $connection->connect(); $connection->selectDatabase(RC::DEFAULT_DATABASE); From 1be9bef15909c2e3e11facca1d51b2b78ad01495 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 23 Jan 2010 16:01:03 +0100 Subject: [PATCH 6/6] Updated CHANGELOG --- CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 2cbc929d..d8a43a7a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,5 +7,8 @@ v0.5.1 * Added missing support for BGREWRITEAOF for Redis >= 1.2.0 + * Implemented a factory method for the RedisServerProfile class to ease the + creation of new server profile instances based on a version string. + v0.5.0 * First versioned release of Predis