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/README.markdown b/README.markdown index b7eaaf48..431e0e8b 100644 --- a/README.markdown +++ b/README.markdown @@ -88,7 +88,7 @@ client instance at runtime. Actually, it is easier done than said: } $redis = new Predis_Client(); - $redis->registerCommand('BrandNewRedisCommand', 'newcmd'); + $redis->getProfile()->registerCommand('BrandNewRedisCommand', 'newcmd'); $redis->newcmd(); diff --git a/lib/Predis.php b/lib/Predis.php index 1db5389f..0e41ada4 100644 --- a/lib/Predis.php +++ b/lib/Predis.php @@ -784,7 +784,7 @@ class Predis_ConnectionCluster implements Predis_IConnection, IteratorAggregate /* ------------------------------------------------------------------------- */ abstract class Predis_RedisServerProfile { - const DEFAULT_SERVER_PROFILE = 'Predis_RedisServer_v1_2'; + private static $_serverProfiles; private $_registeredCommands; public function __construct() { @@ -796,8 +796,27 @@ abstract class Predis_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 Predis_ClientException("Unknown server profile: $version"); + } + $profile = self::$_serverProfiles[$version]; + return new $profile(); } public function compareWith($version, $operator = null) { @@ -1017,6 +1036,10 @@ class Predis_RedisServer_v1_2 extends Predis_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', )); } } @@ -1276,7 +1299,11 @@ class Predis_Commands_ListRemove extends Predis_BulkCommand { public function getCommandId() { return 'LREM'; } } -class Predis_Commands_ListPopLastPushHead extends Predis_BulkCommand { +class Predis_Commands_ListPopLastPushHead extends Predis_InlineCommand { + public function getCommandId() { return 'RPOPLPUSH'; } +} + +class Predis_Commands_ListPopLastPushHeadBulk extends Predis_BulkCommand { public function getCommandId() { return 'RPOPLPUSH'; } } @@ -1484,6 +1511,14 @@ class Predis_Commands_BackgroundSave extends Predis_InlineCommand { } } +class Predis_Commands_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 Predis_Commands_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 9c6a0b84..d1c134bd 100644 --- a/test/PredisShared.php +++ b/test/PredisShared.php @@ -30,7 +30,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 f3325852..718f2def 100644 --- a/test/RedisCommandsTest.php +++ b/test/RedisCommandsTest.php @@ -1336,6 +1336,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()); }