2 +--------------------------------------------------------------------+
3 | libmemcached-awesome - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020-2021 Michael Wallner https://awesome.co/ |
13 +--------------------------------------------------------------------+
16 #include "mem_config.h"
18 #define PROGRAM_NAME "memflush"
19 #define PROGRAM_DESCRIPTION "Erase all data in a cluster of memcached servers."
20 #define PROGRAM_VERSION "1.1"
22 #include "common/options.hpp"
23 #include "common/checks.hpp"
25 int main(int argc
, char *argv
[]) {
26 client_options opt
{PROGRAM_NAME
, PROGRAM_VERSION
, PROGRAM_DESCRIPTION
};
28 for (const auto &def
: opt
.defaults
) {
29 switch (def
.opt
.val
) {
30 case 'H': // no need for --hash
38 opt
.add("expire", 'e', required_argument
, "Flush based on expire time.");
40 if (!opt
.parse(argc
, argv
, nullptr)) {
45 if (!check_memcached(opt
, memc
)) {
49 if (!opt
.apply(&memc
)) {
50 memcached_free(&memc
);
55 if (auto exp_str
= opt
.argof("expire")) {
56 expire
= std::stoul(exp_str
);
59 auto exit_code
= EXIT_SUCCESS
;
60 memcached_return_t rc
= memcached_flush(&memc
, expire
);
61 if (!memcached_success(rc
)) {
62 exit_code
= EXIT_FAILURE
;
63 if (!opt
.isset("quiet")) {
64 std::cerr
<< "Failed to flush server: " << memcached_last_error_message(&memc
) << "\n";
68 if (!check_buffering(opt
, memc
)) {
69 exit_code
= EXIT_FAILURE
;
72 memcached_free(&memc
);