Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

TIME command

  • Loading branch information...
commit f1231c98e2d48a1f57797b6549c3e44470141233 1 parent f295c1c
@michael-grunder michael-grunder authored
Showing with 69 additions and 12 deletions.
  1. +13 −0 README.markdown
  2. +2 −0  php_redis.h
  3. +47 −12 redis.c
  4. +7 −0 tests/TestRedis.php
View
13 README.markdown
@@ -2549,3 +2549,16 @@ Migrates a key to a different Redis instance.
<pre>
$redis->migrate('backup', 6379, 'foo', 0, 3600);
</pre>
+
+## time
+##### Description
+Return the current Redis server time.
+##### Parameters
+(none)
+##### Return value
+If successfull, the time will come back as an associative array with element zero being
+the unix timestamp, and element one being microseconds.
+##### Examples
+<pre>
+$redis->time();
+</pre>
View
2  php_redis.h
@@ -136,6 +136,8 @@ PHP_METHOD(Redis, dump);
PHP_METHOD(Redis, restore);
PHP_METHOD(Redis, migrate);
+PHP_METHOD(Redis, time);
+
PHP_METHOD(Redis, getLastError);
PHP_METHOD(Redis, _prefix);
PHP_METHOD(Redis, _unserialize);
View
59 redis.c
@@ -157,18 +157,6 @@ static zend_function_entry redis_functions[] = {
PHP_ME(Redis, bitop, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, bitcount, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, eval, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, evalsha, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, script, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, dump, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, restore, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, migrate, NULL, ZEND_ACC_PUBLIC)
-
- PHP_ME(Redis, getLastError, NULL, ZEND_ACC_PUBLIC)
-
- PHP_ME(Redis, _prefix, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, _unserialize, NULL, ZEND_ACC_PUBLIC)
-
/* 1.1 */
PHP_ME(Redis, mset, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, msetnx, NULL, ZEND_ACC_PUBLIC)
@@ -220,6 +208,22 @@ static zend_function_entry redis_functions[] = {
PHP_ME(Redis, subscribe, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, unsubscribe, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, time, NULL, ZEND_ACC_PUBLIC)
+
+ PHP_ME(Redis, eval, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, evalsha, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, script, NULL, ZEND_ACC_PUBLIC)
+
+ PHP_ME(Redis, dump, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, restore, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, migrate, NULL, ZEND_ACC_PUBLIC)
+
+ PHP_ME(Redis, getLastError, NULL, ZEND_ACC_PUBLIC)
+
+ PHP_ME(Redis, _prefix, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, _unserialize, NULL, ZEND_ACC_PUBLIC)
+
+
/* options */
PHP_ME(Redis, getOption, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, setOption, NULL, ZEND_ACC_PUBLIC)
@@ -6153,5 +6157,36 @@ PHP_METHOD(Redis, getLastError) {
}
}
+/*
+ * {{{ proto Redis::time()
+ */
+PHP_METHOD(Redis, time) {
+ zval *object;
+ RedisSock *redis_sock;
+ char *cmd;
+ int cmd_len;
+
+ // Grab our object
+ if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, redis_ce) == FAILURE) {
+ RETURN_FALSE;
+ }
+ // Grab socket
+ if(redis_sock_get(object, &redis_sock TSRMLS_CC, 0) < 0) {
+ RETURN_FALSE;
+ }
+
+ // Build TIME command
+ cmd_len = redis_cmd_format_static(&cmd, "TIME", "");
+
+ // Execute or queue command
+ REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
+ IF_ATOMIC() {
+ if(redis_sock_read_multibulk_reply_raw(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL) < 0) {
+ RETURN_FALSE;
+ }
+ }
+ REDIS_PROCESS_RESPONSE(redis_sock_read_multibulk_reply_raw);
+}
+
/* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */
View
7 tests/TestRedis.php
@@ -3197,6 +3197,13 @@ public function testReconnectSelect() {
// Revert the setting.
$this->redis->config('SET', 'timeout', $original_cfg['timeout']);
}
+
+ public function testTime() {
+ $time_arr = $this->redis->time();
+ $this->assertTrue(is_array($time_arr) && count($time_arr) == 2 &&
+ strval(intval($time_arr[0])) === strval($time_arr[0]) &&
+ strval(intval($time_arr[1])) === strval($time_arr[1]));
+ }
}
TestSuite::run("Redis_Test");

0 comments on commit f1231c9

Please sign in to comment.
Something went wrong with that request. Please try again.