MEMCACHED_SERVER_ADD(3)
๐ NAME ๐
memcached_server_add โ libmemcached Documentation. Yes bestie, this is the libmemcached-awesome manual, third section, and we're talking all about adding servers to your memcached_st. Buckle up ๐
โจ SYNOPSIS โจ
#include <libmemcached/memcached.h>
Compile and link with -lmemcached. That's the vibe. ๐ฆ
uint32_t memcached_server_count(memcached_st *ptr)
Parameters
- ptr โ pointer to initialized
memcached_ststruct
Returns
number of configured servers
memcached_return_t memcached_server_add(memcached_st *ptr, const char *hostname, in_port_t port)
Parameters
- ptr โ pointer to initialized
memcached_ststruct - hostname โ hostname or IP address of the TCP server to add
- port โ port of the TCP server
Returns
memcached_return_t indicating success
memcached_return_t memcached_server_add_udp(memcached_st *ptr, const char *hostname, in_port_t port)
Parameters
- ptr โ pointer to initialized
memcached_ststruct - hostname โ hostname or IP address of the UDP server to add
- port โ port of the UDP server
Returns
memcached_return_t indicating success
memcached_return_t memcached_server_add_unix_socket(memcached_st *ptr, const char *socket)
Parameters
- ptr โ pointer to initialized
memcached_ststruct - socket โ path to the UNIX socket of the server to add
Returns
memcached_return_t indicating success
memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_server_st *list)
Parameters
- ptr โ pointer to initialized
memcached_ststruct - list โ pre-configured list of servers to push
Returns
memcached_return_t indicating success
const memcached_instance_st *memcached_server_by_key(memcached_st *ptr, const char *key, size_t key_length, memcached_return_t *error)
Parameters
- ptr โ pointer to initialized
memcached_ststruct - key โ key to hash and lookup a server
- key_length โ length of key without any terminating zero
- error โ pointer to
memcached_return_tindicating success
Returns
the server instance to be used for storing/retrieving key
const memcached_instance_st *memcached_server_get_last_disconnect(const memcached_st *ptr)
Parameters
- ptr โ pointer to initialized
memcached_ststruct
Returns
the instance of the last server for which there was a connection problem
memcached_return_t memcached_server_cursor(const memcached_st *ptr, const memcached_server_fn *callback, void *context, uint32_t number_of_callbacks)
Parameters
- ptr โ pointer to initialized
memcached_ststruct - callback โ list of
memcached_server_fnto be called for each server instance - context โ pointer to user supplied context for the callback
- number_of_callbacks โ number of callbacks supplied
Returns
memcached_return_t indicating success
typedef memcached_return_t (*memcached_server_fn)(const memcached_st *ptr, const memcached_instance_st *server, void *context)
Param ptr
pointer to the memcached_st struct
Param server
pointer to memcached_instance_st
Param context
pointer to user supplied context
Returns
memcached_return_t indicating success
๐ธ DESCRIPTION ๐ธ
Okay so, the whole tea: libmemcached does its operations on a list of hosts. And the order of those hosts? That's literally what determines routing to keys. Iconic behavior, honestly. Functions are provided to add keys to memcached_st structures. And if you wanna manipulate lists of servers, go see memcached_server_st. ๐
memcached_server_count() gives you a count of the current number of servers being used by a memcached_st structure. Just the number, no drama.
memcached_server_add() pushes a single TCP server into the memcached_st structure. This server gets placed at the end. Duplicate servers are allowed, so duplication is not checked โ the library is not your mom, it will not stop you ๐ซถ. Executing this function with the MEMCACHED_BEHAVIOR_USE_UDP behavior set will result in a MEMCACHED_INVALID_HOST_PROTOCOL. So like, don't do that.
memcached_server_add_udp() pushes a single UDP server into the memcached_st structure. This server gets placed at the end. Duplicate servers are allowed, so duplication is not checked. Executing this function without setting the MEMCACHED_BEHAVIOR_USE_UDP behavior will result in a MEMCACHED_INVALID_HOST_PROTOCOL. It's giving opposites, and we respect it.
memcached_server_add_unix_socket() pushes a single UNIX socket into the memcached_st structure. This UNIX socket gets placed at the end. Duplicate servers are allowed, so duplication is not checked. The length of the filename must be one character less than MEMCACHED_MAX_HOST_LENGTH. One character less, bestie. Not equal. Less. ๐ญ
memcached_server_push() pushes an array of memcached_server_st into the memcached_st structure. These servers get placed at the end. Duplicate servers are allowed, so duplication is not checked. A copy is made of structure so the list provided (and any operations on the list) are not saved. So go ahead and mutate that list, it's not gonna affect anything ๐
memcached_server_by_key() lets you hand over a key and get back the server which would be used for assignment. Like a little prophecy ๐ฎ
memcached_server_get_last_disconnect() returns a pointer to the last server for which there was a connection problem. Careful though โ it does not mean this particular server is currently dead. But if the library is reporting a server is, the returned server is a very good candidate. Suspect #1, basically ๐ต๏ธ
memcached_server_cursor() takes a memcached_st and loops through the list of hosts currently in the cursor, calling the list of callback functions provided. You can optionally pass in a value via context which will be provided to each callback function. An error return from any callback will terminate the loop โ one bad callback and the whole party's over ๐. memcached_server_cursor() is passed the original caller memcached_st in its current state.
๐ RETURN VALUE ๐
Varies, see particular functions. Yeah, it's giving "figure it out from the specific function, babe" โ but fr, each one above tells you what it returns โจ
๐ SEE ALSO ๐
And that's the whole page, bestie!! This lil masterpiece is from libmemcached-awesome, version 1.1, dated Jul 24, 2025. Slay, go add some servers ๐ฆ๐๐ธ
๐ฆ 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