Переглянути джерело

Backported changes from the mainline library to the PHP 5.2 branch (up to commit c81e02b)

Daniele Alessandri 15 роки тому
батько
коміт
3ebdf16d1c
5 змінених файлів з 59 додано та 6 видалено
  1. 14 0
      CHANGELOG
  2. 1 1
      README.markdown
  3. 39 4
      lib/Predis.php
  4. 1 1
      test/PredisShared.php
  5. 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

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

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

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

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