36
36
static void options_parse(int argc, char *argv[]);
38
static int opt_binary=0;
38
static bool opt_binary=0;
39
39
static int opt_verbose= 0;
40
40
static char *opt_servers= NULL;
41
41
static char *opt_hash= NULL;
43
43
static char *opt_passwd;
45
45
/* Print the keys and counter how many were found */
46
static memcached_return_t key_printer(const memcached_st *ptr,
46
static memcached_return_t key_printer(const memcached_st *,
47
47
const char *key, size_t key_length,
50
(void)ptr;(void)context;
51
printf("%.*s\n", (uint32_t)key_length, key);
50
std::cout.write(key, key_length);
51
std::cout << std::endl;
53
53
return MEMCACHED_SUCCESS;
56
56
int main(int argc, char *argv[])
59
memcached_return_t rc;
60
memcached_server_st *servers;
61
58
memcached_dump_fn callbacks[1];
63
60
callbacks[0]= &key_printer;
65
62
options_parse(argc, argv);
67
memc= memcached_create(NULL);
64
memcached_st *memc= memcached_create(NULL);
68
65
process_hash_option(memc, opt_hash);
67
if (opt_servers == NULL)
74
71
if ((temp= getenv("MEMCACHED_SERVERS")))
75
73
opt_servers= strdup(temp);
78
fprintf(stderr, "No Servers provided\n");
77
std::cerr << "No Servers provided" << std::endl;
82
memcached_server_st *servers;
84
85
servers= memcached_servers_parse(opt_servers);
86
89
servers= memcached_servers_parse(argv[--argc]);
88
92
memcached_server_push(memc, servers);
89
93
memcached_server_list_free(servers);
111
rc= memcached_dump(memc, callbacks, NULL, 1);
115
memcached_return_t rc= memcached_dump(memc, callbacks, NULL, 1);
113
if (rc != MEMCACHED_SUCCESS)
117
int exit_code= EXIT_SUCCESS;
118
if (memcached_failed(rc))
115
fprintf(stderr, "memdump: memcache error %s", memcached_strerror(memc, rc));
116
if (memcached_last_error_errno(memc))
117
fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc)));
118
fprintf(stderr, "\n");
122
std::cerr << "Failed to dump keys: " << memcached_last_error_message(memc) << std::endl;
124
exit_code= EXIT_FAILURE;
121
127
memcached_free(memc);
124
131
free(opt_servers);
131
141
static void options_parse(int argc, char *argv[])
136
143
static struct option long_options[]=
138
145
{(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION},
139
146
{(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP},
147
{(OPTIONSTRING)"quiet", no_argument, NULL, OPT_QUIET},
140
148
{(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
141
149
{(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG},
142
150
{(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS},
159
bool opt_version= false;
160
bool opt_help= false;
152
option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
163
int option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
154
165
if (option_rv == -1) break;
163
176
case OPT_VERBOSE: /* --verbose or -v */
164
opt_verbose = OPT_VERBOSE;
177
opt_verbose= OPT_VERBOSE;
166
180
case OPT_DEBUG: /* --debug or -d */
167
opt_verbose = OPT_DEBUG;
181
opt_verbose= OPT_DEBUG;
169
184
case OPT_VERSION: /* --version or -V */
170
version_command(PROGRAM_NAME);
172
188
case OPT_HELP: /* --help or -h */
173
help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, NULL);
175
192
case OPT_SERVERS: /* --servers or -s */
176
193
opt_servers= strdup(optarg);
179
197
opt_hash= strdup(optarg);
181
200
case OPT_USERNAME:
182
201
opt_username= optarg;
185
205
opt_passwd= optarg;
188
213
/* getopt_long already printed an error message. */