diff options
-rw-r--r-- | README.markdown | 13 | ||||
-rwxr-xr-x | php_redis.h | 2 | ||||
-rwxr-xr-x | redis.c | 59 | ||||
-rw-r--r-- | tests/TestRedis.php | 7 |
4 files changed, 69 insertions, 12 deletions
diff --git a/README.markdown b/README.markdown index 468cddf3..a355af6c 100644 --- a/README.markdown +++ b/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> diff --git a/php_redis.h b/php_redis.h index 4a87e496..4092d38f 100755 --- a/php_redis.h +++ b/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); @@ -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: */ diff --git a/tests/TestRedis.php b/tests/TestRedis.php index e2d2ef37..188d8224 100644 --- a/tests/TestRedis.php +++ b/tests/TestRedis.php @@ -3197,6 +3197,13 @@ class Redis_Test extends TestSuite // 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"); |