diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 00000000..d8a43a7a --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,14 @@ +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. + + * 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 diff --git a/lib/Predis.php b/lib/Predis.php index 0b9d9529..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) { @@ -1003,6 +1022,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', )); } } @@ -1262,7 +1285,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'; } } @@ -1470,6 +1497,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'; } 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); 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()); }