2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
8 * Summary: interface for memcached server
9 * Description: main include file for libmemcached
13 #ifndef __MEMCACHED_H__
14 #define __MEMCACHED_H__
19 #if !defined(__cplusplus)
23 #include <sys/types.h>
24 #include <netinet/in.h>
26 #include <libmemcached/visibility.h>
27 #include <libmemcached/memcached_configure.h>
28 #include <libmemcached/memcached_constants.h>
29 #include <libmemcached/memcached_types.h>
30 #include <libmemcached/memcached_behavior.h>
31 #include <libmemcached/memcached_callback.h>
32 #include <libmemcached/memcached_get.h>
33 #include <libmemcached/memcached_server.h>
34 #include <libmemcached/memcached_string.h>
35 #include <libmemcached/memcached_result.h>
36 #include <libmemcached/memcached_storage.h>
42 #define MEMCACHED_VERSION_STRING_LENGTH 24
44 struct memcached_analysis_st
{
45 uint32_t average_item_size
;
46 uint32_t longest_uptime
;
47 uint32_t least_free_server
;
48 uint32_t most_consumed_server
;
49 uint32_t oldest_server
;
50 double pool_hit_ratio
;
51 uint64_t most_used_bytes
;
52 uint64_t least_remaining_bytes
;
55 struct memcached_stat_st
{
56 uint32_t connection_structures
;
57 uint32_t curr_connections
;
60 uint32_t pointer_size
;
61 uint32_t rusage_system_microseconds
;
62 uint32_t rusage_system_seconds
;
63 uint32_t rusage_user_microseconds
;
64 uint32_t rusage_user_seconds
;
67 uint32_t total_connections
;
72 uint64_t bytes_written
;
78 uint64_t limit_maxbytes
;
79 char version
[MEMCACHED_VERSION_STRING_LENGTH
];
85 bool is_initialized
:1;
88 memcached_server_distribution_t distribution
;
89 memcached_hash_t hash
;
90 uint32_t continuum_points_counter
;
91 memcached_server_st
*hosts
;
92 memcached_server_st
*last_disconnected_server
;
95 uint32_t server_failure_limit
;
96 uint32_t io_msg_watermark
;
97 uint32_t io_bytes_watermark
;
98 uint32_t io_key_prefetch
;
99 uint32_t number_of_hosts
;
100 uint32_t cursor_server
;
108 bool use_cache_lookups
:1;
110 bool buffer_requests
:1;
111 bool use_sort_hosts
:1;
113 bool ketama_weighted
:1;
114 bool binary_protocol
:1;
115 bool hash_with_prefix_key
:1;
118 bool auto_eject_hosts
:1;
119 bool randomize_replica_read
:1;
121 int32_t poll_timeout
;
122 int32_t connect_timeout
;
123 int32_t retry_timeout
;
124 uint32_t continuum_count
;
128 time_t next_distribution_rebuild
;
129 size_t prefix_key_length
;
130 memcached_hash_t hash_continuum
;
131 memcached_result_st result
;
132 memcached_continuum_item_st
*continuum
;
133 memcached_clone_fn on_clone
;
134 memcached_cleanup_fn on_cleanup
;
135 memcached_free_fn call_free
;
136 memcached_malloc_fn call_malloc
;
137 memcached_realloc_fn call_realloc
;
138 memcached_calloc_fn call_calloc
;
139 memcached_trigger_key_fn get_key_failure
;
140 memcached_trigger_delete_key_fn delete_trigger
;
141 char prefix_key
[MEMCACHED_PREFIX_KEY_MAX_SIZE
];
142 uint32_t number_of_replicas
;
143 memcached_callback_st
*callbacks
;
147 memcached_return_t
memcached_version(memcached_st
*ptr
);
152 const char * memcached_lib_version(void);
155 memcached_st
*memcached_create(memcached_st
*ptr
);
157 void memcached_free(memcached_st
*ptr
);
159 memcached_st
*memcached_clone(memcached_st
*clone
, memcached_st
*ptr
);
162 memcached_return_t
memcached_delete(memcached_st
*ptr
, const char *key
, size_t key_length
,
165 memcached_return_t
memcached_increment(memcached_st
*ptr
,
166 const char *key
, size_t key_length
,
170 memcached_return_t
memcached_decrement(memcached_st
*ptr
,
171 const char *key
, size_t key_length
,
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
,
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
,
190 memcached_return_t
memcached_increment_with_initial(memcached_st
*ptr
,
198 memcached_return_t
memcached_decrement_with_initial(memcached_st
*ptr
,
206 memcached_return_t
memcached_increment_with_initial_by_key(memcached_st
*ptr
,
207 const char *master_key
,
208 size_t master_key_length
,
216 memcached_return_t
memcached_decrement_with_initial_by_key(memcached_st
*ptr
,
217 const char *master_key
,
218 size_t master_key_length
,
226 void memcached_stat_free(memcached_st
*, memcached_stat_st
*);
229 memcached_stat_st
*memcached_stat(memcached_st
*ptr
, char *args
, memcached_return_t
*error
);
232 memcached_return_t
memcached_stat_servername(memcached_stat_st
*memc_stat
, char *args
,
233 const char *hostname
, in_port_t port
);
236 memcached_return_t
memcached_flush(memcached_st
*ptr
, time_t expiration
);
239 memcached_return_t
memcached_verbosity(memcached_st
*ptr
, unsigned int verbosity
);
242 void memcached_quit(memcached_st
*ptr
);
245 const char *memcached_strerror(memcached_st
*ptr
, memcached_return_t rc
);
247 /* The two public hash bits */
249 uint32_t memcached_generate_hash_value(const char *key
, size_t key_length
, memcached_hash_t hash_algorithm
);
252 uint32_t memcached_generate_hash(memcached_st
*ptr
, const char *key
, size_t key_length
);
255 memcached_return_t
memcached_flush_buffers(memcached_st
*mem
);
257 /* Server Public functions */
260 memcached_return_t
memcached_server_add_udp(memcached_st
*ptr
,
261 const char *hostname
,
264 memcached_return_t
memcached_server_add_unix_socket(memcached_st
*ptr
,
265 const char *filename
);
267 memcached_return_t
memcached_server_add(memcached_st
*ptr
,
268 const char *hostname
, in_port_t port
);
271 memcached_return_t
memcached_server_add_udp_with_weight(memcached_st
*ptr
,
272 const char *hostname
,
276 memcached_return_t
memcached_server_add_unix_socket_with_weight(memcached_st
*ptr
,
277 const char *filename
,
280 memcached_return_t
memcached_server_add_with_weight(memcached_st
*ptr
, const char *hostname
,
284 void memcached_server_list_free(memcached_server_st
*ptr
);
287 memcached_return_t
memcached_server_push(memcached_st
*ptr
, memcached_server_st
*list
);
290 memcached_server_st
*memcached_server_list_append(memcached_server_st
*ptr
,
291 const char *hostname
,
293 memcached_return_t
*error
);
295 memcached_server_st
*memcached_server_list_append_with_weight(memcached_server_st
*ptr
,
296 const char *hostname
,
299 memcached_return_t
*error
);
301 unsigned int memcached_server_list_count(memcached_server_st
*ptr
);
304 memcached_server_st
*memcached_servers_parse(const char *server_strings
);
307 char *memcached_stat_get_value(memcached_st
*ptr
, memcached_stat_st
*memc_stat
,
308 const char *key
, memcached_return_t
*error
);
310 char ** memcached_stat_get_keys(memcached_st
*ptr
, memcached_stat_st
*memc_stat
,
311 memcached_return_t
*error
);
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
,
320 memcached_return_t
memcached_fetch_execute(memcached_st
*ptr
,
321 memcached_execute_fn
*callback
,
323 unsigned int number_of_callbacks
);
326 memcached_return_t
memcached_dump(memcached_st
*ptr
, memcached_dump_fn
*function
, void *context
, uint32_t number_of_callbacks
);
330 memcached_return_t
memcached_set_memory_allocators(memcached_st
*ptr
,
331 memcached_malloc_fn mem_malloc
,
332 memcached_free_fn mem_free
,
333 memcached_realloc_fn mem_realloc
,
334 memcached_calloc_fn mem_calloc
);
337 void memcached_get_memory_allocators(memcached_st
*ptr
,
338 memcached_malloc_fn
*mem_malloc
,
339 memcached_free_fn
*mem_free
,
340 memcached_realloc_fn
*mem_realloc
,
341 memcached_calloc_fn
*mem_calloc
);
344 void *memcached_get_user_data(memcached_st
*ptr
);
346 void *memcached_set_user_data(memcached_st
*ptr
, void *data
);
349 memcached_return_t
run_distribution(memcached_st
*ptr
);
351 #define memcached_is_allocated(__object) ((__object)->options.is_allocated)
352 #define memcached_is_initialized(__object) ((__object)->options.is_initialized)
359 #endif /* __MEMCACHED_H__ */