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 "memexist"
19 #define PROGRAM_DESCRIPTION "Check for the existence of a key within a memcached cluster."
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
, "key [key ...]"};
28 for (const auto &def
: opt
.defaults
) {
32 char **argp
= nullptr;
33 if (!opt
.parse(argc
, argv
, &argp
)) {
38 if (!check_memcached(opt
, memc
)) {
42 if (!opt
.apply(&memc
)) {
43 memcached_free(&memc
);
47 if (!check_argp(opt
, argp
, "No key(s) provided.")) {
48 memcached_free(&memc
);
52 auto exit_code
= EXIT_SUCCESS
;
53 for (auto arg
= argp
; *arg
; ++arg
) {
56 if (check_return(opt
, memc
, key
, memcached_exist(&memc
, *arg
, strlen(*arg
)))) {
57 if (opt
.isset("verbose")) {
58 std::cerr
<< "Found key '" << *arg
<< "'.\n";
61 exit_code
= EXIT_FAILURE
;
66 memcached_free(&memc
);