MEMCACHED_BEHAVIOR_SET(3)
π NAME π
memcached_behavior_set β libmemcached Documentation
okay bestie so this whole page is about how to manipulate the behavior of a memcached_st structure. That's it, that's the job. You poke the settings on your client object and the client changes how it acts. Iconic. π
This is the manpage for memcached_behavior_set(3) from libmemcached-awesome, and heads up, it's a long one so we're doing it in parts. Strap in. π
πΈ SYNOPSIS πΈ
#include <libmemcached/memcached.h>
and, like, obviously:
Compile and link with -lmemcached
The two functions you're here for:
uint64_t memcached_behavior_get(memcached_st *ptr, memcached_behavior_t flag)
Parameters
ptrβ pointer to initializedmemcached_ststructflagβmemcached_behavior_tto query
Returns β the vaue set for flag (yes that's how the doc spells it, we're all just vibing β¨)
memcached_return_t memcached_behavior_set(memcached_st *ptr,
memcached_behavior_t flag,
uint64_t data)
Parameters
ptrβ pointer to initializedmemcached_ststructflagβmemcached_behavior_tto setdataβ the value to set forflag
Returns β memcached_return_t indicating success π«Ά
Changed in version 0.17: thedataargument ofmemcached_behavior_set()was changed from taking a pointer to data value, to taking auin64_t. (that's the doc's spelling, not mine, I promise π)
β¨ the typedef, then the whole enum β¨
typedef enum memcached_behavior_t memcached_behavior_t
enum memcached_behavior_t
This is the menu, bestie. Every flag you can set or get lives right here. π
- enumerator
MEMCACHED_BEHAVIOR_USE_UDPCauses libmemcached to use the UDP transport when communicating with a memcached server. Not all I/O operations are tested when this behavior is enabled.
The following operations will return MEMCACHED_NOT_SUPPORTED when executed with MEMCACHED_BEHAVIOR_USE_UDP enabled:
memcached_version(),memcached_stat(),memcached_get(),memcached_get_by_key(),memcached_mget(),memcached_mget_by_key(),memcached_fetch(),memcached_fetch_result(),memcached_fetch_execute().
All other operations are tested but are executed in a 'fire-and-forget' mode, in which once the client has executed the operation, no attempt will be made to ensure the operation has been received and acted on by the server.
libmemcached does not allow TCP and UDP servers to be shared within the same libmemcached client 'instance'. An attempt to add a TCP server when this behavior is enabled will result in a MEMCACHED_INVALID_HOST_PROTOCOL, as will attempting to add a UDP server when this behavior has not been enabled. π
- enumerator
MEMCACHED_BEHAVIOR_NO_BLOCKThis enablesSO_LINGERonly, so theclose(2)call on the socket returns immediately. I/O is always handled asynchronously in recent versions of libmemcached. - enumerator
MEMCACHED_BEHAVIOR_SND_TIMEOUTThis sets the microsecond behavior of the socket against theSO_SNDTIMEOflag. - enumerator
MEMCACHED_BEHAVIOR_RCV_TIMEOUTThis sets the microsecond behavior of the socket against theSO_RCVTIMEOflag. - enumerator
MEMCACHED_BEHAVIOR_TCP_NODELAYDisables Nagle's algorithm. See RFC 896. - enumerator
MEMCACHED_BEHAVIOR_HASHSet the hash algorithm used for keys.
Each hash has its advantages and its weaknesses. If you don't know or don't care, just go with the default. (main character advice honestly π)
- enumerator
MEMCACHED_BEHAVIOR_DISTRIBUTIONSetting amemcached_server_distribution_tyou can enable different means of distributing values to servers.
The default method is MEMCACHED_DISTRIBUTION_MODULA (hash of the key modulo number of servers).
You can enable consistent hashing by setting MEMCACHED_DISTRIBUTION_CONSISTENT. Consistent hashing delivers better distribution and allows servers to be added to the cluster with minimal cache losses.
Currently MEMCACHED_DISTRIBUTION_CONSISTENT is an alias for the value MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA.
- enumerator
MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
Deprecated since version 0.46(?): DNS lookups are now always cached until an error occurs with the server.
Memcached can cache named lookups so that DNS lookups are made only once.
- enumerator
MEMCACHED_BEHAVIOR_SUPPORT_CASSupport CAS operations (this is not enabled by default at this point in the server since it imposes a slight performance penalty). - enumerator
MEMCACHED_BEHAVIOR_KETAMASets the default distribution toMEMCACHED_DISTRIBUTION_CONSISTENT_KETAMAand the hash toMEMCACHED_HASH_MD5. - enumerator
MEMCACHED_BEHAVIOR_KETAMA_WEIGHTEDSets the default distribution toMEMCACHED_DISTRIBUTION_CONSISTENT_KETAMAwith the weighted tests. Makes the default hashing algorithm for keys useMEMCACHED_HASH_MD5. - enumerator
MEMCACHED_BEHAVIOR_KETAMA_HASHSets the hashing algorithm for host mapping on continuum. - enumerator
MEMCACHED_BEHAVIOR_KETAMA_COMPATSets the compatibility mode. The value can be set to eitherMEMCACHED_KETAMA_COMPAT_LIBMEMCACHED(this is the default) orMEMCACHED_KETAMA_COMPAT_SPYto be compatible with the SPY Memcached client for Java. - enumerator
MEMCACHED_BEHAVIOR_POLL_TIMEOUTModify the timeout in milliseconds value that is used by poll. The default value is-1. An signed int must be passed tomemcached_behavior_set()to change this value (this requires casting). Formemcached_behavior_get()a 'signed int' value will be cast and returned as 'unsigned long long'. - enumerator
MEMCACHED_BEHAVIOR_USER_DATA
Deprecated since version <: 0.30 (yes the doc literally prints <: there β we don't know either π)
- enumerator
MEMCACHED_BEHAVIOR_BUFFER_REQUESTSEnabling buffered IO causes commands to "buffer" instead of being sent. Any action that gets data causes this buffer to be be sent to the remote connection. Quiting the connection or closing down the connection will also cause the buffered data to be pushed to the remote connection. - enumerator
MEMCACHED_BEHAVIOR_VERIFY_KEYEnabling this will cause libmemcached to test all keys to verify that they are valid keys. - enumerator
MEMCACHED_BEHAVIOR_SORT_HOSTSEnabling this will cause hosts that are added to be placed in the host list in sorted order. This will defeat consistent hashing. - enumerator
MEMCACHED_BEHAVIOR_CONNECT_TIMEOUTSet the timeout during socket connection in milliseconds. Specifying-1means an infinite timeβout. - enumerator
MEMCACHED_BEHAVIOR_BINARY_PROTOCOLEnable the use of the binary protocol. Please note that you cannot toggle this flag on an open connection. - enumerator
MEMCACHED_BEHAVIOR_IO_MSG_WATERMARKSet this value to tune the number of messages that may be sent before libmemcached should start to automatically drain the input queue.
Setting this value to high, may cause libmemcached to deadlock (trying to send data, but the send will block because the input buffer in the kernel is full). π
- enumerator
MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARKSet this value to tune the number of bytes that may be sent before libmemcached should start to automatically drain the input queue (need at least 10 IO requests sent without reading the input buffer).
Setting this value to high, may cause libmemcached to deadlock (trying to send data, but the send will block because the input buffer in the kernel is full). π
- enumerator
MEMCACHED_BEHAVIOR_IO_KEY_PREFETCHThe binary protocol works a bit different than the textual protocol in that a multiget is implemented as a pipe of single get-operations which are sent to the server in a chunk.
If you are using large multigets from your application, you may improve the latency of the gets by setting this value so you send out the first chunk of requests when you hit the specified limit. It allows the servers to start processing the requests to send the data back while the rest of the requests are created and sent to the server. π¦
- enumerator
MEMCACHED_BEHAVIOR_NOREPLYSet this value to specify that you really don't care about the result from your storage commands (set,add,replace,append,prepend). (unbothered. moisturized. in my lane. β¨) - enumerator
MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICASSpecify the number of replicas libmemcached should store of each item (on different servers).
This replication does not dedicate certain memcached servers to store the replicas in, but instead it will store the replicas together with all of the other objects (on the 'n' next servers specified in your server list).
Requires the binary protocol and only supports (M)GET/SET/DELETE.
NOTE: libmemcached does not guarantee nor enforce any consistency.
- enumerator
MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READAllows randomizing the replica reads starting point. Normally the read is done from primary server and in case of failure the read is done from primary + 1, then primary + 2 all the way to 'n' replicas.
This allows distributing read load to multiple servers with the expense of more write traffic.
NOTE: Only errors to communicate with a server are considered failures, so MEMCACHED_NOTFOUND does not account for failure.
- enumerator
MEMCACHED_BEHAVIOR_CORKβ Deprecated since version ?: This option has been deprecated with the behavior now built in and used appropriately on selected platforms. she's retired, bestie π - enumerator
MEMCACHED_BEHAVIOR_KEEPALIVEβ EnableTCP_KEEPALIVEbehavior. keep those connections alive, periodt β¨ - enumerator
MEMCACHED_BEHAVIOR_KEEPALIVE_IDLEβ Specify time, in seconds, to mark a connection as idle. This is only available as an option on Linux. Linux girlies rise π§ - enumerator
MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZEβ Find the current size ofSO_SNDBUF. A value of0means either an error occurred or no hosts were available. It is safe to assume system default if this occurs.
If an error occurs you can check the last cached errno to find the specific error. detective mode activated π
- enumerator
MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZEβ Find the current size ofSO_RCVBUF. A value of0means either an error occurred or no hosts were available. It is safe to assume system default if this occurs.
If an error occurs you can check the last cached errno to find the specific error. same energy, receive side π
- enumerator
MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMITβ Deprecated since version 0.48: SeeMEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS
Set this value to enable the server be removed after continuous MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT times connection failure. old school, but we still list her π
- enumerator
MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTSβ Deprecated since version 0.48: SeeMEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS
If enabled any hosts which have been flagged as disabled will be removed from the list of servers in the memcached_st structure. This must be used in combination with MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT. combo move, fr fr
- enumerator
MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERSβ If enabled any hosts which have been flagged as disabled will be removed from the list of servers in thememcached_ststructure. bye felicia π - enumerator
MEMCACHED_BEHAVIOR_RETRY_TIMEOUTβ When enabled a host which is problematic will only be checked for usage based on the amount of time set by this behavior. The value is in seconds. patience is a virtue β³ - enumerator
MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEYβ When enabled the prefix key will be added to the key when determining server by hash. SeeMEMCACHED_CALLBACK_NAMESPACEfor additional information. hash girlies know π
okay and then there's this whole other enum situation, bestie:
typedef enum memcached_server_distribution_t
memcached_server_distribution_t
enum memcached_server_distribution_t
- enumerator
MEMCACHED_DISTRIBUTION_MODULAβ Distribute keys by hash modulo number of servers. math but make it fashion β¨ - enumerator
MEMCACHED_DISTRIBUTION_CONSISTENTβ Alias forMEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA. same vibe, different name - enumerator
MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMAβ Unweighted consistent key distribution. ketama said what she said - enumerator
MEMCACHED_DISTRIBUTION_RANDOMβ Distribute keys byrand(3)modulo number of servers. chaotic good π - enumerator
MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPYβ Unweighted consistent key distribution compatible with the SPY client. spy x family energy π΅οΈββοΈ - enumerator
MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTEDβ Weighted consistent key distribution. she got range π - enumerator
MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKETβ Consistent key distribution by virtual buckets. bucket list but make it servers πͺ£
β¨ DESCRIPTION β¨
libmemcached behavior can be modified by using memcached_behavior_set(). Default behavior is the library strives to be quick and accurate. Some behavior, while being faster, can also result in not entirely accurate behavior (for instance, memcached_set() will always respond with MEMCACHED_SUCCESS). so like, fast but maybe messy, iykyk
memcached_behavior_get() takes a behavior flag and returns whether or not that behavior is currently enabled in the client. she's just asking questions π
memcached_behavior_set() changes the value of a particular option of the client. It takes both a flag and a value. For simple on or off options you just need to pass in a value of 1. Calls to memcached_behavior_set() will flush and reset all connections. heads up: she will flush and reset ALL connections, no cap.
π RETURN VALUE π
memcached_behavior_get() returns either the current value of the key, or 0 or 1 on simple flag behaviors (1 being enabled). one means yes, bestie β
memcached_behavior_set() returns failure or success. simple as that, fr fr
π NOTES π
The data argument of memcached_behavior_set() was changed in version 0.17 from taking a pointer to data value, to taking a uin64_t. yes, it says uin64_t, not uint64_t, we don't make the rules π
π SEE ALSO π
kisses, your girl from the libmemcached 1.1 manual, dated Jul 24, 2025, for MEMCACHED_BEHAVIOR_SET(3) π«Άβ¨
π¦ where this page comes from
- fedora 43: libmemcached-awesome-devel 1.1.4-7.fc43 Β· BSD-3-Clause
- fedora 43: libmemcached-awesome-devel 1.1.4-7.fc43 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms