2 +--------------------------------------------------------------------+
3 | libmemcached - 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 Michael Wallner <mike@php.net> |
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"
24 int main(int argc
, char *argv
[]) {
25 client_options opt
{PROGRAM_NAME
, PROGRAM_VERSION
, PROGRAM_DESCRIPTION
, "key [key ...]"};
27 for (const auto &def
: opt
.defaults
) {
31 char **argp
= nullptr;
32 if (!opt
.parse(argc
, argv
, &argp
)) {
37 if (!memcached_create(&memc
)) {
38 if (!opt
.isset("quiet")) {
39 std::cerr
<< "Failed to initialize memcached client.\n";
44 if (!opt
.apply(&memc
)) {
45 memcached_free(&memc
);
50 if (!opt
.isset("quiet")) {
51 std::cerr
<< "No key(s) provided.\n";
53 memcached_free(&memc
);
57 auto exit_code
= EXIT_SUCCESS
;
58 for (auto arg
= argp
; *arg
; ++arg
) {
59 auto rc
= memcached_exist(&memc
, *arg
, strlen(*arg
));
61 if (MEMCACHED_SUCCESS
== rc
) {
62 if (opt
.isset("verbose")) {
63 std::cerr
<< "Found key '" << *arg
<< "'.\n";
66 exit_code
= EXIT_FAILURE
;
67 if (opt
.isset("verbose")) {
68 if (rc
== MEMCACHED_NOTFOUND
) {
69 std::cerr
<< "Could not find key '" << *arg
<< "'.\n";
71 std::cerr
<< "Fatal error for key '" << *arg
<< "': "
72 << memcached_last_error_message(&memc
) << "\n";
78 memcached_free(&memc
);