Add support for incr/decr with initial value
[awesomized/libmemcached] / libmemcached / memcached.h
1 /*
2 * Summary: interface for memcached server
3 * Description: main include file for libmemcached
4 *
5 * Copy: See Copyright for the status of this software.
6 *
7 * Author: Brian Aker
8 */
9
10 #ifndef __MEMCACHED_H__
11 #define __MEMCACHED_H__
12
13 #include <stdlib.h>
14 #include <inttypes.h>
15 #if !defined(__cplusplus)
16 # include <stdbool.h>
17 #endif
18 #include <sys/types.h>
19 #include <netinet/in.h>
20
21 #ifdef MEMCACHED_INTERNAL
22 #include <libmemcached/libmemcached_config.h>
23 #endif
24 #include <libmemcached/memcached_constants.h>
25 #include <libmemcached/memcached_types.h>
26 #include <libmemcached/memcached_watchpoint.h>
27 #include <libmemcached/memcached_get.h>
28 #include <libmemcached/memcached_server.h>
29 #include <libmemcached/memcached_string.h>
30 #include <libmemcached/memcached_result.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /* These are Private and should not be used by applications */
37 #define MEMCACHED_VERSION_STRING_LENGTH 24
38
39 /* string value */
40 struct memcached_continuum_item_st {
41 uint32_t index;
42 uint32_t value;
43 };
44
45 #define LIBMEMCACHED_VERSION_STRING "0.28"
46
47 struct memcached_analysis_st {
48 uint64_t most_used_bytes;
49 uint64_t least_remaining_bytes;
50 uint32_t average_item_size;
51 uint32_t longest_uptime;
52 uint32_t least_free_server;
53 uint32_t most_consumed_server;
54 uint32_t oldest_server;
55 double pool_hit_ratio;
56 };
57
58 struct memcached_stat_st {
59 uint32_t pid;
60 uint32_t uptime;
61 uint32_t threads;
62 uint32_t time;
63 uint32_t pointer_size;
64 uint32_t rusage_user_seconds;
65 uint32_t rusage_user_microseconds;
66 uint32_t rusage_system_seconds;
67 uint32_t rusage_system_microseconds;
68 uint32_t curr_items;
69 uint32_t total_items;
70 uint64_t limit_maxbytes;
71 uint32_t curr_connections;
72 uint32_t total_connections;
73 uint32_t connection_structures;
74 uint64_t bytes;
75 uint64_t cmd_get;
76 uint64_t cmd_set;
77 uint64_t get_hits;
78 uint64_t get_misses;
79 uint64_t evictions;
80 uint64_t bytes_read;
81 uint64_t bytes_written;
82 char version[MEMCACHED_VERSION_STRING_LENGTH];
83 };
84
85 struct memcached_st {
86 uint8_t purging;
87 bool is_allocated;
88 memcached_server_st *hosts;
89 uint32_t number_of_hosts;
90 uint32_t cursor_server;
91 int cached_errno;
92 uint32_t flags;
93 int send_size;
94 int recv_size;
95 int32_t poll_timeout;
96 int32_t connect_timeout;
97 int32_t retry_timeout;
98 memcached_result_st result;
99 memcached_hash hash;
100 memcached_server_distribution distribution;
101 void *user_data;
102 uint32_t continuum_count;
103 memcached_continuum_item_st *continuum;
104 memcached_clone_func on_clone;
105 memcached_cleanup_func on_cleanup;
106 memcached_free_function call_free;
107 memcached_malloc_function call_malloc;
108 memcached_realloc_function call_realloc;
109 memcached_trigger_key get_key_failure;
110 memcached_trigger_delete_key delete_trigger;
111 char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE];
112 size_t prefix_key_length;
113 memcached_hash hash_continuum;
114 uint32_t continuum_points_counter;
115 int32_t snd_timeout;
116 int32_t rcv_timeout;
117 uint32_t server_failure_limit;
118 uint32_t io_msg_watermark;
119 uint32_t io_bytes_watermark;
120 };
121
122
123 /* Public API */
124 const char * memcached_lib_version(void);
125
126 memcached_st *memcached_create(memcached_st *ptr);
127 void memcached_free(memcached_st *ptr);
128 memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr);
129
130 memcached_return memcached_delete(memcached_st *ptr, const char *key, size_t key_length,
131 time_t expiration);
132 memcached_return memcached_increment(memcached_st *ptr,
133 const char *key, size_t key_length,
134 uint32_t offset,
135 uint64_t *value);
136 memcached_return memcached_decrement(memcached_st *ptr,
137 const char *key, size_t key_length,
138 uint32_t offset,
139 uint64_t *value);
140 memcached_return memcached_increment_with_initial(memcached_st *ptr,
141 const char *key,
142 size_t key_length,
143 uint64_t offset,
144 uint64_t initial,
145 time_t expiration,
146 uint64_t *value);
147 memcached_return memcached_decrement_with_initial(memcached_st *ptr,
148 const char *key,
149 size_t key_length,
150 uint64_t offset,
151 uint64_t initial,
152 time_t expiration,
153 uint64_t *value);
154 void memcached_stat_free(memcached_st *, memcached_stat_st *);
155 memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return *error);
156 memcached_return memcached_stat_servername(memcached_stat_st *stat, char *args,
157 char *hostname, unsigned int port);
158 memcached_return memcached_flush(memcached_st *ptr, time_t expiration);
159 memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity);
160 void memcached_quit(memcached_st *ptr);
161 char *memcached_strerror(memcached_st *ptr, memcached_return rc);
162 memcached_return memcached_behavior_set(memcached_st *ptr, memcached_behavior flag, uint64_t data);
163 uint64_t memcached_behavior_get(memcached_st *ptr, memcached_behavior flag);
164 uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memcached_hash hash_algorithm);
165 memcached_return memcached_flush_buffers(memcached_st *mem);
166
167 /* Server Public functions */
168
169 memcached_return memcached_server_add_udp(memcached_st *ptr,
170 const char *hostname,
171 unsigned int port);
172 memcached_return memcached_server_add_unix_socket(memcached_st *ptr,
173 const char *filename);
174 memcached_return memcached_server_add(memcached_st *ptr, const char *hostname,
175 unsigned int port);
176
177 memcached_return memcached_server_add_udp_with_weight(memcached_st *ptr,
178 const char *hostname,
179 unsigned int port,
180 uint32_t weight);
181 memcached_return memcached_server_add_unix_socket_with_weight(memcached_st *ptr,
182 const char *filename,
183 uint32_t weight);
184 memcached_return memcached_server_add_with_weight(memcached_st *ptr, const char *hostname,
185 unsigned int port,
186 uint32_t weight);
187 void memcached_server_list_free(memcached_server_st *ptr);
188 memcached_return memcached_server_push(memcached_st *ptr, memcached_server_st *list);
189
190 memcached_server_st *memcached_server_list_append(memcached_server_st *ptr,
191 const char *hostname,
192 unsigned int port,
193 memcached_return *error);
194 memcached_server_st *memcached_server_list_append_with_weight(memcached_server_st *ptr,
195 const char *hostname,
196 unsigned int port,
197 uint32_t weight,
198 memcached_return *error);
199 unsigned int memcached_server_list_count(memcached_server_st *ptr);
200 memcached_server_st *memcached_servers_parse(const char *server_strings);
201
202 char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *stat,
203 const char *key, memcached_return *error);
204 char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *stat,
205 memcached_return *error);
206
207 memcached_return memcached_delete_by_key(memcached_st *ptr,
208 const char *master_key, size_t master_key_length,
209 const char *key, size_t key_length,
210 time_t expiration);
211
212 memcached_return memcached_fetch_execute(memcached_st *ptr,
213 memcached_execute_function *callback,
214 void *context,
215 unsigned int number_of_callbacks);
216
217 memcached_return memcached_callback_set(memcached_st *ptr,
218 memcached_callback flag,
219 void *data);
220 void *memcached_callback_get(memcached_st *ptr,
221 memcached_callback flag,
222 memcached_return *error);
223
224
225 #ifdef __cplusplus
226 }
227 #endif
228
229 #include <libmemcached/memcached_storage.h>
230
231 #endif /* __MEMCACHED_H__ */