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
);
38 memc
= memcached_create(NULL
);
39 process_hash_option(memc
, opt_hash
);
41 servers
= memcached_servers_parse(opt_servers
);
42 memcached_server_push(memc
, servers
);
43 memcached_server_list_free(servers
);
48 printf("key: %s\nexpires: %llu\n", argv
[optind
], (unsigned long long)opt_expire
);
49 rc
= memcached_delete(memc
, argv
[optind
], strlen(argv
[optind
]), opt_expire
);
51 if (rc
!= MEMCACHED_SUCCESS
)
53 fprintf(stderr
, "memrm: %s: memcache error %s",
54 argv
[optind
], memcached_strerror(memc
, rc
));
55 if (memc
->cached_errno
)
56 fprintf(stderr
, " system error %s", strerror(memc
->cached_errno
));
57 fprintf(stderr
, "\n");
74 void options_parse(int argc
, char *argv
[])
76 memcached_programs_help_st help_options
[]=
81 static struct option long_options
[]=
83 {"version", no_argument
, NULL
, OPT_VERSION
},
84 {"help", no_argument
, NULL
, OPT_HELP
},
85 {"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
86 {"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
87 {"servers", required_argument
, NULL
, OPT_SERVERS
},
88 {"expire", required_argument
, NULL
, OPT_EXPIRE
},
89 {"hash", required_argument
, NULL
, OPT_HASH
},
97 option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
98 if (option_rv
== -1) break;
103 case OPT_VERBOSE
: /* --verbose or -v */
104 opt_verbose
= OPT_VERBOSE
;
106 case OPT_DEBUG
: /* --debug or -d */
107 opt_verbose
= OPT_DEBUG
;
109 case OPT_VERSION
: /* --version or -V */
110 version_command(PROGRAM_NAME
);
112 case OPT_HELP
: /* --help or -h */
113 help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
, long_options
, help_options
);
115 case OPT_SERVERS
: /* --servers or -s */
116 opt_servers
= strdup(optarg
);
118 case OPT_EXPIRE
: /* --expire */
119 opt_expire
= (time_t)strtoll(optarg
, (char **)NULL
, 10);
122 opt_hash
= strdup(optarg
);
125 /* getopt_long already printed an error message. */