From: Brian Aker Date: Fri, 16 Jul 2010 03:19:00 +0000 (-0700) Subject: Merge in usage for execute_stat. X-Git-Tag: 0.44~23 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=6ed79842586640b88d73b90fe42ed88ff1d891e1;p=m6w6%2Flibmemcached Merge in usage for execute_stat. --- diff --git a/clients/memstat.c b/clients/memstat.c index 510cb359..652421bc 100644 --- a/clients/memstat.c +++ b/clients/memstat.c @@ -56,36 +56,22 @@ static struct option long_options[]= }; -static memcached_return_t server_print_callback(const memcached_st *memc, - memcached_server_instance_st instance, - void *context) +static memcached_return_t stat_printer(memcached_server_instance_st instance, + const char *key, size_t key_length, + const char *value, size_t value_length, + void *context) { - memcached_stat_st server_stat; - memcached_return_t rc; - char **list; - char **ptr; - + static memcached_server_instance_st last= NULL; (void)context; - rc= memcached_stat_servername(&server_stat, NULL, - memcached_server_name(instance), - memcached_server_port(instance)); - - list= memcached_stat_get_keys(memc, &server_stat, &rc); - - printf("Server: %s (%u)\n", memcached_server_name(instance), - (uint32_t)memcached_server_port(instance)); - - for (ptr= list; *ptr; ptr++) + if (last != instance) { - char *value= memcached_stat_get_value(memc, &server_stat, *ptr, &rc); - - printf("\t %s: %s\n", *ptr, value); - free(value); + printf("Server: %s (%u)\n", memcached_server_name(instance), + (uint32_t)memcached_server_port(instance)); + last= instance; } - free(list); - printf("\n"); + printf("\t %.*s: %.*s\n", (int)key_length, key, (int)value_length, value); return MEMCACHED_SUCCESS; } @@ -140,12 +126,7 @@ int main(int argc, char *argv[]) } else { - memcached_server_fn callbacks[1]; - - callbacks[0]= server_print_callback; - rc= memcached_server_cursor(memc, callbacks, - NULL, 1); - + rc= memcached_stat_execute(memc, NULL, stat_printer, NULL); } free(opt_servers); diff --git a/tests/mem_functions.c b/tests/mem_functions.c index a94787bb..510d6ace 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -5725,6 +5725,7 @@ static test_return_t test_cull_servers(memcached_st *memc) return TEST_SUCCESS; } + static memcached_return_t stat_printer(memcached_server_instance_st server, const char *key, size_t key_length, const char *value, size_t value_length,