diff options
author | michael-grunder <michael.grunder@gmail.com> | 2014-07-21 23:50:52 +0400 |
---|---|---|
committer | michael-grunder <michael.grunder@gmail.com> | 2014-07-21 23:50:52 +0400 |
commit | 94e064940c488805485ad61a470ec9b34784f71f (patch) | |
tree | c7fd179b24fb366ac4d063842ddc40aa84a3bea3 | |
parent | 6d14bf535548f1614d07460f0939cf5a29ec7103 (diff) | |
parent | 96374a91051ded6275885dd2459f0c7bd5d300fe (diff) |
Merge branch 'hotfix/debug_object'debug_object
-rw-r--r-- | library.c | 61 | ||||
-rw-r--r-- | library.h | 1 | ||||
-rw-r--r-- | php_redis.h | 1 | ||||
-rw-r--r-- | redis.c | 32 | ||||
-rw-r--r-- | tests/TestRedis.php | 6 |
5 files changed, 101 insertions, 0 deletions
@@ -1089,6 +1089,67 @@ PHP_REDIS_API void redis_ping_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock * } } +/* Response for DEBUG object which is a formatted single line reply */ +PHP_REDIS_API void redis_debug_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + zval *z_tab, void *ctx) +{ + char *resp, *p, *p2, *p3, *p4; + int is_numeric, resp_len; + zval *z_result; + + /* Add or return false if we can't read from the socket */ + if((resp = redis_sock_read(redis_sock, &resp_len TSRMLS_CC))==NULL) { + IF_MULTI_OR_PIPELINE() { + add_next_index_bool(z_tab, 0); + return; + } + RETURN_FALSE; + } + + MAKE_STD_ZVAL(z_result); + array_init(z_result); + + /* Skip the '+' */ + p = resp + 1; + + /* <info>:<value> <info2:value2> ... */ + while((p2 = strchr(p, ':'))!=NULL) { + /* Null terminate at the ':' */ + *p2++ = '\0'; + + /* Null terminate at the space if we have one */ + if((p3 = strchr(p2, ' '))!=NULL) { + *p3++ = '\0'; + } else { + p3 = resp + resp_len; + } + + is_numeric = 1; + for(p4=p2; *p4; ++p4) { + if(*p4 < '0' || *p4 > '9') { + is_numeric = 0; + break; + } + } + + /* Add our value */ + if(is_numeric) { + add_assoc_long(z_result, p, atol(p2)); + } else { + add_assoc_string(z_result, p, p2, 1); + } + + p = p3; + } + + efree(resp); + + IF_MULTI_OR_PIPELINE() { + add_next_index_zval(z_tab, z_result); + } else { + RETVAL_ZVAL(z_result, 0, 1); + } +} /** * redis_sock_create @@ -21,6 +21,7 @@ PHP_REDIS_API void redis_boolean_response(INTERNAL_FUNCTION_PARAMETERS, RedisSoc PHP_REDIS_API void redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); PHP_REDIS_API void redis_string_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); PHP_REDIS_API void redis_ping_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API void redis_debug_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); PHP_REDIS_API void redis_info_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); PHP_REDIS_API void redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); PHP_REDIS_API RedisSock* redis_sock_create(char *host, int host_len, unsigned short port, double timeout, int persistent, char *persistent_id, long retry_interval, zend_bool lazy_connect); diff --git a/php_redis.h b/php_redis.h index ccc2e724..e6ec1ef2 100644 --- a/php_redis.h +++ b/php_redis.h @@ -134,6 +134,7 @@ PHP_METHOD(Redis, bitpos); PHP_METHOD(Redis, eval); PHP_METHOD(Redis, evalsha); PHP_METHOD(Redis, script); +PHP_METHOD(Redis, debug); PHP_METHOD(Redis, dump); PHP_METHOD(Redis, restore); PHP_METHOD(Redis, migrate); @@ -240,6 +240,7 @@ static zend_function_entry redis_functions[] = { PHP_ME(Redis, evalsha, NULL, ZEND_ACC_PUBLIC) PHP_ME(Redis, script, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Redis, debug, 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) @@ -6564,6 +6565,37 @@ PHP_METHOD(Redis, dump) { REDIS_PROCESS_RESPONSE(redis_ping_response); } +/* {{{ proto Redis::DEBUG(string key) */ +PHP_METHOD(Redis, debug) { + zval *object; + RedisSock *redis_sock; + char *cmd, *key; + int cmd_len, key_len, key_free; + + if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", + &object, redis_ce, &key, &key_len)==FAILURE) + { + RETURN_FALSE; + } + + /* Grab our socket */ + if(redis_sock_get(object, &redis_sock TSRMLS_CC, 0)<0) { + RETURN_FALSE; + } + + /* Prefix key, format command */ + key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC); + cmd_len = redis_cmd_format_static(&cmd, "DEBUG", "ss", "OBJECT", sizeof("OBJECT")-1, key, key_len); + if(key_free) efree(key); + + /* Kick it off */ + REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len); + IF_ATOMIC() { + redis_debug_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL); + } + REDIS_PROCESS_RESPONSE(redis_debug_response); +} + /* * {{{ proto Redis::restore(ttl, key, value) */ diff --git a/tests/TestRedis.php b/tests/TestRedis.php index 9fe4e039..9bbef4da 100644 --- a/tests/TestRedis.php +++ b/tests/TestRedis.php @@ -4237,6 +4237,12 @@ class Redis_Test extends TestSuite $this->assertTrue($this->redis->getOption(Redis::OPT_SERIALIZER) === Redis::SERIALIZER_NONE); // get ok } + public function testDebug() { + $this->redis->set('foo', 0); + $arr_info = $this->redis->debug('foo'); + $this->assertTrue(isset($arr_info['encoding']) && $arr_info['encoding']=='int'); + } + public function testDumpRestore() { if (version_compare($this->version, "2.5.0", "lt")) { |