memcached 1.2.6 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. data/CHANGELOG +2 -0
  2. data/Manifest +206 -12
  3. data/Rakefile +32 -1
  4. data/ext/extconf.rb +10 -35
  5. data/ext/libmemcached-0.32/AUTHORS +7 -0
  6. data/ext/libmemcached-0.32/COPYING +32 -0
  7. data/ext/libmemcached-0.32/ChangeLog +303 -0
  8. data/ext/libmemcached-0.32/INSTALL +302 -0
  9. data/ext/libmemcached-0.32/Makefile.am +36 -0
  10. data/ext/libmemcached-0.32/Makefile.in +828 -0
  11. data/ext/libmemcached-0.32/NEWS +1 -0
  12. data/ext/libmemcached-0.32/README +33 -0
  13. data/ext/libmemcached-0.32/THANKS +14 -0
  14. data/ext/libmemcached-0.32/TODO +11 -0
  15. data/ext/libmemcached-0.32/aclocal.m4 +1852 -0
  16. data/ext/libmemcached-0.32/clients/Makefile.am +73 -0
  17. data/ext/libmemcached-0.32/clients/Makefile.in +770 -0
  18. data/ext/libmemcached-0.32/clients/client_options.h +32 -0
  19. data/ext/libmemcached-0.32/clients/execute.c +64 -0
  20. data/ext/libmemcached-0.32/clients/execute.h +5 -0
  21. data/ext/libmemcached-0.32/clients/generator.c +74 -0
  22. data/ext/libmemcached-0.32/clients/generator.h +20 -0
  23. data/ext/libmemcached-0.32/clients/memcat.c +178 -0
  24. data/ext/libmemcached-0.32/clients/memcp.c +251 -0
  25. data/ext/libmemcached-0.32/clients/memdump.c +170 -0
  26. data/ext/libmemcached-0.32/clients/memerror.c +80 -0
  27. data/ext/libmemcached-0.32/clients/memflush.c +143 -0
  28. data/ext/libmemcached-0.32/clients/memrm.c +160 -0
  29. data/ext/libmemcached-0.32/clients/memslap.c +441 -0
  30. data/ext/libmemcached-0.32/clients/memstat.c +326 -0
  31. data/ext/libmemcached-0.32/clients/utilities.c +207 -0
  32. data/ext/libmemcached-0.32/clients/utilities.h +41 -0
  33. data/ext/libmemcached-0.32/config.h.in +252 -0
  34. data/ext/libmemcached-0.32/config/compile +143 -0
  35. data/ext/libmemcached-0.32/config/config.guess +1561 -0
  36. data/ext/libmemcached-0.32/config/config.rpath +666 -0
  37. data/ext/libmemcached-0.32/config/config.sub +1686 -0
  38. data/ext/libmemcached-0.32/config/depcomp +630 -0
  39. data/ext/libmemcached-0.32/config/install-sh +520 -0
  40. data/ext/libmemcached-0.32/config/ltmain.sh +8406 -0
  41. data/ext/libmemcached-0.32/config/missing +376 -0
  42. data/ext/libmemcached-0.32/configure +23048 -0
  43. data/ext/libmemcached-0.32/configure.ac +122 -0
  44. data/ext/libmemcached-0.32/docs/Makefile.am +415 -0
  45. data/ext/libmemcached-0.32/docs/Makefile.in +918 -0
  46. data/ext/libmemcached-0.32/docs/libmemcached.pod +123 -0
  47. data/ext/libmemcached-0.32/docs/libmemcached_examples.pod +115 -0
  48. data/ext/libmemcached-0.32/docs/libmemcachedutil.pod +40 -0
  49. data/ext/libmemcached-0.32/docs/memcached_analyze.pod +52 -0
  50. data/ext/libmemcached-0.32/docs/memcached_auto.pod +97 -0
  51. data/ext/libmemcached-0.32/docs/memcached_behavior.pod +224 -0
  52. data/ext/libmemcached-0.32/docs/memcached_callback.pod +123 -0
  53. data/ext/libmemcached-0.32/docs/memcached_create.pod +61 -0
  54. data/ext/libmemcached-0.32/docs/memcached_delete.pod +54 -0
  55. data/ext/libmemcached-0.32/docs/memcached_dump.pod +53 -0
  56. data/ext/libmemcached-0.32/docs/memcached_flush.pod +46 -0
  57. data/ext/libmemcached-0.32/docs/memcached_flush_buffers.pod +42 -0
  58. data/ext/libmemcached-0.32/docs/memcached_generate_hash_value.pod +57 -0
  59. data/ext/libmemcached-0.32/docs/memcached_get.pod +161 -0
  60. data/ext/libmemcached-0.32/docs/memcached_memory_allocators.pod +73 -0
  61. data/ext/libmemcached-0.32/docs/memcached_pool.pod +77 -0
  62. data/ext/libmemcached-0.32/docs/memcached_quit.pod +47 -0
  63. data/ext/libmemcached-0.32/docs/memcached_sasl.pod +63 -0
  64. data/ext/libmemcached-0.32/docs/memcached_server_st.pod +75 -0
  65. data/ext/libmemcached-0.32/docs/memcached_servers.pod +102 -0
  66. data/ext/libmemcached-0.32/docs/memcached_set.pod +187 -0
  67. data/ext/libmemcached-0.32/docs/memcached_stats.pod +82 -0
  68. data/ext/libmemcached-0.32/docs/memcached_strerror.pod +46 -0
  69. data/ext/libmemcached-0.32/docs/memcached_user_data.pod +49 -0
  70. data/ext/libmemcached-0.32/docs/memcached_verbosity.pod +41 -0
  71. data/ext/libmemcached-0.32/docs/memcached_version.pod +56 -0
  72. data/ext/libmemcached-0.32/docs/memcat.pod +37 -0
  73. data/ext/libmemcached-0.32/docs/memcp.pod +40 -0
  74. data/ext/libmemcached-0.32/docs/memdump.pod +31 -0
  75. data/ext/libmemcached-0.32/docs/memerror.pod +30 -0
  76. data/ext/libmemcached-0.32/docs/memflush.pod +35 -0
  77. data/ext/libmemcached-0.32/docs/memrm.pod +34 -0
  78. data/ext/libmemcached-0.32/docs/memslap.pod +33 -0
  79. data/ext/libmemcached-0.32/docs/memstat.pod +35 -0
  80. data/ext/libmemcached-0.32/libmemcached/Makefile.am +107 -0
  81. data/ext/libmemcached-0.32/libmemcached/Makefile.in +1050 -0
  82. data/ext/libmemcached-0.32/libmemcached/byteorder.c +31 -0
  83. data/ext/libmemcached-0.32/libmemcached/common.h +183 -0
  84. data/ext/libmemcached-0.32/libmemcached/crc.c +86 -0
  85. data/ext/libmemcached-0.32/libmemcached/hsieh_hash.c +68 -0
  86. data/ext/libmemcached-0.32/libmemcached/jenkins_hash.c +213 -0
  87. data/ext/libmemcached-0.32/libmemcached/libmemcached.ver +1 -0
  88. data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.d +28 -0
  89. data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.h +78 -0
  90. data/ext/libmemcached-0.32/libmemcached/md5.c +354 -0
  91. data/ext/libmemcached-0.32/libmemcached/memcached.c +152 -0
  92. data/ext/libmemcached-0.32/libmemcached/memcached.h +302 -0
  93. data/ext/libmemcached-0.32/libmemcached/memcached.hpp +799 -0
  94. data/ext/libmemcached-0.32/libmemcached/memcached/README.txt +7 -0
  95. data/ext/libmemcached-0.32/libmemcached/memcached/protocol_binary.h +366 -0
  96. data/ext/libmemcached-0.32/libmemcached/memcached_allocators.c +72 -0
  97. data/ext/libmemcached-0.32/libmemcached/memcached_analyze.c +100 -0
  98. data/ext/libmemcached-0.32/libmemcached/memcached_auto.c +207 -0
  99. data/ext/libmemcached-0.32/libmemcached/memcached_behavior.c +285 -0
  100. data/ext/libmemcached-0.32/libmemcached/memcached_callback.c +175 -0
  101. data/ext/libmemcached-0.32/libmemcached/memcached_configure.h.in +23 -0
  102. data/ext/libmemcached-0.32/libmemcached/memcached_connect.c +361 -0
  103. data/ext/libmemcached-0.32/libmemcached/memcached_constants.h +145 -0
  104. data/ext/libmemcached-0.32/libmemcached/memcached_delete.c +0 -0
  105. data/ext/libmemcached-0.32/libmemcached/memcached_do.c +34 -0
  106. data/ext/libmemcached-0.32/libmemcached/memcached_dump.c +79 -0
  107. data/ext/libmemcached-0.32/libmemcached/memcached_fetch.c +102 -0
  108. data/ext/libmemcached-0.32/libmemcached/memcached_flush.c +89 -0
  109. data/ext/libmemcached-0.32/libmemcached/memcached_flush_buffers.c +22 -0
  110. data/ext/libmemcached-0.32/libmemcached/memcached_get.c +495 -0
  111. data/ext/libmemcached-0.32/libmemcached/memcached_get.h +87 -0
  112. data/ext/libmemcached-0.32/libmemcached/memcached_hash.c +252 -0
  113. data/ext/libmemcached-0.32/libmemcached/memcached_hosts.c +510 -0
  114. data/ext/libmemcached-0.32/libmemcached/memcached_internal.h +31 -0
  115. data/ext/libmemcached-0.32/libmemcached/memcached_io.c +547 -0
  116. data/ext/libmemcached-0.32/libmemcached/memcached_io.h +59 -0
  117. data/ext/libmemcached-0.32/libmemcached/memcached_key.c +28 -0
  118. data/ext/libmemcached-0.32/libmemcached/memcached_parse.c +74 -0
  119. data/ext/libmemcached-0.32/libmemcached/memcached_pool.h +38 -0
  120. data/ext/libmemcached-0.32/libmemcached/memcached_purge.c +76 -0
  121. data/ext/libmemcached-0.32/libmemcached/memcached_quit.c +75 -0
  122. data/ext/libmemcached-0.32/libmemcached/memcached_response.c +528 -0
  123. data/ext/libmemcached-0.32/libmemcached/memcached_result.c +57 -0
  124. data/ext/libmemcached-0.32/libmemcached/memcached_result.h +59 -0
  125. data/ext/libmemcached-0.32/libmemcached/memcached_sasl.c +225 -0
  126. data/ext/libmemcached-0.32/libmemcached/memcached_sasl.h +44 -0
  127. data/ext/libmemcached-0.32/libmemcached/memcached_server.c +159 -0
  128. data/ext/libmemcached-0.32/libmemcached/memcached_server.h +93 -0
  129. data/ext/libmemcached-0.32/libmemcached/memcached_stats.c +454 -0
  130. data/ext/libmemcached-0.32/libmemcached/memcached_storage.c +514 -0
  131. data/ext/libmemcached-0.32/libmemcached/memcached_storage.h +107 -0
  132. data/ext/libmemcached-0.32/libmemcached/memcached_strerror.c +92 -0
  133. data/ext/libmemcached-0.32/libmemcached/memcached_string.c +138 -0
  134. data/ext/libmemcached-0.32/libmemcached/memcached_string.h +53 -0
  135. data/ext/libmemcached-0.32/libmemcached/memcached_types.h +44 -0
  136. data/ext/libmemcached-0.32/libmemcached/memcached_util.h +15 -0
  137. data/ext/libmemcached-0.32/libmemcached/memcached_verbosity.c +36 -0
  138. data/ext/libmemcached-0.32/libmemcached/memcached_version.c +112 -0
  139. data/ext/libmemcached-0.32/libmemcached/memcached_watchpoint.h +38 -0
  140. data/ext/libmemcached-0.32/libmemcached/murmur_hash.c +76 -0
  141. data/ext/libmemcached-0.32/libmemcached/visibility.h +51 -0
  142. data/ext/libmemcached-0.32/libmemcachedutil/Makefile.am +11 -0
  143. data/ext/libmemcached-0.32/libmemcachedutil/Makefile.in +602 -0
  144. data/ext/libmemcached-0.32/libmemcachedutil/libmemcachedutil.ver +1 -0
  145. data/ext/libmemcached-0.32/libmemcachedutil/memcached_pool.c +170 -0
  146. data/ext/libmemcached-0.32/m4/ac_cxx_compile_stdcxx_0x.m4 +103 -0
  147. data/ext/libmemcached-0.32/m4/ac_cxx_header_stdcxx_98.m4 +67 -0
  148. data/ext/libmemcached-0.32/m4/acx_pthread.m4 +276 -0
  149. data/ext/libmemcached-0.32/m4/byteorder.m4 +40 -0
  150. data/ext/libmemcached-0.32/m4/deprecated.m4 +17 -0
  151. data/ext/libmemcached-0.32/m4/enable_utillib.m4 +16 -0
  152. data/ext/libmemcached-0.32/m4/extensions.m4 +94 -0
  153. data/ext/libmemcached-0.32/m4/hsieh.m4 +18 -0
  154. data/ext/libmemcached-0.32/m4/lib-prefix.m4 +221 -0
  155. data/ext/libmemcached-0.32/m4/libtool.m4 +7360 -0
  156. data/ext/libmemcached-0.32/m4/ltoptions.m4 +368 -0
  157. data/ext/libmemcached-0.32/m4/ltsugar.m4 +123 -0
  158. data/ext/libmemcached-0.32/m4/ltversion.m4 +23 -0
  159. data/ext/libmemcached-0.32/m4/lt~obsolete.m4 +92 -0
  160. data/ext/libmemcached-0.32/m4/memcached.m4 +30 -0
  161. data/ext/libmemcached-0.32/m4/pandora_64bit.m4 +55 -0
  162. data/ext/libmemcached-0.32/m4/pandora_canonical.m4 +151 -0
  163. data/ext/libmemcached-0.32/m4/pandora_check_compiler_version.m4 +37 -0
  164. data/ext/libmemcached-0.32/m4/pandora_check_cxx_standard.m4 +16 -0
  165. data/ext/libmemcached-0.32/m4/pandora_enable_dtrace.m4 +41 -0
  166. data/ext/libmemcached-0.32/m4/pandora_ensure_gcc_version.m4 +36 -0
  167. data/ext/libmemcached-0.32/m4/pandora_have_better_malloc.m4 +54 -0
  168. data/ext/libmemcached-0.32/m4/pandora_have_sasl.m4 +133 -0
  169. data/ext/libmemcached-0.32/m4/pandora_header_assert.m4 +23 -0
  170. data/ext/libmemcached-0.32/m4/pandora_libtool.m4 +15 -0
  171. data/ext/libmemcached-0.32/m4/pandora_optimize.m4 +79 -0
  172. data/ext/libmemcached-0.32/m4/pandora_shared_ptr.m4 +56 -0
  173. data/ext/libmemcached-0.32/m4/pandora_vc_build.m4 +32 -0
  174. data/ext/libmemcached-0.32/m4/pandora_warnings.m4 +262 -0
  175. data/ext/libmemcached-0.32/m4/pod2man.m4 +7 -0
  176. data/ext/libmemcached-0.32/m4/protocol_binary.m4 +23 -0
  177. data/ext/libmemcached-0.32/m4/setsockopt.m4 +57 -0
  178. data/ext/libmemcached-0.32/m4/visibility.m4 +52 -0
  179. data/ext/libmemcached-0.32/support/Makefile.am +4 -0
  180. data/ext/libmemcached-0.32/support/Makefile.in +485 -0
  181. data/ext/libmemcached-0.32/support/libmemcached-fc.spec.in +105 -0
  182. data/ext/libmemcached-0.32/support/libmemcached.pc.in +10 -0
  183. data/ext/libmemcached-0.32/support/libmemcached.spec +105 -0
  184. data/ext/libmemcached-0.32/support/libmemcached.spec.in +105 -0
  185. data/ext/libmemcached-0.32/support/set_benchmark.sh +5 -0
  186. data/ext/libmemcached-0.32/tests/Makefile.am +105 -0
  187. data/ext/libmemcached-0.32/tests/Makefile.in +748 -0
  188. data/ext/libmemcached-0.32/tests/atomsmasher.c +245 -0
  189. data/ext/libmemcached-0.32/tests/function.c +4781 -0
  190. data/ext/libmemcached-0.32/tests/ketama_test_cases.h +108 -0
  191. data/ext/libmemcached-0.32/tests/output.cmp +7 -0
  192. data/ext/libmemcached-0.32/tests/output.res +7 -0
  193. data/ext/libmemcached-0.32/tests/output2.res +46 -0
  194. data/ext/libmemcached-0.32/tests/plus.cpp +293 -0
  195. data/ext/libmemcached-0.32/tests/r/memcat.res +19 -0
  196. data/ext/libmemcached-0.32/tests/r/memcp.res +27 -0
  197. data/ext/libmemcached-0.32/tests/r/memrm.res +19 -0
  198. data/ext/libmemcached-0.32/tests/r/memslap.res +33 -0
  199. data/ext/libmemcached-0.32/tests/r/memstat.res +33 -0
  200. data/ext/libmemcached-0.32/tests/server.c +118 -0
  201. data/ext/libmemcached-0.32/tests/server.h +25 -0
  202. data/ext/libmemcached-0.32/tests/start.c +16 -0
  203. data/ext/libmemcached-0.32/tests/t/memcat.test +4 -0
  204. data/ext/libmemcached-0.32/tests/t/memcp.test +3 -0
  205. data/ext/libmemcached-0.32/tests/t/memrm.test +3 -0
  206. data/ext/libmemcached-0.32/tests/t/memslap.test +5 -0
  207. data/ext/libmemcached-0.32/tests/t/memstat.test +3 -0
  208. data/ext/libmemcached-0.32/tests/test.c +137 -0
  209. data/ext/libmemcached-0.32/tests/test.h +46 -0
  210. data/ext/libmemcached-0.32/tests/udp.c +76 -0
  211. data/memcached.gemspec +4 -4
  212. data/test/unit/memcached_test.rb +30 -0
  213. metadata +213 -16
  214. data/ext/libmemcached-0.32.tar.gz +0 -0
  215. data/ext/libmemcached-1.patch +0 -270
  216. data/ext/libmemcached-10.patch +0 -12
  217. data/ext/libmemcached-2.patch +0 -116
  218. data/ext/libmemcached-3.patch +0 -8
  219. data/ext/libmemcached-4.patch +0 -40
  220. data/ext/libmemcached-5.patch +0 -832
  221. data/ext/libmemcached-6.patch +0 -20
  222. data/ext/libmemcached-7.patch +0 -2989
  223. data/ext/libmemcached-8.patch +0 -137
  224. data/ext/libmemcached-9.patch +0 -13
  225. data/ext/sasl.patch +0 -29283
