Merge in usage for execute_stat.
authorBrian Aker <brian@gaz>
Fri, 16 Jul 2010 03:19:00 +0000 (20:19 -0700)
committerBrian Aker <brian@gaz>
Fri, 16 Jul 2010 03:19:00 +0000 (20:19 -0700)
clients/memstat.c
tests/mem_functions.c

index 510cb359937e5702ed2721ca988d234df50ae2a0..652421bc1dd553bb46e14e6cd17a60aa2a793ee5 100644 (file)
@@ -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);
index a94787bba84396a9f8d8685982994b5d7cda1470..510d6ace2f398bb9adef1b7fe441e63313d27440 100644 (file)
@@ -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,