Browse Source

New command: TIME (Redis v2.6-dev).

Daniele Alessandri 13 years ago
parent
commit
7893fd1faa

+ 43 - 0
lib/Predis/Command/ServerTime.php

@@ -0,0 +1,43 @@
+<?php
+
+/*
+ * This file is part of the Predis package.
+ *
+ * (c) Daniele Alessandri <suppakilla@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Predis\Command;
+
+/**
+ * @link http://redis.io/commands/time
+ * @author Daniele Alessandri <suppakilla@gmail.com>
+ */
+class ServerTime extends AbstractCommand
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function getId()
+    {
+        return 'TIME';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function canBeHashed()
+    {
+        return false;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function parseResponse($data)
+    {
+        return $data instanceof \Iterator ? iterator_to_array($data) : $data;
+    }
+}

+ 1 - 0
lib/Predis/Profile/ServerVersionNext.php

@@ -51,6 +51,7 @@ class ServerVersionNext extends ServerVersion24
 
             /* remote server control commands */
             'info'                      => 'Predis\Command\ServerInfoV26x',
+            'time'                      => 'Predis\Command\ServerTime',
         ));
     }
 }

+ 74 - 0
tests/Predis/Command/ServerTimeTest.php

@@ -0,0 +1,74 @@
+<?php
+
+/*
+ * This file is part of the Predis package.
+ *
+ * (c) Daniele Alessandri <suppakilla@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Predis\Command;
+
+use \PHPUnit_Framework_TestCase as StandardTestCase;
+
+/**
+ * @group commands
+ * @group realm-server
+ */
+class ServerTimeTest extends CommandTestCase
+{
+    /**
+     * {@inheritdoc}
+     */
+    protected function getExpectedCommand()
+    {
+        return 'Predis\Command\ServerTime';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function getExpectedId()
+    {
+        return 'TIME';
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testFilterArguments()
+    {
+        $arguments = array();
+        $expected = array();
+
+        $command = $this->getCommand();
+        $command->setArguments($arguments);
+
+        $this->assertSame($expected, $command->getArguments());
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testParseResponse()
+    {
+        $expected = array(1331114908, 453990);
+        $command = $this->getCommand();
+
+        $this->assertSame($expected, $command->parseResponse($expected));
+    }
+
+    /**
+     * @group connected
+     */
+    public function testReturnsServerTime()
+    {
+        $redis = $this->getClient();
+
+        $this->assertInternalType('array', $time = $redis->time());
+        $this->assertInternalType('string', $time[0]);
+        $this->assertInternalType('string', $time[1]);
+    }
+}

+ 1 - 0
tests/Predis/Profile/ServerVersionNextTest.php

@@ -168,6 +168,7 @@ class ServerVersionNextTest extends ServerVersionTestCase
             127 => 'eval',
             128 => 'evalsha',
             129 => 'script',
+            130 => 'time',
         );
     }
 }