5 #include "client_options.h"
8 static int opt_verbose
= 0;
9 static time_t opt_expire
= 0;
10 static char *opt_servers
= NULL
;
12 #define PROGRAM_NAME "memrm"
13 #define PROGRAM_DESCRIPTION "Erase a key or set of keys from a memcached cluster."
16 void options_parse(int argc
, char *argv
[]);
18 int main(int argc
, char *argv
[])
22 memcached_server_st
*servers
;
24 options_parse(argc
, argv
);
30 if ((temp
= getenv("MEMCACHED_SERVERS")))
31 opt_servers
= strdup(temp
);
36 memc
= memcached_create(NULL
);
38 servers
= memcached_servers_parse(opt_servers
);
39 memcached_server_push(memc
, servers
);
40 memcached_server_list_free(servers
);
45 printf("key: %s\nexpires: %llu\n", argv
[optind
], (unsigned long long)opt_expire
);
46 rc
= memcached_delete(memc
, argv
[optind
], strlen(argv
[optind
]), opt_expire
);
48 if (rc
!= MEMCACHED_SUCCESS
)
50 fprintf(stderr
, "memrm: %s: memcache error %s\n",
51 argv
[optind
], memcached_strerror(memc
, rc
));
65 void options_parse(int argc
, char *argv
[])
67 memcached_programs_help_st help_options
[]=
72 static struct option long_options
[]=
74 {"version", no_argument
, NULL
, OPT_VERSION
},
75 {"help", no_argument
, NULL
, OPT_HELP
},
76 {"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
77 {"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
78 {"servers", required_argument
, NULL
, OPT_SERVERS
},
79 {"expire", required_argument
, NULL
, OPT_EXPIRE
},
87 option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
88 if (option_rv
== -1) break;
93 case OPT_VERBOSE
: /* --verbose or -v */
94 opt_verbose
= OPT_VERBOSE
;
96 case OPT_DEBUG
: /* --debug or -d */
97 opt_verbose
= OPT_DEBUG
;
99 case OPT_VERSION
: /* --version or -V */
100 version_command(PROGRAM_NAME
);
102 case OPT_HELP
: /* --help or -h */
103 help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
, long_options
, help_options
);
105 case OPT_SERVERS
: /* --servers or -s */
106 opt_servers
= strdup(optarg
);
108 case OPT_EXPIRE
: /* --expire */
109 opt_expire
= (time_t)strtoll(optarg
, (char **)NULL
, 10);
112 /* getopt_long already printed an error message. */