Skip to content

Commit

Permalink
TIME command
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-grunder committed Jun 5, 2012
1 parent f295c1c commit f1231c9
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 12 deletions.
13 changes: 13 additions & 0 deletions README.markdown
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions php_redis.h
Expand Up @@ -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);
Expand Down
59 changes: 47 additions & 12 deletions redis.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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: */

7 changes: 7 additions & 0 deletions tests/TestRedis.php
Expand Up @@ -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");
Expand Down

0 comments on commit f1231c9

Please sign in to comment.