vinted-memcached 1.8.0

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 (210) hide show
  1. checksums.yaml +7 -0
  2. data/BENCHMARKS +142 -0
  3. data/CHANGELOG +176 -0
  4. data/Gemfile +11 -0
  5. data/Gemfile.lock +45 -0
  6. data/LICENSE +184 -0
  7. data/Manifest +209 -0
  8. data/README.rdoc +124 -0
  9. data/Rakefile +134 -0
  10. data/TODO +1 -0
  11. data/ext/extconf-make.rb +25 -0
  12. data/ext/extconf.rb +78 -0
  13. data/ext/libmemcached-0.32/AUTHORS +7 -0
  14. data/ext/libmemcached-0.32/COPYING +32 -0
  15. data/ext/libmemcached-0.32/ChangeLog +303 -0
  16. data/ext/libmemcached-0.32/INSTALL +302 -0
  17. data/ext/libmemcached-0.32/Makefile.am +36 -0
  18. data/ext/libmemcached-0.32/Makefile.in +911 -0
  19. data/ext/libmemcached-0.32/NEWS +1 -0
  20. data/ext/libmemcached-0.32/README +33 -0
  21. data/ext/libmemcached-0.32/THANKS +14 -0
  22. data/ext/libmemcached-0.32/TODO +11 -0
  23. data/ext/libmemcached-0.32/aclocal.m4 +2108 -0
  24. data/ext/libmemcached-0.32/clients/Makefile.am +80 -0
  25. data/ext/libmemcached-0.32/clients/Makefile.in +773 -0
  26. data/ext/libmemcached-0.32/clients/client_options.h +32 -0
  27. data/ext/libmemcached-0.32/clients/execute.c +64 -0
  28. data/ext/libmemcached-0.32/clients/execute.h +5 -0
  29. data/ext/libmemcached-0.32/clients/generator.c +74 -0
  30. data/ext/libmemcached-0.32/clients/generator.h +20 -0
  31. data/ext/libmemcached-0.32/clients/memcat.c +178 -0
  32. data/ext/libmemcached-0.32/clients/memcp.c +251 -0
  33. data/ext/libmemcached-0.32/clients/memdump.c +170 -0
  34. data/ext/libmemcached-0.32/clients/memerror.c +80 -0
  35. data/ext/libmemcached-0.32/clients/memflush.c +143 -0
  36. data/ext/libmemcached-0.32/clients/memrm.c +160 -0
  37. data/ext/libmemcached-0.32/clients/memslap.c +441 -0
  38. data/ext/libmemcached-0.32/clients/memstat.c +326 -0
  39. data/ext/libmemcached-0.32/clients/utilities.c +207 -0
  40. data/ext/libmemcached-0.32/clients/utilities.h +41 -0
  41. data/ext/libmemcached-0.32/config/compile +143 -0
  42. data/ext/libmemcached-0.32/config/config.guess +1561 -0
  43. data/ext/libmemcached-0.32/config/config.rpath +666 -0
  44. data/ext/libmemcached-0.32/config/config.sub +1686 -0
  45. data/ext/libmemcached-0.32/config/depcomp +630 -0
  46. data/ext/libmemcached-0.32/config/install-sh +520 -0
  47. data/ext/libmemcached-0.32/config/ltmain.sh +9636 -0
  48. data/ext/libmemcached-0.32/config/missing +376 -0
  49. data/ext/libmemcached-0.32/config.h.in +254 -0
  50. data/ext/libmemcached-0.32/configure +23843 -0
  51. data/ext/libmemcached-0.32/configure.ac +120 -0
  52. data/ext/libmemcached-0.32/libmemcached/Makefile.am +111 -0
  53. data/ext/libmemcached-0.32/libmemcached/Makefile.in +1069 -0
  54. data/ext/libmemcached-0.32/libmemcached/byteorder.c +31 -0
  55. data/ext/libmemcached-0.32/libmemcached/common.h +189 -0
  56. data/ext/libmemcached-0.32/libmemcached/crc.c +86 -0
  57. data/ext/libmemcached-0.32/libmemcached/hsieh_hash.c +68 -0
  58. data/ext/libmemcached-0.32/libmemcached/jenkins_hash.c +213 -0
  59. data/ext/libmemcached-0.32/libmemcached/libmemcached.ver +1 -0
  60. data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.d +30 -0
  61. data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.h +82 -0
  62. data/ext/libmemcached-0.32/libmemcached/md5.c +354 -0
  63. data/ext/libmemcached-0.32/libmemcached/memcached/README.txt +7 -0
  64. data/ext/libmemcached-0.32/libmemcached/memcached/protocol_binary.h +385 -0
  65. data/ext/libmemcached-0.32/libmemcached/memcached.c +153 -0
  66. data/ext/libmemcached-0.32/libmemcached/memcached.h +305 -0
  67. data/ext/libmemcached-0.32/libmemcached/memcached.hpp +799 -0
  68. data/ext/libmemcached-0.32/libmemcached/memcached_allocators.c +72 -0
  69. data/ext/libmemcached-0.32/libmemcached/memcached_analyze.c +100 -0
  70. data/ext/libmemcached-0.32/libmemcached/memcached_auto.c +207 -0
  71. data/ext/libmemcached-0.32/libmemcached/memcached_behavior.c +290 -0
  72. data/ext/libmemcached-0.32/libmemcached/memcached_callback.c +175 -0
  73. data/ext/libmemcached-0.32/libmemcached/memcached_configure.h.in +23 -0
  74. data/ext/libmemcached-0.32/libmemcached/memcached_connect.c +371 -0
  75. data/ext/libmemcached-0.32/libmemcached/memcached_constants.h +146 -0
  76. data/ext/libmemcached-0.32/libmemcached/memcached_delete.c +0 -0
  77. data/ext/libmemcached-0.32/libmemcached/memcached_do.c +72 -0
  78. data/ext/libmemcached-0.32/libmemcached/memcached_dump.c +79 -0
  79. data/ext/libmemcached-0.32/libmemcached/memcached_exist.c +114 -0
  80. data/ext/libmemcached-0.32/libmemcached/memcached_exist.h +20 -0
  81. data/ext/libmemcached-0.32/libmemcached/memcached_fetch.c +102 -0
  82. data/ext/libmemcached-0.32/libmemcached/memcached_flush.c +89 -0
  83. data/ext/libmemcached-0.32/libmemcached/memcached_flush_buffers.c +23 -0
  84. data/ext/libmemcached-0.32/libmemcached/memcached_get.c +494 -0
  85. data/ext/libmemcached-0.32/libmemcached/memcached_get.h +87 -0
  86. data/ext/libmemcached-0.32/libmemcached/memcached_hash.c +252 -0
  87. data/ext/libmemcached-0.32/libmemcached/memcached_hosts.c +510 -0
  88. data/ext/libmemcached-0.32/libmemcached/memcached_internal.h +31 -0
  89. data/ext/libmemcached-0.32/libmemcached/memcached_io.c +594 -0
  90. data/ext/libmemcached-0.32/libmemcached/memcached_io.h +72 -0
  91. data/ext/libmemcached-0.32/libmemcached/memcached_key.c +28 -0
  92. data/ext/libmemcached-0.32/libmemcached/memcached_parse.c +74 -0
  93. data/ext/libmemcached-0.32/libmemcached/memcached_pool.h +38 -0
  94. data/ext/libmemcached-0.32/libmemcached/memcached_purge.c +76 -0
  95. data/ext/libmemcached-0.32/libmemcached/memcached_quit.c +75 -0
  96. data/ext/libmemcached-0.32/libmemcached/memcached_response.c +529 -0
  97. data/ext/libmemcached-0.32/libmemcached/memcached_result.c +57 -0
  98. data/ext/libmemcached-0.32/libmemcached/memcached_result.h +59 -0
  99. data/ext/libmemcached-0.32/libmemcached/memcached_sasl.c +225 -0
  100. data/ext/libmemcached-0.32/libmemcached/memcached_sasl.h +44 -0
  101. data/ext/libmemcached-0.32/libmemcached/memcached_server.c +159 -0
  102. data/ext/libmemcached-0.32/libmemcached/memcached_server.h +93 -0
  103. data/ext/libmemcached-0.32/libmemcached/memcached_stats.c +437 -0
  104. data/ext/libmemcached-0.32/libmemcached/memcached_storage.c +514 -0
  105. data/ext/libmemcached-0.32/libmemcached/memcached_storage.h +107 -0
  106. data/ext/libmemcached-0.32/libmemcached/memcached_strerror.c +92 -0
  107. data/ext/libmemcached-0.32/libmemcached/memcached_string.c +138 -0
  108. data/ext/libmemcached-0.32/libmemcached/memcached_string.h +53 -0
  109. data/ext/libmemcached-0.32/libmemcached/memcached_touch.c +60 -0
  110. data/ext/libmemcached-0.32/libmemcached/memcached_touch.h +31 -0
  111. data/ext/libmemcached-0.32/libmemcached/memcached_types.h +44 -0
  112. data/ext/libmemcached-0.32/libmemcached/memcached_util.h +15 -0
  113. data/ext/libmemcached-0.32/libmemcached/memcached_verbosity.c +36 -0
  114. data/ext/libmemcached-0.32/libmemcached/memcached_version.c +112 -0
  115. data/ext/libmemcached-0.32/libmemcached/memcached_watchpoint.h +38 -0
  116. data/ext/libmemcached-0.32/libmemcached/murmur_hash.c +76 -0
  117. data/ext/libmemcached-0.32/libmemcached/visibility.h +51 -0
  118. data/ext/libmemcached-0.32/libmemcachedutil/Makefile.am +11 -0
  119. data/ext/libmemcached-0.32/libmemcachedutil/Makefile.in +604 -0
  120. data/ext/libmemcached-0.32/libmemcachedutil/libmemcachedutil.ver +1 -0
  121. data/ext/libmemcached-0.32/libmemcachedutil/memcached_pool.c +170 -0
  122. data/ext/libmemcached-0.32/m4/ac_cxx_compile_stdcxx_0x.m4 +103 -0
  123. data/ext/libmemcached-0.32/m4/ac_cxx_header_stdcxx_98.m4 +67 -0
  124. data/ext/libmemcached-0.32/m4/acx_pthread.m4 +276 -0
  125. data/ext/libmemcached-0.32/m4/byteorder.m4 +40 -0
  126. data/ext/libmemcached-0.32/m4/deprecated.m4 +17 -0
  127. data/ext/libmemcached-0.32/m4/enable_utillib.m4 +16 -0
  128. data/ext/libmemcached-0.32/m4/extensions.m4 +94 -0
  129. data/ext/libmemcached-0.32/m4/hsieh.m4 +18 -0
  130. data/ext/libmemcached-0.32/m4/lib-prefix.m4 +221 -0
  131. data/ext/libmemcached-0.32/m4/libtool.m4 +7831 -0
  132. data/ext/libmemcached-0.32/m4/ltoptions.m4 +369 -0
  133. data/ext/libmemcached-0.32/m4/ltsugar.m4 +123 -0
  134. data/ext/libmemcached-0.32/m4/ltversion.m4 +23 -0
  135. data/ext/libmemcached-0.32/m4/lt~obsolete.m4 +98 -0
  136. data/ext/libmemcached-0.32/m4/memcached.m4 +30 -0
  137. data/ext/libmemcached-0.32/m4/pandora_64bit.m4 +55 -0
  138. data/ext/libmemcached-0.32/m4/pandora_canonical.m4 +151 -0
  139. data/ext/libmemcached-0.32/m4/pandora_check_compiler_version.m4 +37 -0
  140. data/ext/libmemcached-0.32/m4/pandora_check_cxx_standard.m4 +16 -0
  141. data/ext/libmemcached-0.32/m4/pandora_enable_dtrace.m4 +41 -0
  142. data/ext/libmemcached-0.32/m4/pandora_ensure_gcc_version.m4 +36 -0
  143. data/ext/libmemcached-0.32/m4/pandora_have_better_malloc.m4 +54 -0
  144. data/ext/libmemcached-0.32/m4/pandora_have_sasl.m4 +133 -0
  145. data/ext/libmemcached-0.32/m4/pandora_header_assert.m4 +23 -0
  146. data/ext/libmemcached-0.32/m4/pandora_libtool.m4 +15 -0
  147. data/ext/libmemcached-0.32/m4/pandora_optimize.m4 +79 -0
  148. data/ext/libmemcached-0.32/m4/pandora_shared_ptr.m4 +56 -0
  149. data/ext/libmemcached-0.32/m4/pandora_vc_build.m4 +32 -0
  150. data/ext/libmemcached-0.32/m4/pandora_warnings.m4 +262 -0
  151. data/ext/libmemcached-0.32/m4/pod2man.m4 +7 -0
  152. data/ext/libmemcached-0.32/m4/protocol_binary.m4 +23 -0
  153. data/ext/libmemcached-0.32/m4/setsockopt.m4 +57 -0
  154. data/ext/libmemcached-0.32/m4/visibility.m4 +52 -0
  155. data/ext/libmemcached-0.32/support/Makefile.am +4 -0
  156. data/ext/libmemcached-0.32/support/Makefile.in +487 -0
  157. data/ext/libmemcached-0.32/support/libmemcached-fc.spec.in +105 -0
  158. data/ext/libmemcached-0.32/support/libmemcached.pc.in +10 -0
  159. data/ext/libmemcached-0.32/support/libmemcached.spec +105 -0
  160. data/ext/libmemcached-0.32/support/libmemcached.spec.in +105 -0
  161. data/ext/libmemcached-0.32/support/set_benchmark.sh +5 -0
  162. data/ext/libmemcached-0.32/tests/Makefile.am +113 -0
  163. data/ext/libmemcached-0.32/tests/Makefile.in +762 -0
  164. data/ext/libmemcached-0.32/tests/atomsmasher.c +245 -0
  165. data/ext/libmemcached-0.32/tests/function.c +4904 -0
  166. data/ext/libmemcached-0.32/tests/ketama_test_cases.h +108 -0
  167. data/ext/libmemcached-0.32/tests/output.cmp +7 -0
  168. data/ext/libmemcached-0.32/tests/output.res +7 -0
  169. data/ext/libmemcached-0.32/tests/output2.res +46 -0
  170. data/ext/libmemcached-0.32/tests/plus.cpp +293 -0
  171. data/ext/libmemcached-0.32/tests/r/memcat.res +19 -0
  172. data/ext/libmemcached-0.32/tests/r/memcp.res +27 -0
  173. data/ext/libmemcached-0.32/tests/r/memrm.res +19 -0
  174. data/ext/libmemcached-0.32/tests/r/memslap.res +33 -0
  175. data/ext/libmemcached-0.32/tests/r/memstat.res +33 -0
  176. data/ext/libmemcached-0.32/tests/server.c +118 -0
  177. data/ext/libmemcached-0.32/tests/server.h +25 -0
  178. data/ext/libmemcached-0.32/tests/start.c +16 -0
  179. data/ext/libmemcached-0.32/tests/t/memcat.test +4 -0
  180. data/ext/libmemcached-0.32/tests/t/memcp.test +3 -0
  181. data/ext/libmemcached-0.32/tests/t/memrm.test +3 -0
  182. data/ext/libmemcached-0.32/tests/t/memslap.test +5 -0
  183. data/ext/libmemcached-0.32/tests/t/memstat.test +3 -0
  184. data/ext/libmemcached-0.32/tests/test.c +137 -0
  185. data/ext/libmemcached-0.32/tests/test.h +46 -0
  186. data/ext/libmemcached-0.32/tests/udp.c +76 -0
  187. data/ext/rlibmemcached.i +258 -0
  188. data/ext/rlibmemcached_wrap.c +13917 -0
  189. data/lib/memcached/auth.rb +16 -0
  190. data/lib/memcached/behaviors.rb +78 -0
  191. data/lib/memcached/exceptions.rb +84 -0
  192. data/lib/memcached/experimental.rb +48 -0
  193. data/lib/memcached/marshal_codec.rb +10 -0
  194. data/lib/memcached/memcached.rb +732 -0
  195. data/lib/memcached/rails.rb +250 -0
  196. data/lib/memcached.rb +33 -0
  197. data/memcached.gemspec +0 -0
  198. data/test/profile/benchmark.rb +280 -0
  199. data/test/profile/c_profiler.rb +14 -0
  200. data/test/profile/exercise.rb +185 -0
  201. data/test/profile/rb_profiler.rb +21 -0
  202. data/test/profile/valgrind.rb +10 -0
  203. data/test/setup.rb +30 -0
  204. data/test/teardown.rb +0 -0
  205. data/test/test_helper.rb +18 -0
  206. data/test/unit/binding_test.rb +8 -0
  207. data/test/unit/memcached_experimental_test.rb +272 -0
  208. data/test/unit/memcached_test.rb +1487 -0
  209. data/test/unit/rails_test.rb +330 -0
  210. metadata +336 -0
