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 behavior MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS.
  • --BINARY-PROTOCOL β€” forces all connections to use the binary protocol.
  • --BUFFER-REQUESTS β€” pls see MEMCACHED_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 reset memcached_st based on information only contained in the file. so like, everything else? gone. poof.
  • --CONNECT-TIMEOUT= β€” see memcached_behavior_set() for MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT.
  • --DISTRIBUTION= β€” sets the distribution model the client uses. see memcached_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 β€” see memcached_behavior_set() for MEMCACHED_BEHAVIOR_SUPPORT_CAS
  • --USE-UDP β€” see memcached_behavior_set() for MEMCACHED_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 β€” see memcached_behavior_set() for MEMCACHED_BEHAVIOR_TCP_NODELAY
  • --TCP-KEEPALIVE β€” see memcached_behavior_set() for MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
  • --RETRY-TIMEOUT= β€” see memcached_behavior_set() for MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
  • --SERVER-FAILURE-LIMIT= β€” see memcached_behavior_set() for MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
  • --SND-TIMEOUT= β€” see memcached_behavior_set() for MEMCACHED_BEHAVIOR_SND_TIMEOUT
  • --SOCKET-RECV-SIZE= β€” see memcached_behavior_set() for MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
  • --SOCKET-SEND-SIZE= β€” see memcached_behavior_set() for MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
  • --POLL-TIMEOUT= β€” sets the timeout used by poll(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 reset memcached_st. bestie behaviour honestly.
  • RESET β€” reset memcached_st and 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