Skip to content

Commit f1231c9

Browse files
TIME command
1 parent f295c1c commit f1231c9

File tree

4 files changed

+69
-12
lines changed

4 files changed

+69
-12
lines changed

README.markdown

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,3 +2549,16 @@ Migrates a key to a different Redis instance.
25492549
<pre>
25502550
$redis->migrate('backup', 6379, 'foo', 0, 3600);
25512551
</pre>
2552+
2553+
## time
2554+
##### Description
2555+
Return the current Redis server time.
2556+
##### Parameters
2557+
(none)
2558+
##### Return value
2559+
If successfull, the time will come back as an associative array with element zero being
2560+
the unix timestamp, and element one being microseconds.
2561+
##### Examples
2562+
<pre>
2563+
$redis->time();
2564+
</pre>

php_redis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ PHP_METHOD(Redis, dump);
136136
PHP_METHOD(Redis, restore);
137137
PHP_METHOD(Redis, migrate);
138138

139+
PHP_METHOD(Redis, time);
140+
139141
PHP_METHOD(Redis, getLastError);
140142
PHP_METHOD(Redis, _prefix);
141143
PHP_METHOD(Redis, _unserialize);

redis.c

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,6 @@ static zend_function_entry redis_functions[] = {
157157
PHP_ME(Redis, bitop, NULL, ZEND_ACC_PUBLIC)
158158
PHP_ME(Redis, bitcount, NULL, ZEND_ACC_PUBLIC)
159159

160-
PHP_ME(Redis, eval, NULL, ZEND_ACC_PUBLIC)
161-
PHP_ME(Redis, evalsha, NULL, ZEND_ACC_PUBLIC)
162-
PHP_ME(Redis, script, NULL, ZEND_ACC_PUBLIC)
163-
PHP_ME(Redis, dump, NULL, ZEND_ACC_PUBLIC)
164-
PHP_ME(Redis, restore, NULL, ZEND_ACC_PUBLIC)
165-
PHP_ME(Redis, migrate, NULL, ZEND_ACC_PUBLIC)
166-
167-
PHP_ME(Redis, getLastError, NULL, ZEND_ACC_PUBLIC)
168-
169-
PHP_ME(Redis, _prefix, NULL, ZEND_ACC_PUBLIC)
170-
PHP_ME(Redis, _unserialize, NULL, ZEND_ACC_PUBLIC)
171-
172160
/* 1.1 */
173161
PHP_ME(Redis, mset, NULL, ZEND_ACC_PUBLIC)
174162
PHP_ME(Redis, msetnx, NULL, ZEND_ACC_PUBLIC)
@@ -220,6 +208,22 @@ static zend_function_entry redis_functions[] = {
220208
PHP_ME(Redis, subscribe, NULL, ZEND_ACC_PUBLIC)
221209
PHP_ME(Redis, unsubscribe, NULL, ZEND_ACC_PUBLIC)
222210

211+
PHP_ME(Redis, time, NULL, ZEND_ACC_PUBLIC)
212+
213+
PHP_ME(Redis, eval, NULL, ZEND_ACC_PUBLIC)
214+
PHP_ME(Redis, evalsha, NULL, ZEND_ACC_PUBLIC)
215+
PHP_ME(Redis, script, NULL, ZEND_ACC_PUBLIC)
216+
217+
PHP_ME(Redis, dump, NULL, ZEND_ACC_PUBLIC)
218+
PHP_ME(Redis, restore, NULL, ZEND_ACC_PUBLIC)
219+
PHP_ME(Redis, migrate, NULL, ZEND_ACC_PUBLIC)
220+
221+
PHP_ME(Redis, getLastError, NULL, ZEND_ACC_PUBLIC)
222+
223+
PHP_ME(Redis, _prefix, NULL, ZEND_ACC_PUBLIC)
224+
PHP_ME(Redis, _unserialize, NULL, ZEND_ACC_PUBLIC)
225+
226+
223227
/* options */
224228
PHP_ME(Redis, getOption, NULL, ZEND_ACC_PUBLIC)
225229
PHP_ME(Redis, setOption, NULL, ZEND_ACC_PUBLIC)
@@ -6153,5 +6157,36 @@ PHP_METHOD(Redis, getLastError) {
61536157
}
61546158
}
61556159

6160+
/*
6161+
* {{{ proto Redis::time()
6162+
*/
6163+
PHP_METHOD(Redis, time) {
6164+
zval *object;
6165+
RedisSock *redis_sock;
6166+
char *cmd;
6167+
int cmd_len;
6168+
6169+
// Grab our object
6170+
if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, redis_ce) == FAILURE) {
6171+
RETURN_FALSE;
6172+
}
6173+
// Grab socket
6174+
if(redis_sock_get(object, &redis_sock TSRMLS_CC, 0) < 0) {
6175+
RETURN_FALSE;
6176+
}
6177+
6178+
// Build TIME command
6179+
cmd_len = redis_cmd_format_static(&cmd, "TIME", "");
6180+
6181+
// Execute or queue command
6182+
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
6183+
IF_ATOMIC() {
6184+
if(redis_sock_read_multibulk_reply_raw(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL) < 0) {
6185+
RETURN_FALSE;
6186+
}
6187+
}
6188+
REDIS_PROCESS_RESPONSE(redis_sock_read_multibulk_reply_raw);
6189+
}
6190+
61566191
/* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */
61576192

tests/TestRedis.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,6 +3197,13 @@ public function testReconnectSelect() {
31973197
// Revert the setting.
31983198
$this->redis->config('SET', 'timeout', $original_cfg['timeout']);
31993199
}
3200+
3201+
public function testTime() {
3202+
$time_arr = $this->redis->time();
3203+
$this->assertTrue(is_array($time_arr) && count($time_arr) == 2 &&
3204+
strval(intval($time_arr[0])) === strval($time_arr[0]) &&
3205+
strval(intval($time_arr[1])) === strval($time_arr[1]));
3206+
}
32003207
}
32013208

32023209
TestSuite::run("Redis_Test");

0 commit comments

Comments
 (0)