diff options
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | redis/client.py | 6 | ||||
-rw-r--r-- | tests/server_commands.py | 19 |
3 files changed, 18 insertions, 8 deletions
@@ -1,5 +1,6 @@ * 2.6.3 (in development) * Added BITOP and BITCOUNT commands. Thanks Mark Tozzi. + * Added the TIME command. Thanks Jason Knight. * 2.6.2 * `from_url` is now available as a classmethod on client classes. Thanks Jon Parise for the patch. diff --git a/redis/client.py b/redis/client.py index 74a040a..d475ae3 100644 --- a/redis/client.py +++ b/redis/client.py @@ -373,8 +373,10 @@ class StrictRedis(object): return self.execute_command('DBSIZE') def time(self): - """Returns the server time in (seconds since epoch, microseconds - into this second).""" + """ + Returns the server time as a 2-item tuple of ints: + (seconds since epoch, microseconds into this second). + """ return self.execute_command('TIME') def debug_object(self, key): diff --git a/tests/server_commands.py b/tests/server_commands.py index 7fb8e79..df92bfb 100644 --- a/tests/server_commands.py +++ b/tests/server_commands.py @@ -38,12 +38,6 @@ class ServerCommandsTestCase(unittest.TestCase): self.client['b'] = 'bar' self.assertEquals(self.client.dbsize(), 2) - def test_time(self): - first = self.client.time() - time.sleep(0.05) - second = self.client.time() - self.assertLess(first, second) - def test_get_and_set(self): # get and set can't be tested independently of each other client = redis.Redis(host='localhost', port=6379, db=9) @@ -122,6 +116,19 @@ class ServerCommandsTestCase(unittest.TestCase): def test_ping(self): self.assertEquals(self.client.ping(), True) + def test_time(self): + version = self.client.info()['redis_version'] + if StrictVersion(version) < StrictVersion('2.6.0'): + try: + raise unittest.SkipTest() + except AttributeError: + return + + t = self.client.time() + self.assertEquals(len(t), 2) + self.assert_(isinstance(t[0], int)) + self.assert_(isinstance(t[1], int)) + # KEYS def test_append(self): # invalid key type |