@@ -0,0 +1,799 @@
1
+ /*
2
+ * Summary: C++ interface for memcached server
3
+ *
4
+ * Copy: See Copyright for the status of this software.
5
+ *
6
+ * Authors: Padraig O'Sullivan <osullivan.padraig@gmail.com>
7
+ * Patrick Galbraith <patg@patg.net>
8
+ */
9
+
10
+ /**
11
+ * @file memcached.hpp
12
+ * @brief Libmemcached C++ interface
13
+ */
14
+
15
+ #ifndef LIBMEMCACHEDPP_H
16
+ #define LIBMEMCACHEDPP_H
17
+
18
+ #include <libmemcached/memcached.h>
19
+
20
+ #include <string.h>
21
+
22
+ #include <string>
23
+ #include <vector>
24
+ #include <map>
25
+
26
+ namespace memcache
27
+ {
28
+
29
+ /**
30
+ * This is the core memcached library (if later, other objects
31
+ * are needed, they will be created from this class).
32
+ */
33
+ class Memcache
34
+ {
35
+ public:
36
+
37
+ Memcache()
38
+ :
39
+ memc(),
40
+ result()
41
+ {
42
+ memcached_create(&memc);
43
+ }
44
+
45
+ Memcache(memcached_st *clone)
46
+ :
47
+ memc(),
48
+ result()
49
+ {
50
+ memcached_clone(&memc, clone);
51
+ }
52
+
53
+ Memcache(const Memcache &rhs)
54
+ :
55
+ memc(),
56
+ result()
57
+ {
58
+ memcached_clone(&memc, const_cast<memcached_st *>(&rhs.getImpl()));
59
+ }
60
+
61
+ ~Memcache()
62
+ {
63
+ memcached_free(&memc);
64
+ }
65
+
66
+ /**
67
+ * Get the internal memcached_st *
68
+ */
69
+ memcached_st &getImpl()
70
+ {
71
+ return memc;
72
+ }
73
+
74
+ /**
75
+ * Get the internal memcached_st *
76
+ */
77
+ const memcached_st &getImpl() const
78
+ {
79
+ return memc;
80
+ }
81
+
82
+ /**
83
+ * Return an error string for the given return structure.
84
+ *
85
+ * @param[in] rc a memcached_return structure
86
+ * @return error string corresponding to given return code in the library.
87
+ */
88
+ const std::string getError(memcached_return rc) const
89
+ {
90
+ /* first parameter to strerror is unused */
91
+ return memcached_strerror(NULL, rc);
92
+ }
93
+
94
+ /**
95
+ * Fetches an individual value from the server. mget() must always
96
+ * be called before using this method.
97
+ *
98
+ * @param[in] key key of object to fetch
99
+ * @param[out] ret_val store returned object in this vector
100
+ * @return a memcached return structure
101
+ */
102
+ memcached_return fetch(std::string &key,
103
+ std::vector<char> &ret_val)
104
+ {
105
+ char ret_key[MEMCACHED_MAX_KEY];
106
+ size_t value_length= 0;
107
+ size_t key_length= 0;
108
+ memcached_return rc;
109
+ uint32_t flags= 0;
110
+ char *value= memcached_fetch(&memc, ret_key, &key_length,
111
+ &value_length, &flags, &rc);
112
+ if (value && ret_val.empty())
113
+ {
114
+ ret_val.reserve(value_length);
115
+ ret_val.assign(value, value + value_length);
116
+ key.assign(ret_key);
117
+ }
118
+ return rc;
119
+ }
120
+
121
+ /**
122
+ * Fetches an individual value from the server.
123
+ *
124
+ * @param[in] key key of object whose value to get
125
+ * @param[out] ret_val object that is retrieved is stored in
126
+ * this vector
127
+ * @return true on success; false otherwise
128
+ */
129
+ bool get(const std::string &key,
130
+ std::vector<char> &ret_val)
131
+ {
132
+ uint32_t flags= 0;
133
+ memcached_return rc;
134
+ size_t value_length= 0;
135
+
136
+ if (key.empty())
137
+ {
138
+ return false;
139
+ }
140
+ char *value= memcached_get(&memc, key.c_str(), key.length(),
141
+ &value_length, &flags, &rc);
142
+ if (value != NULL && ret_val.empty())
143
+ {
144
+ ret_val.reserve(value_length);
145
+ ret_val.assign(value, value + value_length);
146
+ return true;
147
+ }
148
+ return false;
149
+ }
150
+
151
+ /**
152
+ * Fetches an individual from a server which is specified by
153
+ * the master_key parameter that is used for determining which
154
+ * server an object was stored in if key partitioning was
155
+ * used for storage.
156
+ *
157
+ * @param[in] master_key key that specifies server object is stored on
158
+ * @param[in] key key of object whose value to get
159
+ * @param[out] ret_val object that is retrieved is stored in
160
+ * this vector
161
+ * @return true on success; false otherwise
162
+ */
163
+ bool getByKey(const std::string &master_key,
164
+ const std::string &key,
165
+ std::vector<char> &ret_val)
166
+ {
167
+ uint32_t flags= 0;
168
+ memcached_return rc;
169
+ size_t value_length= 0;
170
+
171
+ if (master_key.empty() || key.empty())
172
+ {
173
+ return false;
174
+ }
175
+ char *value= memcached_get_by_key(&memc,
176
+ master_key.c_str(), master_key.length(),
177
+ key.c_str(), key.length(),
178
+ GET_LEN_ARG_UNSPECIFIED,
179
+ &value_length, &flags, &rc);
180
+ if (value)
181
+ {
182
+ ret_val.reserve(value_length);
183
+ ret_val.assign(value, value + value_length);
184
+ return true;
185
+ }
186
+ return false;
187
+ }
188
+
189
+ /**
190
+ * Selects multiple keys at once. This method always
191
+ * works asynchronously.
192
+ *
193
+ * @param[in] keys vector of keys to select
194
+ * @return true if all keys are found
195
+ */
196
+ bool mget(std::vector<std::string> &keys)
197
+ {
198
+ std::vector<const char *> real_keys;
199
+ std::vector<size_t> key_len;
200
+ /*
201
+ * Construct an array which will contain the length
202
+ * of each of the strings in the input vector. Also, to
203
+ * interface with the memcached C API, we need to convert
204
+ * the vector of std::string's to a vector of char *.
205
+ */
206
+ real_keys.reserve(keys.size());
207
+ key_len.reserve(keys.size());
208
+
209
+ std::vector<std::string>::iterator it= keys.begin();
210
+
211
+ while (it != keys.end())
212
+ {
213
+ real_keys.push_back(const_cast<char *>((*it).c_str()));
214
+ key_len.push_back((*it).length());
215
+ ++it;
216
+ }
217
+
218
+ /*
219
+ * If the std::vector of keys is empty then we cannot
220
+ * call memcached_mget as we will get undefined behavior.
221
+ */
222
+ if (! real_keys.empty())
223
+ {
224
+ memcached_return rc= memcached_mget(&memc, &real_keys[0], &key_len[0],
225
+ real_keys.size());
226
+ return (rc == MEMCACHED_SUCCESS);
227
+ }
228
+
229
+ return false;
230
+ }
231
+
232
+ /**
233
+ * Writes an object to the server. If the object already exists, it will
234
+ * overwrite the existing object. This method always returns true
235
+ * when using non-blocking mode unless a network error occurs.
236
+ *
237
+ * @param[in] key key of object to write to server
238
+ * @param[in] value value of object to write to server
239
+ * @param[in] expiration time to keep the object stored in the server for
240
+ * @param[in] flags flags to store with the object
241
+ * @return true on succcess; false otherwise
242
+ */
243
+ bool set(const std::string &key,
244
+ const std::vector<char> &value,
245
+ time_t expiration,
246
+ uint32_t flags)
247
+ {
248
+ if (key.empty() || value.empty())
249
+ {
250
+ return false;
251
+ }
252
+ memcached_return rc= memcached_set(&memc,
253
+ key.c_str(), key.length(),
254
+ &value[0], value.size(),
255
+ expiration, flags);
256
+ return (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
257
+ }
258
+
259
+ /**
260
+ * Writes an object to a server specified by the master_key parameter.
261
+ * If the object already exists, it will overwrite the existing object.
262
+ *
263
+ * @param[in] master_key key that specifies server to write to
264
+ * @param[in] key key of object to write to server
265
+ * @param[in] value value of object to write to server
266
+ * @param[in] expiration time to keep the object stored in the server for
267
+ * @param[in] flags flags to store with the object
268
+ * @return true on succcess; false otherwise
269
+ */
270
+ bool setByKey(const std::string &master_key,
271
+ const std::string &key,
272
+ const std::vector<char> &value,
273
+ time_t expiration,
274
+ uint32_t flags)
275
+ {
276
+ if (master_key.empty() ||
277
+ key.empty() ||
278
+ value.empty())
279
+ {
280
+ return false;
281
+ }
282
+ memcached_return rc= memcached_set_by_key(&memc, master_key.c_str(),
283
+ master_key.length(),
284
+ key.c_str(), key.length(),
285
+ &value[0], value.size(),
286
+ expiration,
287
+ flags);
288
+ return (rc == MEMCACHED_SUCCESS);
289
+ }
290
+
291
+ /**
292
+ * Writes a list of objects to the server. Objects are specified by
293
+ * 2 vectors - 1 vector of keys and 1 vector of values.
294
+ *
295
+ * @param[in] keys vector of keys of objects to write to server
296
+ * @param[in] values vector of values of objects to write to server
297
+ * @param[in] expiration time to keep the objects stored in server for
298
+ * @param[in] flags flags to store with the objects
299
+ * @return true on success; false otherwise
300
+ */
301
+ bool setAll(std::vector<std::string> &keys,
302
+ std::vector< std::vector<char> *> &values,
303
+ time_t expiration,
304
+ uint32_t flags)
305
+ {
306
+ if (keys.size() != values.size())
307
+ {
308
+ return false;
309
+ }
310
+ bool retval= true;
311
+ std::vector<std::string>::iterator key_it= keys.begin();
312
+ std::vector< std::vector<char> *>::iterator val_it= values.begin();
313
+ while (key_it != keys.end())
314
+ {
315
+ retval= set((*key_it), *(*val_it), expiration, flags);
316
+ if (retval == false)
317
+ {
318
+ return retval;
319
+ }
320
+ ++key_it;
321
+ ++val_it;
322
+ }
323
+ return retval;
324
+ }
325
+
326
+ /**
327
+ * Writes a list of objects to the server. Objects are specified by
328
+ * a map of keys to values.
329
+ *
330
+ * @param[in] key_value_map map of keys and values to store in server
331
+ * @param[in] expiration time to keep the objects stored in server for
332
+ * @param[in] flags flags to store with the objects
333
+ * @return true on success; false otherwise
334
+ */
335
+ bool setAll(std::map<const std::string, std::vector<char> > &key_value_map,
336
+ time_t expiration,
337
+ uint32_t flags)
338
+ {
339
+ if (key_value_map.empty())
340
+ {
341
+ return false;
342
+ }
343
+ bool retval= true;
344
+ std::map<const std::string, std::vector<char> >::iterator it=
345
+ key_value_map.begin();
346
+ while (it != key_value_map.end())
347
+ {
348
+ retval= set(it->first, it->second, expiration, flags);
349
+ if (retval == false)
350
+ {
351
+ return false;
352
+ }
353
+ ++it;
354
+ }
355
+ return true;
356
+ }
357
+
358
+ /**
359
+ * Increment the value of the object associated with the specified
360
+ * key by the offset given. The resulting value is saved in the value
361
+ * parameter.
362
+ *
363
+ * @param[in] key key of object in server whose value to increment
364
+ * @param[in] offset amount to increment object's value by
365
+ * @param[out] value store the result of the increment here
366
+ * @return true on success; false otherwise
367
+ */
368
+ bool increment(const std::string &key, uint32_t offset, uint64_t *value)
369
+ {
370
+ if (key.empty())
371
+ {
372
+ return false;
373
+ }
374
+ memcached_return rc= memcached_increment(&memc, key.c_str(), key.length(),
375
+ offset, value);
376
+ return (rc == MEMCACHED_SUCCESS);
377
+ }
378
+
379
+ /**
380
+ * Decrement the value of the object associated with the specified
381
+ * key by the offset given. The resulting value is saved in the value
382
+ * parameter.
383
+ *
384
+ * @param[in] key key of object in server whose value to decrement
385
+ * @param[in] offset amount to increment object's value by
386
+ * @param[out] value store the result of the decrement here
387
+ * @return true on success; false otherwise
388
+ */
389
+ bool decrement(const std::string &key, uint32_t offset, uint64_t *value)
390
+ {
391
+ if (key.empty())
392
+ {
393
+ return false;
394
+ }
395
+ memcached_return rc= memcached_decrement(&memc, key.c_str(),
396
+ key.length(),
397
+ offset, value);
398
+ return (rc == MEMCACHED_SUCCESS);
399
+ }
400
+
401
+
402
+ /**
403
+ * Add an object with the specified key and value to the server. This
404
+ * function returns false if the object already exists on the server.
405
+ *
406
+ * @param[in] key key of object to add
407
+ * @param[in] value of object to add
408
+ * @return true on success; false otherwise
409
+ */
410
+ bool add(const std::string &key, const std::vector<char> &value)
411
+ {
412
+ if (key.empty() || value.empty())
413
+ {
414
+ return false;
415
+ }
416
+ memcached_return rc= memcached_add(&memc, key.c_str(), key.length(),
417
+ &value[0], value.size(), 0, 0);
418
+ return (rc == MEMCACHED_SUCCESS);
419
+ }
420
+
421
+ /**
422
+ * Add an object with the specified key and value to the server. This
423
+ * function returns false if the object already exists on the server. The
424
+ * server to add the object to is specified by the master_key parameter.
425
+ *
426
+ * @param[in[ master_key key of server to add object to
427
+ * @param[in] key key of object to add
428
+ * @param[in] value of object to add
429
+ * @return true on success; false otherwise
430
+ */
431
+ bool addByKey(const std::string &master_key,
432
+ const std::string &key,
433
+ const std::vector<char> &value)
434
+ {
435
+ if (master_key.empty() ||
436
+ key.empty() ||
437
+ value.empty())
438
+ {
439
+ return false;
440
+ }
441
+ memcached_return rc= memcached_add_by_key(&memc,
442
+ master_key.c_str(),
443
+ master_key.length(),
444
+ key.c_str(),
445
+ key.length(),
446
+ &value[0],
447
+ value.size(),
448
+ 0, 0);
449
+ return (rc == MEMCACHED_SUCCESS);
450
+ }
451
+
452
+ /**
453
+ * Replaces an object on the server. This method only succeeds
454
+ * if the object is already present on the server.
455
+ *
456
+ * @param[in] key key of object to replace
457
+ * @param[in[ value value to replace object with
458
+ * @return true on success; false otherwise
459
+ */
460
+ bool replace(const std::string &key, const std::vector<char> &value)
461
+ {
462
+ if (key.empty() ||
463
+ value.empty())
464
+ {
465
+ return false;
466
+ }
467
+ memcached_return rc= memcached_replace(&memc, key.c_str(), key.length(),
468
+ &value[0], value.size(),
469
+ 0, 0);
470
+ return (rc == MEMCACHED_SUCCESS);
471
+ }
472
+
473
+ /**
474
+ * Replaces an object on the server. This method only succeeds
475
+ * if the object is already present on the server. The server
476
+ * to replace the object on is specified by the master_key param.
477
+ *
478
+ * @param[in] master_key key of server to replace object on
479
+ * @param[in] key key of object to replace
480
+ * @param[in[ value value to replace object with
481
+ * @return true on success; false otherwise
482
+ */
483
+ bool replaceByKey(const std::string &master_key,
484
+ const std::string &key,
485
+ const std::vector<char> &value)
486
+ {
487
+ if (master_key.empty() ||
488
+ key.empty() ||
489
+ value.empty())
490
+ {
491
+ return false;
492
+ }
493
+ memcached_return rc= memcached_replace_by_key(&memc,
494
+ master_key.c_str(),
495
+ master_key.length(),
496
+ key.c_str(),
497
+ key.length(),
498
+ &value[0],
499
+ value.size(),
500
+ 0, 0);
501
+ return (rc == MEMCACHED_SUCCESS);
502
+ }
503
+
504
+ /**
505
+ * Places a segment of data before the last piece of data stored.
506
+ *
507
+ * @param[in] key key of object whose value we will prepend data to
508
+ * @param[in] value data to prepend to object's value
509
+ * @return true on success; false otherwise
510
+ */
511
+ bool prepend(const std::string &key, const std::vector<char> &value)
512
+ {
513
+ if (key.empty() || value.empty())
514
+ {
515
+ return false;
516
+ }
517
+ memcached_return rc= memcached_prepend(&memc, key.c_str(), key.length(),
518
+ &value[0], value.size(), 0, 0);
519
+ return (rc == MEMCACHED_SUCCESS);
520
+ }
521
+
522
+ /**
523
+ * Places a segment of data before the last piece of data stored. The
524
+ * server on which the object where we will be prepending data is stored
525
+ * on is specified by the master_key parameter.
526
+ *
527
+ * @param[in] master_key key of server where object is stored
528
+ * @param[in] key key of object whose value we will prepend data to
529
+ * @param[in] value data to prepend to object's value
530
+ * @return true on success; false otherwise
531
+ */
532
+ bool prependByKey(const std::string &master_key,
533
+ const std::string &key,
534
+ const std::vector<char> &value)
535
+ {
536
+ if (master_key.empty() ||
537
+ key.empty() ||
538
+ value.empty())
539
+ {
540
+ return false;
541
+ }
542
+ memcached_return rc= memcached_prepend_by_key(&memc,
543
+ master_key.c_str(),
544
+ master_key.length(),
545
+ key.c_str(),
546
+ key.length(),
547
+ &value[0],
548
+ value.size(),
549
+ 0,
550
+ 0);
551
+ return (rc == MEMCACHED_SUCCESS);
552
+ }
553
+
554
+ /**
555
+ * Places a segment of data at the end of the last piece of data stored.
556
+ *
557
+ * @param[in] key key of object whose value we will append data to
558
+ * @param[in] value data to append to object's value
559
+ * @return true on success; false otherwise
560
+ */
561
+ bool append(const std::string &key, const std::vector<char> &value)
562
+ {
563
+ if (key.empty() || value.empty())
564
+ {
565
+ return false;
566
+ }
567
+ memcached_return rc= memcached_append(&memc,
568
+ key.c_str(),
569
+ key.length(),
570
+ &value[0],
571
+ value.size(),
572
+ 0, 0);
573
+ return (rc == MEMCACHED_SUCCESS);
574
+ }
575
+
576
+ /**
577
+ * Places a segment of data at the end of the last piece of data stored. The
578
+ * server on which the object where we will be appending data is stored
579
+ * on is specified by the master_key parameter.
580
+ *
581
+ * @param[in] master_key key of server where object is stored
582
+ * @param[in] key key of object whose value we will append data to
583
+ * @param[in] value data to append to object's value
584
+ * @return true on success; false otherwise
585
+ */
586
+ bool appendByKey(const std::string &master_key,
587
+ const std::string &key,
588
+ const std::vector<char> &value)
589
+ {
590
+ if (master_key.empty() ||
591
+ key.empty() ||
592
+ value.empty())
593
+ {
594
+ return false;
595
+ }
596
+ memcached_return rc= memcached_append_by_key(&memc,
597
+ master_key.c_str(),
598
+ master_key.length(),
599
+ key.c_str(),
600
+ key.length(),
601
+ &value[0],
602
+ value.size(),
603
+ 0, 0);
604
+ return (rc == MEMCACHED_SUCCESS);
605
+ }
606
+
607
+ /**
608
+ * Overwrite data in the server as long as the cas_arg value
609
+ * is still the same in the server.
610
+ *
611
+ * @param[in] key key of object in server
612
+ * @param[in] value value to store for object in server
613
+ * @param[in] cas_arg "cas" value
614
+ */
615
+ bool cas(const std::string &key,
616
+ const std::vector<char> &value,
617
+ uint64_t cas_arg)
618
+ {
619
+ if (key.empty() || value.empty())
620
+ {
621
+ return false;
622
+ }
623
+ memcached_return rc= memcached_cas(&memc, key.c_str(), key.length(),
624
+ &value[0], value.size(),
625
+ 0, 0, cas_arg);
626
+ return (rc == MEMCACHED_SUCCESS);
627
+ }
628
+
629
+ /**
630
+ * Overwrite data in the server as long as the cas_arg value
631
+ * is still the same in the server. The server to use is
632
+ * specified by the master_key parameter.
633
+ *
634
+ * @param[in] master_key specifies server to operate on
635
+ * @param[in] key key of object in server
636
+ * @param[in] value value to store for object in server
637
+ * @param[in] cas_arg "cas" value
638
+ */
639
+ bool casByKey(const std::string &master_key,
640
+ const std::string &key,
641
+ const std::vector<char> &value,
642
+ uint64_t cas_arg)
643
+ {
644
+ if (master_key.empty() ||
645
+ key.empty() ||
646
+ value.empty())
647
+ {
648
+ return false;
649
+ }
650
+ memcached_return rc= memcached_cas_by_key(&memc,
651
+ master_key.c_str(),
652
+ master_key.length(),
653
+ key.c_str(),
654
+ key.length(),
655
+ &value[0],
656
+ value.size(),
657
+ 0, 0, cas_arg);
658
+ return (rc == MEMCACHED_SUCCESS);
659
+ }
660
+
661
+ /**
662
+ * Delete an object from the server specified by the key given.
663
+ *
664
+ * @param[in] key key of object to delete
665
+ * @return true on success; false otherwise
666
+ */
667
+ bool remove(const std::string &key)
668
+ {
669
+ if (key.empty())
670
+ {
671
+ return false;
672
+ }
673
+ memcached_return rc= memcached_delete(&memc, key.c_str(), key.length(), 0);
674
+ return (rc == MEMCACHED_SUCCESS);
675
+ }
676
+
677
+ /**
678
+ * Delete an object from the server specified by the key given.
679
+ *
680
+ * @param[in] key key of object to delete
681
+ * @param[in] expiration time to delete the object after
682
+ * @return true on success; false otherwise
683
+ */
684
+ bool remove(const std::string &key,
685
+ time_t expiration)
686
+ {
687
+ if (key.empty())
688
+ {
689
+ return false;
690
+ }
691
+ memcached_return rc= memcached_delete(&memc,
692
+ key.c_str(),
693
+ key.length(),
694
+ expiration);
695
+ return (rc == MEMCACHED_SUCCESS);
696
+ }
697
+
698
+ /**
699
+ * Delete an object from the server specified by the key given.
700
+ *
701
+ * @param[in] master_key specifies server to remove object from
702
+ * @param[in] key key of object to delete
703
+ * @return true on success; false otherwise
704
+ */
705
+ bool removeByKey(const std::string &master_key,
706
+ const std::string &key)
707
+ {
708
+ if (master_key.empty() || key.empty())
709
+ {
710
+ return false;
711
+ }
712
+ memcached_return rc= memcached_delete_by_key(&memc,
713
+ master_key.c_str(),
714
+ master_key.length(),
715
+ key.c_str(),
716
+ key.length(),
717
+ 0);
718
+ return (rc == MEMCACHED_SUCCESS);
719
+ }
720
+
721
+ /**
722
+ * Delete an object from the server specified by the key given.
723
+ *
724
+ * @param[in] master_key specifies server to remove object from
725
+ * @param[in] key key of object to delete
726
+ * @param[in] expiration time to delete the object after
727
+ * @return true on success; false otherwise
728
+ */
729
+ bool removeByKey(const std::string &master_key,
730
+ const std::string &key,
731
+ time_t expiration)
732
+ {
733
+ if (master_key.empty() || key.empty())
734
+ {
735
+ return false;
736
+ }
737
+ memcached_return rc= memcached_delete_by_key(&memc,
738
+ master_key.c_str(),
739
+ master_key.length(),
740
+ key.c_str(),
741
+ key.length(),
742
+ expiration);
743
+ return (rc == MEMCACHED_SUCCESS);
744
+ }
745
+
746
+ /**
747
+ * Wipe the contents of memcached servers.
748
+ *
749
+ * @param[in] expiration time to wait until wiping contents of
750
+ * memcached servers
751
+ * @return true on success; false otherwise
752
+ */
753
+ bool flush(time_t expiration)
754
+ {
755
+ memcached_return rc= memcached_flush(&memc, expiration);
756
+ return (rc == MEMCACHED_SUCCESS);
757
+ }
758
+
759
+ /**
760
+ * Callback function for result sets. It passes the result
761
+ * sets to the list of functions provided.
762
+ *
763
+ * @param[in] callback list of callback functions
764
+ * @param[in] context pointer to memory reference that is
765
+ * supplied to the calling function
766
+ * @param[in] num_of_callbacks number of callback functions
767
+ * @return true on success; false otherwise
768
+ */
769
+ bool fetchExecute(memcached_execute_function *callback,
770
+ void *context,
771
+ unsigned int num_of_callbacks)
772
+ {
773
+ memcached_return rc= memcached_fetch_execute(&memc,
774
+ callback,
775
+ context,
776
+ num_of_callbacks);
777
+ return (rc == MEMCACHED_SUCCESS);
778
+ }
779
+
780
+ /**
781
+ * Get the library version string.
782
+ * @return std::string containing a copy of the library version string.
783
+ */
784
+ const std::string libVersion() const
785
+ {
786
+ const char *ver= memcached_lib_version();
787
+ const std::string version(ver);
788
+ return version;
789
+ }
790
+
791
+ private:
792
+
793
+ memcached_st memc;
794
+ memcached_result_st result;
795
+ };
796
+
797
+ }
798
+
799
+ #endif /* LIBMEMCACHEDPP_H */