From c4cdbc18ca7c8269b25904e4e9da3c76c3a92c6c Mon Sep 17 00:00:00 2001 From: Viktor Kuptsov Date: Tue, 21 Oct 2014 10:49:34 +0300 Subject: [PATCH] Added TIME command that returns the current server time. --- tests/test_operations.py | 12 ++++++++++++ txredisapi.py | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/tests/test_operations.py b/tests/test_operations.py index 2016aac..e9faad4 100644 --- a/tests/test_operations.py +++ b/tests/test_operations.py @@ -137,3 +137,15 @@ def testRedisOperationsSet3(self): result_2 = yield db.get(key) self.assertEqual(result_2, "foo") yield db.disconnect() + + @defer.inlineCallbacks + def testRedisOperationTime(self): + db = yield redis.Connection(REDIS_HOST, REDIS_PORT, reconnect=False) + + time = yield db.time() + self.assertIsInstance(time, list) + self.assertEqual(len(time), 2) + self.assertIsInstance(time[0], int) + self.assertIsInstance(time[1], int) + + yield db.disconnect() diff --git a/txredisapi.py b/txredisapi.py index ea91dcf..3a133fb 100644 --- a/txredisapi.py +++ b/txredisapi.py @@ -648,6 +648,13 @@ def flushall(self): """ return self.execute_command("FLUSHALL") + def time(self): + """ + Returns the current server time as a two items lists: a Unix timestamp + and the amount of microseconds already elapsed in the current second + """ + return self.execute_command("TIME") + # Commands operating on string values def set(self, key, value, expire=None, pexpire=None, only_if_not_exists=False, only_if_exists=False):