memcached_quit should clear internal server variables
[m6w6/libmemcached] / libmemcached / memcached.h
1 /* LibMemcached
2 * Copyright (C) 2006-2009 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
8 * Summary: interface for memcached server
9 * Description: main include file for libmemcached
10 *
11 */
12
13 #ifndef __MEMCACHED_H__
14 #define __MEMCACHED_H__
15
16 #include <stdlib.h>
17 #include <inttypes.h>
18
19 #if !defined(__cplusplus)
20 # include <stdbool.h>
21 #endif
22
23 #include <sys/types.h>
24 #include <netinet/in.h>
25
26 #include <libmemcached/visibility.h>
27 #include <libmemcached/memcached_configure.h>
28 #include <libmemcached/constants.h>
29 #include <libmemcached/types.h>
30 #include <libmemcached/string.h>
31 // Everything above this line must be in the order specified.
32 #include <libmemcached/behavior.h>
33 #include <libmemcached/callback.h>
34 #include <libmemcached/dump.h>
35 #include <libmemcached/get.h>
36 #include <libmemcached/result.h>
37 #include <libmemcached/server.h>
38 #include <libmemcached/storage.h>
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 #define MEMCACHED_VERSION_STRING_LENGTH 24
45
46 struct memcached_analysis_st {
47 uint32_t average_item_size;
48 uint32_t longest_uptime;
49 uint32_t least_free_server;
50 uint32_t most_consumed_server;
51 uint32_t oldest_server;
52 double pool_hit_ratio;
53 uint64_t most_used_bytes;
54 uint64_t least_remaining_bytes;
55 };
56
57 struct memcached_stat_st {
58 uint32_t connection_structures;
59 uint32_t curr_connections;
60 uint32_t curr_items;
61 uint32_t pid;
62 uint32_t pointer_size;
63 uint32_t rusage_system_microseconds;
64 uint32_t rusage_system_seconds;
65 uint32_t rusage_user_microseconds;
66 uint32_t rusage_user_seconds;
67 uint32_t threads;
68 uint32_t time;
69 uint32_t total_connections;
70 uint32_t total_items;
71 uint32_t uptime;
72 uint64_t bytes;
73 uint64_t bytes_read;
74 uint64_t bytes_written;
75 uint64_t cmd_get;
76 uint64_t cmd_set;
77 uint64_t evictions;
78 uint64_t get_hits;
79 uint64_t get_misses;
80 uint64_t limit_maxbytes;
81 char version[MEMCACHED_VERSION_STRING_LENGTH];
82 };
83
84 struct memcached_st {
85 struct {
86 bool is_allocated:1;
87 bool is_initialized:1;
88 bool is_purging:1;
89 } options;
90 memcached_server_distribution_t distribution;
91 memcached_hash_t hash;
92 uint32_t continuum_points_counter;
93 memcached_server_st *hosts;
94 memcached_server_st *last_disconnected_server;
95 int32_t snd_timeout;
96 int32_t rcv_timeout;
97 uint32_t server_failure_limit;
98 uint32_t io_msg_watermark;
99 uint32_t io_bytes_watermark;
100 uint32_t io_key_prefetch;
101 uint32_t number_of_hosts;
102 uint32_t cursor_server;
103 int cached_errno;
104 struct {
105 bool auto_eject_hosts:1;
106 bool binary_protocol:1;
107 bool buffer_requests:1;
108 bool hash_with_prefix_key:1;
109 bool ketama_weighted:1;
110 bool no_block:1;
111 bool no_reply:1;
112 bool randomize_replica_read:1;
113 bool reuse_memory:1;
114 bool support_cas:1;
115 bool tcp_nodelay:1;
116 bool use_cache_lookups:1;
117 bool use_sort_hosts:1;
118 bool use_udp:1;
119 bool verify_key:1;
120 } flags;
121 int32_t poll_timeout;
122 int32_t connect_timeout;
123 int32_t retry_timeout;
124 uint32_t continuum_count;
125 int send_size;
126 int recv_size;
127 void *user_data;
128 time_t next_distribution_rebuild;
129 size_t prefix_key_length;
130 uint32_t number_of_replicas;
131 memcached_hash_t distribution_hash;
132 memcached_result_st result;
133 memcached_continuum_item_st *continuum;
134 memcached_clone_fn on_clone;
135 memcached_cleanup_fn on_cleanup;
136 memcached_free_fn call_free;
137 memcached_malloc_fn call_malloc;
138 memcached_realloc_fn call_realloc;
139 memcached_calloc_fn call_calloc;
140 memcached_trigger_key_fn get_key_failure;
141 memcached_trigger_delete_key_fn delete_trigger;
142 memcached_callback_st *callbacks;
143 char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE];
144 };
145
146 LIBMEMCACHED_API
147 memcached_return_t memcached_version(memcached_st *ptr);
148
149 /* Public API */
150
151 LIBMEMCACHED_API
152 const char * memcached_lib_version(void);
153
154 LIBMEMCACHED_API
155 memcached_st *memcached_create(memcached_st *ptr);
156 LIBMEMCACHED_API
157 void memcached_free(memcached_st *ptr);
158 LIBMEMCACHED_API
159 memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr);
160
161 LIBMEMCACHED_API
162 memcached_return_t memcached_delete(memcached_st *ptr, const char *key, size_t key_length,
163 time_t expiration);
164 LIBMEMCACHED_API
165 memcached_return_t memcached_increment(memcached_st *ptr,
166 const char *key, size_t key_length,
167 uint32_t offset,
168 uint64_t *value);
169 LIBMEMCACHED_API
170 memcached_return_t memcached_decrement(memcached_st *ptr,
171 const char *key, size_t key_length,
172 uint32_t offset,
173 uint64_t *value);
174
175 LIBMEMCACHED_API
176 memcached_return_t memcached_increment_by_key(memcached_st *ptr,
177 const char *master_key, size_t master_key_length,
178 const char *key, size_t key_length,
179 uint64_t offset,
180 uint64_t *value);
181
182 LIBMEMCACHED_API
183 memcached_return_t memcached_decrement_by_key(memcached_st *ptr,
184 const char *master_key, size_t master_key_length,
185 const char *key, size_t key_length,
186 uint64_t offset,
187 uint64_t *value);
188
189 LIBMEMCACHED_API
190 memcached_return_t memcached_increment_with_initial(memcached_st *ptr,
191 const char *key,
192 size_t key_length,
193 uint64_t offset,
194 uint64_t initial,
195 time_t expiration,
196 uint64_t *value);
197 LIBMEMCACHED_API
198 memcached_return_t memcached_decrement_with_initial(memcached_st *ptr,
199 const char *key,
200 size_t key_length,
201 uint64_t offset,
202 uint64_t initial,
203 time_t expiration,
204 uint64_t *value);
205 LIBMEMCACHED_API
206 memcached_return_t memcached_increment_with_initial_by_key(memcached_st *ptr,
207 const char *master_key,
208 size_t master_key_length,
209 const char *key,
210 size_t key_length,
211 uint64_t offset,
212 uint64_t initial,
213 time_t expiration,
214 uint64_t *value);
215 LIBMEMCACHED_API
216 memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *ptr,
217 const char *master_key,
218 size_t master_key_length,
219 const char *key,
220 size_t key_length,
221 uint64_t offset,
222 uint64_t initial,
223 time_t expiration,
224 uint64_t *value);
225 LIBMEMCACHED_API
226 void memcached_stat_free(memcached_st *, memcached_stat_st *);
227
228 LIBMEMCACHED_API
229 memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return_t *error);
230
231 LIBMEMCACHED_API
232 memcached_return_t memcached_stat_servername(memcached_stat_st *memc_stat, char *args,
233 const char *hostname, in_port_t port);
234
235 LIBMEMCACHED_API
236 memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration);
237
238 LIBMEMCACHED_API
239 memcached_return_t memcached_verbosity(memcached_st *ptr, unsigned int verbosity);
240
241 LIBMEMCACHED_API
242 void memcached_quit(memcached_st *ptr);
243
244 LIBMEMCACHED_API
245 const char *memcached_strerror(memcached_st *ptr, memcached_return_t rc);
246
247 /* The two public hash bits */
248 LIBMEMCACHED_API
249 uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memcached_hash_t hash_algorithm);
250
251 LIBMEMCACHED_API
252 uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_length);
253
254 LIBMEMCACHED_API
255 memcached_return_t memcached_flush_buffers(memcached_st *mem);
256
257 /* Server Public functions */
258
259 LIBMEMCACHED_API
260 memcached_return_t memcached_server_add_udp(memcached_st *ptr,
261 const char *hostname,
262 in_port_t port);
263 LIBMEMCACHED_API
264 memcached_return_t memcached_server_add_unix_socket(memcached_st *ptr,
265 const char *filename);
266 LIBMEMCACHED_API
267 memcached_return_t memcached_server_add(memcached_st *ptr,
268 const char *hostname, in_port_t port);
269
270 LIBMEMCACHED_API
271 memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr,
272 const char *hostname,
273 in_port_t port,
274 uint32_t weight);
275 LIBMEMCACHED_API
276 memcached_return_t memcached_server_add_unix_socket_with_weight(memcached_st *ptr,
277 const char *filename,
278 uint32_t weight);
279 LIBMEMCACHED_API
280 memcached_return_t memcached_server_add_with_weight(memcached_st *ptr, const char *hostname,
281 in_port_t port,
282 uint32_t weight);
283 LIBMEMCACHED_API
284 void memcached_server_list_free(memcached_server_st *ptr);
285
286 LIBMEMCACHED_API
287 memcached_return_t memcached_server_push(memcached_st *ptr, memcached_server_st *list);
288
289 LIBMEMCACHED_API
290 memcached_server_st *memcached_server_list_append(memcached_server_st *ptr,
291 const char *hostname,
292 in_port_t port,
293 memcached_return_t *error);
294 LIBMEMCACHED_API
295 memcached_server_st *memcached_server_list_append_with_weight(memcached_server_st *ptr,
296 const char *hostname,
297 in_port_t port,
298 uint32_t weight,
299 memcached_return_t *error);
300 LIBMEMCACHED_API
301 unsigned int memcached_server_list_count(memcached_server_st *ptr);
302
303 LIBMEMCACHED_API
304 memcached_server_st *memcached_servers_parse(const char *server_strings);
305
306 LIBMEMCACHED_API
307 char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat,
308 const char *key, memcached_return_t *error);
309 LIBMEMCACHED_API
310 char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *memc_stat,
311 memcached_return_t *error);
312
313 LIBMEMCACHED_API
314 memcached_return_t memcached_delete_by_key(memcached_st *ptr,
315 const char *master_key, size_t master_key_length,
316 const char *key, size_t key_length,
317 time_t expiration);
318
319 LIBMEMCACHED_API
320 memcached_return_t memcached_fetch_execute(memcached_st *ptr,
321 memcached_execute_fn *callback,
322 void *context,
323 unsigned int number_of_callbacks);
324
325 LIBMEMCACHED_API
326 memcached_return_t memcached_set_memory_allocators(memcached_st *ptr,
327 memcached_malloc_fn mem_malloc,
328 memcached_free_fn mem_free,
329 memcached_realloc_fn mem_realloc,
330 memcached_calloc_fn mem_calloc);
331
332 LIBMEMCACHED_API
333 void memcached_get_memory_allocators(memcached_st *ptr,
334 memcached_malloc_fn *mem_malloc,
335 memcached_free_fn *mem_free,
336 memcached_realloc_fn *mem_realloc,
337 memcached_calloc_fn *mem_calloc);
338
339 LIBMEMCACHED_API
340 void *memcached_get_user_data(memcached_st *ptr);
341 LIBMEMCACHED_API
342 void *memcached_set_user_data(memcached_st *ptr, void *data);
343
344 LIBMEMCACHED_LOCAL
345 memcached_return_t run_distribution(memcached_st *ptr);
346
347 #define memcached_is_allocated(__object) ((__object)->options.is_allocated)
348 #define memcached_is_initialized(__object) ((__object)->options.is_initialized)
349
350 #ifdef __cplusplus
351 }
352 #endif
353
354
355 #endif /* __MEMCACHED_H__ */