Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 807f9cc

Browse files
committed
Merge pull request phpredis#177 from michael-grunder/master
INFO with optional argument
2 parents ad7de59 + c9dbfeb commit 807f9cc

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

redis.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,19 +3181,25 @@ PHP_METHOD(Redis, info) {
31813181

31823182
zval *object;
31833183
RedisSock *redis_sock;
3184+
char *cmd, *opt = NULL;
3185+
int cmd_len, opt_len;
31843186

3185-
char *cmd;
3186-
int cmd_len = redis_cmd_format_static(&cmd, "INFO", "");
3187-
3188-
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
3189-
&object, redis_ce) == FAILURE) {
3187+
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|s",
3188+
&object, redis_ce, &opt, &opt_len) == FAILURE) {
31903189
RETURN_FALSE;
31913190
}
31923191

31933192
if (redis_sock_get(object, &redis_sock TSRMLS_CC, 0) < 0) {
31943193
RETURN_FALSE;
31953194
}
31963195

3196+
// Build a standalone INFO command or one with an option
3197+
if(opt != NULL) {
3198+
cmd_len = redis_cmd_format_static(&cmd, "INFO", "s", opt, opt_len);
3199+
} else {
3200+
cmd_len = redis_cmd_format_static(&cmd, "INFO", "");
3201+
}
3202+
31973203
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
31983204
IF_ATOMIC() {
31993205
redis_info_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);

tests/TestRedis.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,13 @@ public function testinfo() {
15741574
foreach($keys as $k) {
15751575
$this->assertTrue(in_array($k, array_keys($info)));
15761576
}
1577+
1578+
// INFO COMMANDSTATS
1579+
$info = $this->redis->info("COMMANDSTATS");
1580+
1581+
foreach($info as $k => $value) {
1582+
$this->assertTrue(strpos($k, 'cmdstat_') !== false);
1583+
}
15771584
}
15781585

15791586
public function testSelect() {

0 commit comments

Comments
 (0)