MEMCACHED_SERVER_LIST(3)
๐ MEMCACHED_SERVER_LIST ๐
okay so bestie, welcome to memcached_server_list from libmemcached-awesome (that's the MEMCACHED_SERVER_LIST(3) page, third section, we're in library land โจ). this is the whole vibe of managing your little roster of memcached servers. pull up a chair, grab a boba, let's go ๐ง
๐ฆ SYNOPSIS ๐ฆ
#include <libmemcached/memcached.h>
๐ Compile and link with -lmemcached โ don't forget this or nothing works and you'll be sad, no cap.
uint32_t memcached_server_count(memcached_st *ptr)
Parameters
ptrโ pointer to initializedmemcached_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 initializedmemcached_ststructhostnameโ hostname or IP address of the TCP server to addportโ port of the TCP server
Returns
memcached_return_tindicating success โจ
memcached_return_t memcached_server_add_udp(memcached_st *ptr, const char *hostname, in_port_t port)
Parameters
ptrโ pointer to initializedmemcached_ststructhostnameโ hostname or IP address of the UDP server to addportโ port of the UDP server
Returns
memcached_return_tindicating success โจ
memcached_return_t memcached_server_add_unix_socket(memcached_st *ptr, const char *socket)
Parameters
ptrโ pointer to initializedmemcached_ststructsocketโ path to the UNIX socket of the server to add
Returns
memcached_return_tindicating success โจ
memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_server_st *list)
Parameters
ptrโ pointer to initializedmemcached_ststructlistโ pre-configured list of servers to push
Returns
memcached_return_tindicating 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 initializedmemcached_ststructkeyโ key to hash and lookup a serverkey_lengthโ length of key without any terminating zeroerrorโ pointer tomemcached_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 initializedmemcached_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 initializedmemcached_ststructcallbackโ list ofmemcached_server_fnto be called for each server instancecontextโ pointer to user supplied context for the callbacknumber_of_callbacksโ number of callbacks supplied
Returns
memcached_return_tindicating 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_ststruct
Param server
- pointer to
memcached_instance_st
Param context
- pointer to user supplied context
Returns
memcached_return_tindicating success โจ
๐ DESCRIPTION ๐
so here's the tea, bestie: libmemcached does its operations on a list of hosts, and the order of those hosts is literally what decides routing to keys. yes, order matters, it's giving very main character energy. there are functions provided to add keys to memcached_st structures. and if you wanna mess with lists of servers themselves, go look at memcached_server_st ๐ซถ
memcached_server_count() hands you a count of the current number of servers being used by a memcached_st structure. simple, iconic, no notes.
memcached_server_add() pushes a single TCP server into the memcached_st structure, and it gets placed at the end (back of the line, respectfully). duplicate servers are allowed โ so like, nobody checks for duplication, it's not that kind of party. โ ๏ธ but heads up: if you execute this function with the MEMCACHED_BEHAVIOR_USE_UDP behavior set, you get a MEMCACHED_INVALID_HOST_PROTOCOL. pick a lane, babe.
memcached_server_add_udp() pushes a single UDP server into the memcached_st structure. also placed at the end. also allows duplicates, also checks nothing. โ ๏ธ and the flip side: executing this one without setting the MEMCACHED_BEHAVIOR_USE_UDP behavior results in a MEMCACHED_INVALID_HOST_PROTOCOL. the two functions are literally mirror opposites, it's giving twins ๐
memcached_server_add_unix_socket() pushes a single UNIX socket into the memcached_st structure. yep, it goes at the end. yep, duplicates allowed, yep, not checked. ๐ one thing though: the length of the filename must be one character less than MEMCACHED_MAX_HOST_LENGTH. count your characters, queen.
memcached_server_push() pushes an array of memcached_server_st into the memcached_st structure. servers go at the end, duplicates allowed, duplication not checked โ you know the drill by now. ๐ฅ and important: a copy is made of the structure, so the list you provided (and any operations you do on that list afterwards) are not saved. it's a copy, not a link, periodt.
memcached_server_by_key() lets you hand over a key and get back the server that would be used for assignment. it's giving "who's gonna handle this one" ๐ฎ
memcached_server_get_last_disconnect() returns a pointer to the last server that had a connection problem. ๐ฉบ and listen, this does not mean that particular server is currently dead โ but if the library is reporting that some server is, then the returned server is a very good candidate. like, prime suspect energy.
memcached_server_cursor() takes a memcached_st and loops through the list of hosts currently in the cursor, calling the list of callback functions you provided. you can optionally pass in a value via context, which gets handed to each callback function. ๐ an error return from any callback will terminate the loop. also memcached_server_cursor() is passed the original caller memcached_st in its current state.
โญ RETURN VALUE โญ
Varies, see particular functions. (yes that's the whole thing, it's a choose-your-own-adventure situation, iykyk ๐)
๐ SEE ALSO ๐
and that's the whole page bestie!! ๐ this was libmemcached-awesome version 1.1, dated Jul 24, 2025, and honestly? she ate. go forth and configure your servers, you've got this ๐โจ๐ธ
๐ฆ 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