4
#include <libmemcached/memcached.h>
6
#include "client_options.h"
9
static int opt_verbose= 0;
10
static time_t opt_expire= 0;
11
static char *opt_servers= NULL;
12
static char *opt_hash= NULL;
14
#define PROGRAM_NAME "memrm"
15
#define PROGRAM_DESCRIPTION "Erase a key or set of keys from a memcached cluster."
18
void options_parse(int argc, char *argv[]);
20
int main(int argc, char *argv[])
24
memcached_server_st *servers;
26
options_parse(argc, argv);
32
if ((temp= getenv("MEMCACHED_SERVERS")))
33
opt_servers= strdup(temp);
36
fprintf(stderr, "No Servers provided\n");
41
memc= memcached_create(NULL);
42
process_hash_option(memc, opt_hash);
44
servers= memcached_servers_parse(opt_servers);
45
memcached_server_push(memc, servers);
46
memcached_server_list_free(servers);
51
printf("key: %s\nexpires: %llu\n", argv[optind], (unsigned long long)opt_expire);
52
rc = memcached_delete(memc, argv[optind], strlen(argv[optind]), opt_expire);
54
if (rc != MEMCACHED_SUCCESS)
56
fprintf(stderr, "memrm: %s: memcache error %s",
57
argv[optind], memcached_strerror(memc, rc));
58
if (memc->cached_errno)
59
fprintf(stderr, " system error %s", strerror(memc->cached_errno));
60
fprintf(stderr, "\n");
77
void options_parse(int argc, char *argv[])
79
memcached_programs_help_st help_options[]=
84
static struct option long_options[]=
86
{"version", no_argument, NULL, OPT_VERSION},
87
{"help", no_argument, NULL, OPT_HELP},
88
{"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
89
{"debug", no_argument, &opt_verbose, OPT_DEBUG},
90
{"servers", required_argument, NULL, OPT_SERVERS},
91
{"expire", required_argument, NULL, OPT_EXPIRE},
92
{"hash", required_argument, NULL, OPT_HASH},
100
option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
101
if (option_rv == -1) break;
106
case OPT_VERBOSE: /* --verbose or -v */
107
opt_verbose = OPT_VERBOSE;
109
case OPT_DEBUG: /* --debug or -d */
110
opt_verbose = OPT_DEBUG;
112
case OPT_VERSION: /* --version or -V */
113
version_command(PROGRAM_NAME);
115
case OPT_HELP: /* --help or -h */
116
help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
118
case OPT_SERVERS: /* --servers or -s */
119
opt_servers= strdup(optarg);
121
case OPT_EXPIRE: /* --expire */
122
opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10);
125
opt_hash= strdup(optarg);
128
/* getopt_long already printed an error message. */