@@ -0,0 +1,72 @@
1
+ #include "common.h"
2
+
3
+ memcached_return memcached_do(memcached_server_st *ptr, const void *command,
4
+ size_t command_length, uint8_t with_flush)
5
+ {
6
+ memcached_return rc;
7
+ ssize_t sent_length;
8
+
9
+ WATCHPOINT_ASSERT(command_length);
10
+ WATCHPOINT_ASSERT(command);
11
+
12
+ if ((rc= memcached_connect(ptr)) != MEMCACHED_SUCCESS)
13
+ {
14
+ WATCHPOINT_ERROR(rc);
15
+ return rc;
16
+ }
17
+
18
+ /*
19
+ ** Since non buffering ops in UDP mode dont check to make sure they will fit
20
+ ** before they start writing, if there is any data in buffer, clear it out,
21
+ ** otherwise we might get a partial write.
22
+ **/
23
+ if (ptr->type == MEMCACHED_CONNECTION_UDP && with_flush && ptr->write_buffer_offset > UDP_DATAGRAM_HEADER_LENGTH)
24
+ memcached_io_write(ptr, NULL, 0, 1);
25
+
26
+ sent_length= memcached_io_write(ptr, command, command_length, (char) with_flush);
27
+
28
+ if (sent_length == -1 || (size_t)sent_length != command_length)
29
+ rc= MEMCACHED_WRITE_FAILURE;
30
+ else if ((ptr->root->flags & MEM_NOREPLY) == 0)
31
+ memcached_server_response_increment(ptr);
32
+
33
+ return rc;
34
+ }
35
+
36
+ memcached_return memcached_vdo(memcached_server_st *ptr,
37
+ const struct libmemcached_io_vector_st *vector, size_t count,
38
+ uint8_t with_flush)
39
+ {
40
+ memcached_return rc;
41
+ ssize_t sent_length;
42
+ size_t command_length;
43
+ uint32_t x;
44
+
45
+ WATCHPOINT_ASSERT(count);
46
+ WATCHPOINT_ASSERT(vector);
47
+
48
+ if ((rc= memcached_connect(ptr)) != MEMCACHED_SUCCESS)
49
+ {
50
+ WATCHPOINT_ERROR(rc);
51
+ return rc;
52
+ }
53
+
54
+ if (ptr->type == MEMCACHED_CONNECTION_UDP && with_flush && ptr->write_buffer_offset > UDP_DATAGRAM_HEADER_LENGTH)
55
+ {
56
+ memcached_io_write(ptr, NULL, 0, true);
57
+ }
58
+
59
+ sent_length= memcached_io_writev(ptr, vector, count, (char) with_flush);
60
+
61
+ command_length = 0;
62
+ for (x= 0; x < count; ++x, vector++)
63
+ command_length+= vector->length;
64
+
65
+ if (sent_length == -1 || (size_t)sent_length != command_length) {
66
+ rc = MEMCACHED_WRITE_FAILURE;
67
+ WATCHPOINT_ERROR(rc);
68
+ } else if ((ptr->root->flags & MEM_NOREPLY) == 0)
69
+ memcached_server_response_increment(ptr);
70
+
71
+ return rc;
72
+ }
@@ -0,0 +1,79 @@
1
+ /*
2
+ We use this to dump all keys.
3
+
4
+ At this point we only support a callback method. This could be optimized by first
5
+ calling items and finding active slabs. For the moment though we just loop through
6
+ all slabs on servers and "grab" the keys.
7
+ */
8
+
9
+ #include "common.h"
10
+ static memcached_return ascii_dump(memcached_st *ptr, memcached_dump_func *callback, void *context, uint32_t number_of_callbacks)
11
+ {
12
+ memcached_return rc= 0;
13
+ char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
14
+ size_t send_length;
15
+ uint32_t server_key;
16
+ uint32_t x;
17
+
18
+ unlikely (ptr->number_of_hosts == 0)
19
+ return MEMCACHED_NO_SERVERS;
20
+
21
+ for (server_key= 0; server_key < ptr->number_of_hosts; server_key++)
22
+ {
23
+ /* 256 I BELIEVE is the upper limit of slabs */
24
+ for (x= 0; x < 256; x++)
25
+ {
26
+ send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
27
+ "stats cachedump %u 0 0\r\n", x);
28
+
29
+ rc= memcached_do(&ptr->hosts[server_key], buffer, send_length, 1);
30
+
31
+ unlikely (rc != MEMCACHED_SUCCESS)
32
+ goto error;
33
+
34
+ while (1)
35
+ {
36
+ uint32_t callback_counter;
37
+ rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
38
+
39
+ if (rc == MEMCACHED_ITEM)
40
+ {
41
+ char *string_ptr, *end_ptr;
42
+ char *key;
43
+
44
+ string_ptr= buffer;
45
+ string_ptr+= 5; /* Move past ITEM */
46
+ for (end_ptr= string_ptr; isgraph(*end_ptr); end_ptr++);
47
+ key= string_ptr;
48
+ key[(size_t)(end_ptr-string_ptr)]= 0;
49
+ for (callback_counter= 0; callback_counter < number_of_callbacks; callback_counter++)
50
+ {
51
+ rc= (*callback[callback_counter])(ptr, key, (size_t)(end_ptr-string_ptr), context);
52
+ if (rc != MEMCACHED_SUCCESS)
53
+ break;
54
+ }
55
+ }
56
+ else if (rc == MEMCACHED_END)
57
+ break;
58
+ else
59
+ goto error;
60
+ }
61
+ }
62
+ }
63
+
64
+ error:
65
+ if (rc == MEMCACHED_END)
66
+ return MEMCACHED_SUCCESS;
67
+ else
68
+ return rc;
69
+ }
70
+
71
+ memcached_return memcached_dump(memcached_st *ptr, memcached_dump_func *callback, void *context, uint32_t number_of_callbacks)
72
+ {
73
+ /* No support for Binary protocol yet */
74
+ if (ptr->flags & MEM_BINARY_PROTOCOL)
75
+ return MEMCACHED_FAILURE;
76
+
77
+ return ascii_dump(ptr, callback, context, number_of_callbacks);
78
+ }
79
+
@@ -0,0 +1,114 @@
1
+ #include <libmemcached/common.h>
2
+
3
+ static memcached_return binary_exist(memcached_st *ptr, memcached_server_st *server,
4
+ const char* key, size_t key_length)
5
+ {
6
+ protocol_binary_request_set request= {.bytes= {0}};
7
+ size_t send_length= sizeof(request.bytes);
8
+
9
+ request.message.header.request.magic= PROTOCOL_BINARY_REQ;
10
+ request.message.header.request.opcode= PROTOCOL_BINARY_CMD_ADD;
11
+ request.message.header.request.keylen= htons((uint16_t)(ptr->prefix_key_length + key_length));
12
+ request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
13
+ request.message.header.request.extlen= 8;
14
+ request.message.body.flags= 0;
15
+ request.message.body.expiration= htonl(2678400);
16
+
17
+ request.message.header.request.bodylen= htonl((uint32_t) (key_length
18
+ +ptr->prefix_key_length
19
+ +request.message.header.request.extlen));
20
+
21
+
22
+ struct libmemcached_io_vector_st vector[]=
23
+ {
24
+ { send_length, request.bytes },
25
+ { strlen(ptr->prefix_key), ptr->prefix_key },
26
+ { key_length, key }
27
+ };
28
+
29
+ memcached_return rc= memcached_vdo(server, vector, 3, 1);
30
+ if (rc != MEMCACHED_SUCCESS)
31
+ {
32
+ memcached_io_reset(server);
33
+ return (rc == MEMCACHED_SUCCESS) ? MEMCACHED_WRITE_FAILURE : rc;
34
+ }
35
+
36
+ rc= memcached_response(server, NULL, 0, NULL);
37
+
38
+ if (rc == MEMCACHED_SUCCESS)
39
+ rc= MEMCACHED_NOTFOUND;
40
+
41
+ if (rc == MEMCACHED_DATA_EXISTS)
42
+ rc= MEMCACHED_SUCCESS;
43
+
44
+ return rc;
45
+ }
46
+
47
+ static memcached_return ascii_exist(memcached_st *ptr, memcached_server_st *server,
48
+ const char* key, size_t key_length)
49
+ {
50
+ struct libmemcached_io_vector_st vector[]=
51
+ {
52
+ { sizeof("add ") -1, "add " },
53
+ { strlen(ptr->prefix_key), ptr->prefix_key },
54
+ { key_length, key },
55
+ { sizeof(" 0") -1, " 0" },
56
+ { sizeof(" 2678400") -1, " 2678400" },
57
+ { sizeof(" 0") -1, " 0" },
58
+ { 2, "\r\n" },
59
+ { 2, "\r\n" }
60
+ };
61
+
62
+ memcached_return rc = memcached_vdo(server, vector, 8, 1);
63
+
64
+ if (rc == MEMCACHED_SUCCESS)
65
+ {
66
+ char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
67
+ rc= memcached_response(server, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
68
+
69
+ if (rc == MEMCACHED_NOTSTORED)
70
+ rc= MEMCACHED_SUCCESS;
71
+
72
+ if (rc == MEMCACHED_STORED)
73
+ rc= MEMCACHED_NOTFOUND;
74
+ }
75
+
76
+ if (rc == MEMCACHED_WRITE_FAILURE)
77
+ memcached_io_reset(server);
78
+
79
+ return rc;
80
+ }
81
+
82
+ memcached_return memcached_exist(memcached_st *ptr, const char *key, size_t key_length)
83
+ {
84
+ return memcached_exist_by_key(ptr, key, key_length, key, key_length);
85
+ }
86
+
87
+ memcached_return memcached_exist_by_key(memcached_st *ptr,
88
+ const char *group_key, size_t group_key_length,
89
+ const char *key, size_t key_length)
90
+ {
91
+ unlikely (ptr->flags & MEM_USE_UDP)
92
+ return MEMCACHED_NOT_SUPPORTED;
93
+
94
+ if (ptr->number_of_hosts == 0)
95
+ return MEMCACHED_NO_SERVERS;
96
+
97
+ if (ptr->flags & MEM_NOREPLY)
98
+ {
99
+ size_t dummy_length;
100
+ uint32_t dummy_flags;
101
+ memcached_return dummy_error;
102
+
103
+ memcached_get(ptr, key, key_length, &dummy_length, &dummy_flags, &dummy_error);
104
+ return dummy_error;
105
+ }
106
+
107
+ unsigned int server_key= memcached_generate_hash(ptr, key, key_length);
108
+ memcached_server_st *server= &ptr->hosts[server_key];
109
+
110
+ if (ptr->flags & MEM_BINARY_PROTOCOL)
111
+ return binary_exist(ptr, server, key, key_length);
112
+ else
113
+ return ascii_exist(ptr, server, key, key_length);
114
+ }
@@ -0,0 +1,20 @@
1
+ #ifndef __MEMCACHED_EXIST_H__
2
+ #define __MEMCACHED_EXIST_H__
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ LIBMEMCACHED_API
9
+ memcached_return memcached_exist(memcached_st *memc, const char *key, size_t key_length);
10
+
11
+ LIBMEMCACHED_API
12
+ memcached_return memcached_exist_by_key(memcached_st *memc,
13
+ const char *group_key, size_t group_key_length,
14
+ const char *key, size_t key_length);
15
+
16
+ #ifdef __cplusplus
17
+ }
18
+ #endif
19
+
20
+ #endif /* __MEMCACHED_EXIST_H__ */
@@ -0,0 +1,102 @@
1
+ #include "common.h"
2
+ #include "memcached_io.h"
3
+
4
+ char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length,
5
+ size_t *value_length,
6
+ uint32_t *flags,
7
+ memcached_return *error)
8
+ {
9
+ memcached_result_st *result_buffer= &ptr->result;
10
+
11
+ unlikely (ptr->flags & MEM_USE_UDP)
12
+ {
13
+ *error= MEMCACHED_NOT_SUPPORTED;
14
+ return NULL;
15
+ }
16
+
17
+ result_buffer= memcached_fetch_result(ptr, result_buffer, error);
18
+
19
+ if (result_buffer == NULL || *error != MEMCACHED_SUCCESS)
20
+ {
21
+ WATCHPOINT_ASSERT(result_buffer == NULL);
22
+ *value_length= 0;
23
+ return NULL;
24
+ }
25
+
26
+ *value_length= memcached_string_length(&result_buffer->value);
27
+
28
+ if (key)
29
+ {
30
+ strncpy(key, result_buffer->key, result_buffer->key_length);
31
+ *key_length= result_buffer->key_length;
32
+ }
33
+
34
+ if (result_buffer->flags)
35
+ *flags= result_buffer->flags;
36
+ else
37
+ *flags= 0;
38
+
39
+ return memcached_string_c_copy(&result_buffer->value);
40
+ }
41
+
42
+ memcached_result_st *memcached_fetch_result(memcached_st *ptr,
43
+ memcached_result_st *result,
44
+ memcached_return *error)
45
+ {
46
+ memcached_server_st *server;
47
+
48
+ unlikely (ptr->flags & MEM_USE_UDP)
49
+ {
50
+ *error= MEMCACHED_NOT_SUPPORTED;
51
+ return NULL;
52
+ }
53
+
54
+ if (result == NULL)
55
+ if ((result= memcached_result_create(ptr, NULL)) == NULL)
56
+ return NULL;
57
+
58
+ while ((server = memcached_io_get_readable_server(ptr)) != NULL)
59
+ {
60
+ char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
61
+ *error= memcached_response(server, buffer, sizeof(buffer), result);
62
+
63
+ if (*error == MEMCACHED_SUCCESS)
64
+ return result;
65
+ else if (*error == MEMCACHED_END)
66
+ memcached_server_response_reset(server);
67
+ else
68
+ break;
69
+ }
70
+
71
+ /* We have completed reading data */
72
+ if (result->is_allocated)
73
+ memcached_result_free(result);
74
+ else
75
+ memcached_string_reset(&result->value);
76
+
77
+ return NULL;
78
+ }
79
+
80
+ memcached_return memcached_fetch_execute(memcached_st *ptr,
81
+ memcached_execute_function *callback,
82
+ void *context,
83
+ unsigned int number_of_callbacks)
84
+ {
85
+ memcached_result_st *result= &ptr->result;
86
+ memcached_return rc= MEMCACHED_FAILURE;
87
+ unsigned int x;
88
+
89
+ while ((result= memcached_fetch_result(ptr, result, &rc)) != NULL)
90
+ {
91
+ if (rc == MEMCACHED_SUCCESS)
92
+ {
93
+ for (x= 0; x < number_of_callbacks; x++)
94
+ {
95
+ rc= (*callback[x])(ptr, result, context);
96
+ if (rc != MEMCACHED_SUCCESS)
97
+ break;
98
+ }
99
+ }
100
+ }
101
+ return rc;
102
+ }
@@ -0,0 +1,89 @@
1
+ #include "common.h"
2
+
3
+ static memcached_return memcached_flush_binary(memcached_st *ptr,
4
+ time_t expiration);
5
+ static memcached_return memcached_flush_textual(memcached_st *ptr,
6
+ time_t expiration);
7
+
8
+ memcached_return memcached_flush(memcached_st *ptr, time_t expiration)
9
+ {
10
+ memcached_return rc;
11
+
12
+ LIBMEMCACHED_MEMCACHED_FLUSH_START();
13
+ if (ptr->flags & MEM_BINARY_PROTOCOL)
14
+ rc= memcached_flush_binary(ptr, expiration);
15
+ else
16
+ rc= memcached_flush_textual(ptr, expiration);
17
+ LIBMEMCACHED_MEMCACHED_FLUSH_END();
18
+ return rc;
19
+ }
20
+
21
+ static memcached_return memcached_flush_textual(memcached_st *ptr,
22
+ time_t expiration)
23
+ {
24
+ unsigned int x;
25
+ size_t send_length;
26
+ memcached_return rc;
27
+ char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
28
+
29
+ unlikely (ptr->number_of_hosts == 0)
30
+ return MEMCACHED_NO_SERVERS;
31
+
32
+ for (x= 0; x < ptr->number_of_hosts; x++)
33
+ {
34
+ bool no_reply= (ptr->flags & MEM_NOREPLY);
35
+ if (expiration)
36
+ send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
37
+ "flush_all %llu%s\r\n",
38
+ (unsigned long long)expiration, no_reply ? " noreply" : "");
39
+ else
40
+ send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
41
+ "flush_all%s\r\n", no_reply ? " noreply" : "");
42
+
43
+ rc= memcached_do(&ptr->hosts[x], buffer, send_length, 1);
44
+
45
+ if (rc == MEMCACHED_SUCCESS && !no_reply)
46
+ (void)memcached_response(&ptr->hosts[x], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
47
+ }
48
+
49
+ return MEMCACHED_SUCCESS;
50
+ }
51
+
52
+ static memcached_return memcached_flush_binary(memcached_st *ptr,
53
+ time_t expiration)
54
+ {
55
+ unsigned int x;
56
+ protocol_binary_request_flush request= {.bytes= {0}};
57
+
58
+ unlikely (ptr->number_of_hosts == 0)
59
+ return MEMCACHED_NO_SERVERS;
60
+
61
+ request.message.header.request.magic= (uint8_t)PROTOCOL_BINARY_REQ;
62
+ request.message.header.request.opcode= PROTOCOL_BINARY_CMD_FLUSH;
63
+ request.message.header.request.extlen= 4;
64
+ request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
65
+ request.message.header.request.bodylen= htonl(request.message.header.request.extlen);
66
+ request.message.body.expiration= htonl((uint32_t) expiration);
67
+
68
+ for (x= 0; x < ptr->number_of_hosts; x++)
69
+ {
70
+ if (ptr->flags & MEM_NOREPLY)
71
+ request.message.header.request.opcode= PROTOCOL_BINARY_CMD_FLUSHQ;
72
+ else
73
+ request.message.header.request.opcode= PROTOCOL_BINARY_CMD_FLUSH;
74
+ if (memcached_do(&ptr->hosts[x], request.bytes,
75
+ sizeof(request.bytes), 1) != MEMCACHED_SUCCESS)
76
+ {
77
+ memcached_io_reset(&ptr->hosts[x]);
78
+ return MEMCACHED_WRITE_FAILURE;
79
+ }
80
+ }
81
+
82
+ for (x= 0; x < ptr->number_of_hosts; x++)
83
+ {
84
+ if (memcached_server_response_count(&ptr->hosts[x]) > 0)
85
+ (void)memcached_response(&ptr->hosts[x], NULL, 0, NULL);
86
+ }
87
+
88
+ return MEMCACHED_SUCCESS;
89
+ }
@@ -0,0 +1,23 @@
1
+ #include "common.h"
2
+ #include "memcached_io.h"
3
+
4
+ memcached_return memcached_flush_buffers(memcached_st *mem)
5
+ {
6
+ memcached_return ret= MEMCACHED_SUCCESS;
7
+ uint32_t x;
8
+
9
+ for (x= 0; x < mem->number_of_hosts; ++x)
10
+ if (mem->hosts[x].write_buffer_offset != 0)
11
+ {
12
+ if (mem->hosts[x].fd == -1 &&
13
+ (ret= memcached_connect(&mem->hosts[x])) != MEMCACHED_SUCCESS)
14
+ {
15
+ WATCHPOINT_ERROR(ret);
16
+ return ret;
17
+ }
18
+ if (memcached_io_write(&mem->hosts[x], NULL, 0, 1) == -1)
19
+ ret= MEMCACHED_SOME_ERRORS;
20
+ }
21
+
22
+ return ret;
23
+ }