From f580e35770a744c60cb92e1cd581944d9da72205 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Mon, 8 Oct 2007 12:57:07 -0700 Subject: [PATCH] Updated for help commands (and a little bit on ketama) --- ChangeLog | 1 + lib/memcached_hash.c | 8 +++++++- src/client_options.h | 7 +++++++ src/memcat.c | 1 - src/utilities.c | 33 +++++++++++++++++++++++++++++++++ src/utilities.h | 1 + 6 files changed, 49 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7f745df0..09f260aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ set the servers list. * fixed memcached_stat method (and now memstat works) * server connect now happens on demand. + * Help for all command line applications 0.4 Wed Oct 3 10:28:50 PDT 2007 * Added buffered IO to write calls for keys diff --git a/lib/memcached_hash.c b/lib/memcached_hash.c index cb3d5218..4d0d6cf2 100644 --- a/lib/memcached_hash.c +++ b/lib/memcached_hash.c @@ -21,7 +21,13 @@ unsigned int memcached_generate_hash(memcached_st *ptr, char *key, size_t key_le else return_value= internal_generate_hash(key, key_length); - return return_value % ptr->number_of_hosts; + if (ptr->flags & MEM_USE_KETAMA) + { + assert(0); + return 0; + } + else + return return_value % ptr->number_of_hosts; } static unsigned int internal_generate_hash(char *key, size_t key_length) diff --git a/src/client_options.h b/src/client_options.h index 03eac3cc..9242884e 100644 --- a/src/client_options.h +++ b/src/client_options.h @@ -1,3 +1,8 @@ +#ifndef __CLIENT_OPTIONS_H__ +#define __CLIENT_OPTIONS_H__ + +typedef struct memcached_help_text_st memcached_help_text_st; + typedef enum { OPT_SERVERS= 's', OPT_VERSION= 'V', @@ -17,3 +22,5 @@ typedef enum { OPT_SLAP_TCP_NODELAY, OPT_FLUSH, } memcached_options; + +#endif /* CLIENT_OPTIONS */ diff --git a/src/memcat.c b/src/memcat.c index 1c9082f5..88018e19 100644 --- a/src/memcat.c +++ b/src/memcat.c @@ -3,7 +3,6 @@ #include #include -#include "client_options.h" #include "utilities.h" #define PROGRAM_NAME "memcat" diff --git a/src/utilities.c b/src/utilities.c index e6db318b..de11ee2d 100644 --- a/src/utilities.c +++ b/src/utilities.c @@ -2,6 +2,7 @@ #include #include "utilities.h" + long int timedif(struct timeval a, struct timeval b) { register int us, s; @@ -19,6 +20,32 @@ void version_command(char *command_name) exit(0); } +char *lookup_help(memcached_options option) +{ + switch (option) + { + case OPT_SERVERS: return("List which servers you wish to connect to."); + case OPT_VERSION: return("Display the version of the application and then exit."); + case OPT_HELP: return("Diplay this message and then exit."); + case OPT_VERBOSE: return("Give more details on the progression of the application."); + case OPT_DEBUG: return("Provide output only useful for debugging."); + case OPT_FLAG: return("Provide flag information for storage operation."); + case OPT_EXPIRE: return("Set the expire option for the object."); + case OPT_SET: return("Use set command with memcached when storing."); + case OPT_REPLACE: return("Use replace command with memcached when storing."); + case OPT_ADD: return("Use add command with memcached when storing."); + case OPT_SLAP_EXECUTE_NUMBER: return("Number of times to execute the given test."); + case OPT_SLAP_INITIAL_LOAD: return("Number of key pairs to load before executing tests."); + case OPT_SLAP_TEST: return("Test to run."); + case OPT_SLAP_CONCURRENCY: return("Number of users to simulate with load."); + case OPT_SLAP_NON_BLOCK: return("Set TCP up to use non-blocking IO."); + case OPT_SLAP_TCP_NODELAY: return("Set TCP socket up to use nodelay."); + case OPT_FLUSH: return("Flush servers before running tests."); + }; + + return "forgot to document this one :)"; +} + void help_command(char *command_name, char *description, const struct option *long_options, memcached_programs_help_st *options) @@ -30,8 +57,14 @@ void help_command(char *command_name, char *description, printf("Current options. A '=' means the option takes a value.\n\n"); for (x= 0; long_options[x].name; x++) + { + char *help_message; + printf("\t --%s%c\n", long_options[x].name, long_options[x].has_arg ? '=' : ' '); + if ((help_message= lookup_help(long_options[x].val))) + printf("\t\t%s\n", help_message); + } printf("\n"); exit(0); diff --git a/src/utilities.h b/src/utilities.h index 5a1b916d..857f7803 100644 --- a/src/utilities.h +++ b/src/utilities.h @@ -1,5 +1,6 @@ #include #include +#include "client_options.h" typedef struct memcached_programs_help_st memcached_programs_help_st; -- 2.30.2