1 ================================
2 Modifying how the driver behaves
3 ================================
14 C Client Library for memcached (libmemcached, -lmemcached)
25 #include <libmemcached/memcached.h>
28 memcached_behavior_get (memcached_st *ptr,
29 memcached_behavior flag);
32 memcached_behavior_set (memcached_st *ptr,
33 memcached_behavior flag,
43 libmemcached(3) behavior can be modified by use memcached_behavior_set().
44 Default behavior is the library strives to be quick and accurate. Some
45 behavior, while being faster, can also result in not entirely accurate
46 behavior (for instance, memcached_set() will always respond with
47 \ ``MEMCACHED_SUCCESS``\ ).
49 memcached_behavior_get() takes a behavior flag and returns whether or not
50 that behavior is currently enabled in the client.
52 memcached_behavior_set() changes the value of a particular option of the
53 client. It takes both a flag (listed below) and a value. For simple on or
54 off options you just need to pass in a value of 1. Calls to
55 memcached_behavior_set() will flush and reset all connections.
58 MEMCACHED_BEHAVIOR_USE_UDP
60 Causes libmemcached(3) to use the UDP transport when communicating
61 with a memcached server. Not all I/O operations are testsed
62 when this behavior is enababled. The following operations will return
63 \ ``MEMCACHED_NOT_SUPPORTED``\ when executed with the MEMCACHED_BEHAVIOR_USE_UDP
64 enabled: memcached_version(), memcached_stat(), memcached_get(),
65 memcached_get_by_key(), memcached_mget(), memcached_mget_by_key(),
66 memcached_fetch(), memcached_fetch_result(), memcached_value_fetch().
68 All other operations are testsed but are executed in a 'fire-and-forget'
69 mode, in which once the client has executed the operation, no attempt
70 will be made to ensure the operation has been received and acted on by the
73 libmemcached(3) does not allow TCP and UDP servers to be shared within
74 the same libmemached(3) client 'instance'. An attempt to add a TCP server
75 when this behavior is enabled will result in a \ ``MEMCACHED_INVALID_HOST_PROTOCOL``\ ,
76 as will attempting to add a UDP server when this behavior has not been enabled.
80 MEMCACHED_BEHAVIOR_NO_BLOCK
82 Causes libmemcached(3) to use asychronous IO. This is the fastest transport
83 available for storage functions.
87 MEMCACHED_BEHAVIOR_SND_TIMEOUT
89 This sets the microsecond behavior of the socket against the SO_SNDTIMEO flag.
90 In cases where you cannot use non-blocking IO this will allow you to still have
91 timeouts on the sending of data.
95 MEMCACHED_BEHAVIOR_RCV_TIMEOUT
97 This sets the microsecond behavior of the socket against the SO_RCVTIMEO flag.
98 In cases where you cannot use non-blocking IO this will allow you to still have
99 timeouts on the reading of data.
103 MEMCACHED_BEHAVIOR_TCP_NODELAY
105 Turns on the no-delay feature for connecting sockets (may be faster in some
110 MEMCACHED_BEHAVIOR_HASH
112 Makes the default hashing algorithm for keys use MD5. The value can be set
113 to either MEMCACHED_HASH_DEFAULT, MEMCACHED_HASH_MD5, MEMCACHED_HASH_CRC, MEMCACHED_HASH_FNV1_64, MEMCACHED_HASH_FNV1A_64, MEMCACHED_HASH_FNV1_32, MEMCACHED_HASH_FNV1A_32, MEMCACHED_HASH_JENKINS, MEMCACHED_HASH_HSIEH, and MEMCACHED_HASH_MURMUR.
114 Each hash has it's advantages and it's weaknesses. If you don't know or don't care, just go with the default.
115 Support for MEMCACHED_HASH_HSIEH is a compile time option that is disabled by default. To enable tests for this hashing algorithm, configure and build libmemcached with the --enable-hash_hsieh.
119 MEMCACHED_BEHAVIOR_DISTRIBUTION
121 Using this you can enable different means of distributing values to servers.
122 The default method is MEMCACHED_DISTRIBUTION_MODULA. You can enable
123 consistent hashing by setting MEMCACHED_DISTRIBUTION_CONSISTENT.
124 Consistent hashing delivers better distribution and allows servers to be
125 added to the cluster with minimal cache losses. Currently
126 MEMCACHED_DISTRIBUTION_CONSISTENT is an alias for the value
127 MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA.
131 MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
133 Memcached can cache named lookups so that DNS lookups are made only once.
137 MEMCACHED_BEHAVIOR_SUPPORT_CAS
139 Support CAS operations (this is not enabled by default at this point in the server since it imposes a slight performance penalty).
143 MEMCACHED_BEHAVIOR_KETAMA
145 Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
146 and the hash to MEMCACHED_HASH_MD5.
150 MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
152 Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA with the weighted tests.
153 and the hash to MEMCACHED_HASH_MD5.
157 MEMCACHED_BEHAVIOR_KETAMA_HASH
159 Sets the hashing algorithm for host mapping on continuum. The value can be set
160 to either MEMCACHED_HASH_DEFAULT, MEMCACHED_HASH_MD5, MEMCACHED_HASH_CRC, MEMCACHED_HASH_FNV1_64, MEMCACHED_HASH_FNV1A_64, MEMCACHED_HASH_FNV1_32, and MEMCACHED_HASH_FNV1A_32.
164 MEMCACHED_BEHAVIOR_KETAMA_COMPAT
166 Sets the compatibility mode. The value can be set to either
167 MEMCACHED_KETAMA_COMPAT_LIBMEMCACHED (this is the default) or
168 MEMCACHED_KETAMA_COMPAT_SPY to be compatible with the SPY Memcached client
173 MEMCACHED_BEHAVIOR_POLL_TIMEOUT
175 Modify the timeout value that is used by poll(). The default value is -1. An signed int pointer must be passed to memcached_behavior_set() to change this value. For memcached_behavior_get() a signed int value will be cast and returned as the unsigned long long.
179 MEMCACHED_BEHAVIOR_USER_DATA
181 This allows you to store a pointer to a specifc piece of data. This can be
182 retrieved from inside of memcached_fetch_execute(). Cloning a memcached_st
184 will copy the pointer to the clone. This was deprecated in 0.14 in favor
185 of memcached_callback_set(3). This will be removed in 0.15.
189 MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
191 Enabling buffered IO causes commands to "buffer" instead of being sent. Any
192 action that gets data causes this buffer to be be sent to the remote
193 connection. Quiting the connection or closing down the connection will also
194 cause the buffered data to be pushed to the remote connection.
198 MEMCACHED_BEHAVIOR_VERIFY_KEY
200 Enabling this will cause libmemcached(3) to test all keys to verify that they
205 MEMCACHED_BEHAVIOR_SORT_HOSTS
207 Enabling this will cause hosts that are added to be placed in the host list in
208 sorted order. This will defeat consisten hashing.
212 MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
214 In non-blocking mode this changes the value of the timeout during socket
219 MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
221 Enable the use of the binary protocol. Please note that you cannot toggle
222 this flag on an open connection.
226 MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
228 Set this value to enable the server be removed after continuous MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
229 times connection failure.
233 MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
235 Set this value to tune the number of messages that may be sent before
236 libmemcached should start to automatically drain the input queue. Setting
237 this value to high, may cause libmemcached to deadlock (trying to send data,
238 but the send will block because the input buffer in the kernel is full).
242 MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK
244 Set this value to tune the number of bytes that may be sent before
245 libmemcached should start to automatically drain the input queue (need
246 at least 10 IO requests sent without reading the input buffer). Setting
247 this value to high, may cause libmemcached to deadlock (trying to send
248 data, but the send will block because the input buffer in the kernel is full).
252 MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH
254 The binary protocol works a bit different than the textual protocol in
255 that a multiget is implemented as a pipe of single get-operations which
256 are sent to the server in a chunk. If you are using large multigets from
257 your application, you may improve the latency of the gets by setting
258 this value so you send out the first chunk of requests when you hit the
259 specified limit. It allows the servers to start processing the requests
260 to send the data back while the rest of the requests are created and
265 MEMCACHED_BEHAVIOR_NOREPLY
267 Set this value to specify that you really don't care about the result
268 from your storage commands (set, add, replace, append, prepend).
272 MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
274 If you just want "a poor mans HA", you may specify the numbers of
275 replicas libmemcached should store of each item (on different servers).
276 This replication does not dedicate certain memcached servers to store the
277 replicas in, but instead it will store the replicas together with all of the
278 other objects (on the 'n' next servers specified in your server list).
282 MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
284 Allows randomizing the replica reads starting point. Normally the read is
285 done from primary server and in case of miss the read is done from primary
286 + 1, then primary + 2 all the way to 'n' replicas. If this option is set
287 on the starting point of the replica reads is randomized between the servers.
288 This allows distributing read load to multiple servers with the expense of
293 MEMCACHED_BEHAVIOR_CORK
295 Enable TCP_CORK behavior. This is only available as an option Linux.
296 MEMCACHED_NO_SERVERS is returned if no servers are available to test with.
297 MEMCACHED_NOT_SUPPORTED is returned if we were not able to determine
298 if tests was available. All other responses then MEMCACHED_SUCCESS
299 report an error of some sort. This behavior also enables
300 MEMCACHED_BEHAVIOR_TCP_NODELAY when set.
304 MEMCACHED_BEHAVIOR_KEEPALIVE
306 Enable TCP_KEEPALIVE behavior.
310 MEMCACHED_BEHAVIOR_KEEPALIVE_IDLE
312 Specify time, in seconds, to mark a connection as idle. This is only available as an option Linux.
316 MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
318 Find the current size of SO_SNDBUF. A value of 0 means either an error
319 occured or no hosts were available. It is safe to assume system default
320 if this occurs. If an error occurs you can checked the last cached errno statement to find the specific error.
324 MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
326 Find the current size of SO_RCVBUF. A value of 0 means either an error
327 occured or no hosts were available. It is safe to assume system default
328 if this occurs. If an error occurs you can checked the last cached errno statement to find the specific error.
332 MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
334 This number of times a host can have an error before it is disabled.
338 MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
340 If enabled any hosts which have been flagged as disabled will be removed
341 from the list of servers in the memcached_st structure. This must be used
342 in combination with MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT.
346 MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
348 When enabled a host which is problematic will only be checked for usage
349 based on the amount of time set by this behavior.
353 MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY
355 When enabled the prefix key will be added to the key when determining
366 memcached_behavior_get() returns either the current value of the get, or 0
367 or 1 on simple flag behaviors (1 being enabled). memcached_behavior_set()
368 returns failure or success.
376 memcached_behavior_set() in version .17 was changed from taking a pointer
377 to data value, to taking a uin64_t.
385 To find out more information please check:
386 `https://launchpad.net/libmemcached <https://launchpad.net/libmemcached>`_
394 Brian Aker, <brian@tangent.org>
402 :manpage:`memcached(1)` :manpage:`libmemcached(3)` :manpage:`memcached_strerror(3)`