Browse Source

Added CLIENT SET/GETNAME command

Raphael Stolt 12 years ago
parent
commit
1536455fea
2 changed files with 77 additions and 1 deletions
  1. 2 1
      lib/Predis/Command/ServerClient.php
  2. 75 0
      tests/Predis/Command/ServerClientTest.php

+ 2 - 1
lib/Predis/Command/ServerClient.php

@@ -35,8 +35,9 @@ class ServerClient extends AbstractCommand
         switch (strtoupper($args[0])) {
             case 'LIST':
                 return $this->parseClientList($data);
-
             case 'KILL':
+            case 'GETNAME':
+            case 'SETNAME':
             default:
                 return $data;
         }

+ 75 - 0
tests/Predis/Command/ServerClientTest.php

@@ -63,6 +63,32 @@ class ServerClientTest extends CommandTestCase
         $this->assertSame($expected, $command->getArguments());
     }
 
+    /**
+     * @group disconnected
+     */
+    public function testFilterArgumentsOfClientGetname()
+    {
+        $arguments = $expected = array('getname');
+
+        $command = $this->getCommand();
+        $command->setArguments($arguments);
+
+        $this->assertSame($expected, $command->getArguments());
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testFilterArgumentsOfClientSetname()
+    {
+        $arguments = $expected = array('setname', 'connection-a');
+
+        $command = $this->getCommand();
+        $command->setArguments($arguments);
+
+        $this->assertSame($expected, $command->getArguments());
+    }
+
     /**
      * @group disconnected
      */
@@ -117,6 +143,55 @@ BUFFER;
         $this->assertArrayHasKey('psub', $clients[0]);
     }
 
+    /**
+     * @group connected
+     */
+    public function testGetsNameOfConnection()
+    {
+         $redis = $this->getClient();
+         $clientName = $redis->client('GETNAME');
+         $this->assertNull($clientName);
+
+         $expectedConnectionName = 'foo-bar';
+         $this->assertTrue($redis->client('SETNAME', $expectedConnectionName));
+         $this->assertEquals($expectedConnectionName, $redis->client('GETNAME'));
+    }
+
+    /**
+     * @group connected
+     */
+    public function testSetsNameOfConnection()
+    {
+         $redis = $this->getClient();
+
+         $expectedConnectionName = 'foo-baz';
+         $this->assertTrue($redis->client('SETNAME', $expectedConnectionName));
+         $this->assertEquals($expectedConnectionName, $redis->client('GETNAME'));
+    }
+
+    /**
+     * @return array
+     */
+    public function invalidConnectionNameProvider()
+    {
+        return array(
+            array('foo space'),
+            array('foo \n'),
+            array('foo $'),
+        );
+    }
+
+    /**
+     * @group connected
+     * @expectedException Predis\ServerException
+     * @dataProvider invalidConnectionNameProvider
+     */
+    public function testInvalidSetNameOfConnection($invalidConnectionName)
+    {
+         $redis = $this->getClient();
+         $redis->client('SETNAME', $invalidConnectionName);
+    }
+
     /**
      * @group connected
      * @expectedException Predis\ServerException