MEMCACHED(3)
π¦ NAME π¦
memcached β libmemcached Documentation
okay so bestie, welcome to MEMCACHED(3), straight out of the libmemcached-awesome manual π this is the page where we learn how to hand libmemcached a lil config string and get back a whole memcached_st object. it's giving "one string to rule them all". periodt.
π SYNOPSIS π
#include <libmemcached-1.0/memcached.h>
Compile and link with -lmemcached
memcached_st *memcached(const char *string, size_t string_length)
Parameters πΈ
- string β configuration string
- string_length β length of the configuration string without any terminating zero
Returns allocated and initialized memcached_st struct
memcached_return_t libmemcached_check_configuration(const char *option_string, size_t length, char *error_buffer, size_t error_buffer_size)
Parameters πΈ
- option_string β configuration string
- length β length of the configuration string without any terminating zero
- error_buffer β buffer used to store any error message
- error_buffer_size β available size of the error_buffer
Returns memcached_return_t indicating success
β¨ DESCRIPTION β¨
libmemcached implements a custom language for configuring and modifying servers. no cap. you hand it an option string, and boom β it generates a memcached_st object you can use in your application directly. iconic behaviour tbh π
π General Options:
--SERVER=<servername>:<optional_port>/?<optional_weight>β drop a servername for the client to use. if you also give a weight, weighting kicks in across all hosts, and every server starts out with a default weight of 1.--SOCKET=\"<filepath>/?<optional_weight>\"β give a filepath to a UNIX socket file 𧦠and yeah, same deal: providing a weight makes weighting happen across all hosts, with each server getting a default weight of 1.--VERIFY-KEYβ double-checks that the keys being used actually fit within the design of the protocol you're using. vibe check for your keys, fr fr.--REMOVE_FAILED_SERVERSβ turns on the behaviorMEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS.--BINARY-PROTOCOLβ forces all connections to use the binary protocol.--BUFFER-REQUESTSβ pls seeMEMCACHED_BEHAVIOR_BUFFER_REQUESTS.--CONFIGURE-FILE=β hands over a configuration file to be used to load requests. β οΈ beware bestie: by using a configuration file, libmemcached will resetmemcached_stbased on information only contained in the file. so like, everything else? gone. poof.--CONNECT-TIMEOUT=β seememcached_behavior_set()forMEMCACHED_BEHAVIOR_CONNECT_TIMEOUT.--DISTRIBUTION=β sets the distribution model the client uses. seememcached_behavior_set()for more details.--HASH=β sets the hashing algorithm used for placing keys on servers.--HASH-WITH-NAMESPACEβ when it's enabled, the prefix key gets added to the key when figuring out which server to store the data in.--NOREPLYβ enables "no reply" for all calls that support it. π highly recommended that you use this option with the binary protocol only, okay? just the binary protocol. that's the rule.--NUMBER-OF-REPLICAS=β sets how many servers keys will be replicated to.--RANDOMIZE-REPLICA-READβ picks the server to read from randomly within the replication pool.--SORT-HOSTSβ when adding new servers, always calculate their distribution based on sorted naming order.--SUPPORT-CASβ seememcached_behavior_set()forMEMCACHED_BEHAVIOR_SUPPORT_CAS--USE-UDPβ seememcached_behavior_set()forMEMCACHED_BEHAVIOR_USE_UDP--NAMESPACE=β a namespace is a container that provides context for keys; only other requests that know the namespace can access these values. it pulls this off by prepending the namespace value to all keys. so cute, so organized π
πΈ Memcached Pool Options:
--POOL-MINβ initial size of pool.--POOL-MAXβ maximize size of the pool.
π I/O Options:
--TCP-NODELAYβ seememcached_behavior_set()forMEMCACHED_BEHAVIOR_TCP_NODELAY--TCP-KEEPALIVEβ seememcached_behavior_set()forMEMCACHED_BEHAVIOR_TCP_KEEPALIVE--RETRY-TIMEOUT=β seememcached_behavior_set()forMEMCACHED_BEHAVIOR_RETRY_TIMEOUT--SERVER-FAILURE-LIMIT=β seememcached_behavior_set()forMEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT--SND-TIMEOUT=β seememcached_behavior_set()forMEMCACHED_BEHAVIOR_SND_TIMEOUT--SOCKET-RECV-SIZE=β seememcached_behavior_set()forMEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE--SOCKET-SEND-SIZE=β seememcached_behavior_set()forMEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE--POLL-TIMEOUT=β sets the timeout used bypoll(3).--IO-BYTES-WATERMARK=--IO-KEY-PREFETCH=--IO-MSG-WATERMARK=--TCP-KEEPIDLE--RCV-TIMEOUT=
π§ Other Options:
INCLUDEβ include a file in configuration. unlike--CONFIGURE-FILE=, this will not resetmemcached_st. bestie behaviour honestly.RESETβ resetmemcached_stand continue to process.ENDβ end configuration processing.ERRORβ end configuration processing and throw an error. π
π± ENVIRONMENT π±
LIBMEMCACHED
β RETURN VALUE β
memcached() returns a pointer to the memcached_st that was created (or initialized). on an allocation failure, it returns NULL. so like, always check, okay? don't be out here dereferencing NULL, i'm begging π
π₯ EXAMPLE π₯
const char *config_string=
"--SERVER=host10.example.com "
"--SERVER=host11.example.com "
"--SERVER=host10.example.com";
memcached_st *memc= memcached(config_string, strlen(config_string));
{
// ...
}
memcached_free(memc);
π SEE ALSO π
memcached(1) libmemcached(3) memcached_strerror(3)
and that's the whole page, bestie π this was libmemcached-awesome version 1.1, dated Jul 24, 2025, and yeah β it's still called MEMCACHED(3) π¦ slay, go configure some servers, ily, bye π
β¨
π¦ 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