6deca09bb0731ed2c3125f8229c436479d895d4a
[awesomized/libmemcached] / src / memrm.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <getopt.h>
4 #include <memcached.h>
5 #include "client_options.h"
6
7 static int opt_verbose;
8 static char *opt_servers;
9
10 int main(int argc, char *argv[])
11 {
12 memcached_st *memc;
13 char *string;
14 size_t string_length;
15 time_t expires = 0;
16 memcached_return rc;
17
18 static struct option long_options[] =
19 {
20 {"version", no_argument, NULL, OPT_VERSION},
21 {"help", no_argument, NULL, OPT_HELP},
22 {"verbose", no_argument, &opt_verbose, 1},
23 {"debug", no_argument, &opt_verbose, 2},
24 {"servers", required_argument, NULL, OPT_SERVERS},
25 {"expire", required_argument, NULL, OPT_EXPIRE},
26 {0, 0, 0, 0},
27 };
28 int option_index = 0;
29 int option_rv;
30
31 while (1)
32 {
33 option_rv = getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
34 if (option_rv == -1) break;
35 switch (option_rv) {
36 case 0:
37 break;
38 case OPT_VERSION: /* --version or -V */
39 printf("memcache tools, memrm, v1.0\n");
40 exit(0);
41 break;
42 case OPT_HELP: /* --help or -h */
43 printf("useful help messages go here\n");
44 exit(0);
45 break;
46 case OPT_SERVERS: /* --servers or -s */
47 opt_servers = optarg;
48 break;
49 case OPT_EXPIRE: /* --expire */
50 expires = (time_t)strtol(optarg, (char **)NULL, 10);
51 break;
52 case '?':
53 /* getopt_long already printed an error message. */
54 exit(1);
55 default:
56 abort();
57 }
58 }
59
60 memc= memcached_init(NULL);
61 parse_opt_servers(memc, opt_servers);
62
63 while (optind <= argc)
64 {
65 if (opt_verbose) {
66 printf("key: %s\nexpires: %ld\n", argv[optind], expires);
67 }
68 rc = memcached_delete(memc, argv[optind], strlen(argv[optind]), expires);
69 optind++;
70 }
71
72 memcached_deinit(memc);
73
74 return 0;
75 };