dcda9ddd72afb30744ac70acd939ac0bad4b84b6
[m6w6/libmemcached] / test / lib / MemcachedCluster.hpp
1 /*
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 +--------------------------------------------------------------------+
14 */
15
16 #pragma once
17
18 #include "common.hpp"
19 #include "Cluster.hpp"
20 #include "ReturnMatcher.hpp"
21
22 class MemcachedCluster {
23 public:
24 using behavior_t = pair<memcached_behavior_t, uint64_t>;
25 using behaviors_t = vector<behavior_t>;
26
27 Cluster cluster;
28 memcached_st memc{empty_memc};
29 ReturnMatcher returns{&memc};
30
31 MemcachedCluster();
32 explicit MemcachedCluster(Cluster &&cluster, behaviors_t to_set = {});
33 ~MemcachedCluster();
34
35 MemcachedCluster(const MemcachedCluster &) = delete;
36 MemcachedCluster &operator=(const MemcachedCluster &) = delete;
37
38 MemcachedCluster(MemcachedCluster &&mc) noexcept;
39 MemcachedCluster &operator=(MemcachedCluster &&mc) noexcept;
40
41 void enableBinaryProto(bool enable = true);
42 void enableBuffering(bool enable = true);
43 void enableReplication();
44 void flush();
45
46 static MemcachedCluster mixed();
47 static MemcachedCluster network();
48 static MemcachedCluster socket();
49 static MemcachedCluster udp();
50
51 #if LIBMEMCACHED_WITH_SASL_SUPPORT
52 static MemcachedCluster sasl();
53 #endif
54
55 void killOneServer() const;
56
57 private:
58 behaviors_t to_set;
59 static const memcached_st empty_memc;
60
61 void init();
62 };