Browse Source

Merge branch 'master' into version-0.5

Daniele Alessandri 15 years ago
parent
commit
c81e02b0ba
4 changed files with 58 additions and 5 deletions
  1. 14 0
      CHANGELOG
  2. 39 4
      lib/Predis.php
  3. 1 1
      test/PredisShared.php
  4. 4 0
      test/RedisCommandsTest.php

+ 14 - 0
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

+ 39 - 4
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'; }

+ 1 - 1
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);

+ 4 - 0
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());
     }