Memcac...ervers(3pm)

πŸ’– Memcac...ervers(3pm) πŸ’–

okay bestie, so this is a chunk of the User Contributed Perl Documentation for the <rainbow>Memcac...ervers</rainbow> section, and it's literally all about managing your server list. it's giving infrastructure queen energy and i'm obsessed. πŸ‘‘


✨ NAME ✨

memcached_server_count, memcached_server_list, memcached_server_add, memcached_server_push, memcached_server_get_last_disconnect, memcached_server_cursor β€” the whole squad that handles Manage server list. 🫢


πŸ“š LIBRARY πŸ“š

C Client Library for memcached (libmemcached, -lmemcached) β€” that's the C client, not the Perl one, don't get it twisted. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

here's the whole cast list, verbatim, no cap:

#include <memcached.h>

uint32_t memcached_server_count (memcached_st *ptr);

memcached_return_t
  memcached_server_add (memcached_st *ptr,
                        const char *hostname,
                        in_port_t port);

memcached_return_t
  memcached_server_add_udp (memcached_st *ptr,
                            const char *hostname,
                            in_port_t port);

memcached_return_t
  memcached_server_add_unix_socket (memcached_st *ptr,
                                    const char *socket);

memcached_return_t
  memcached_server_push (memcached_st *ptr,
                         const memcached_server_st *list);

memcached_server_instance_st
  memcached_server_by_key (const memcached_st *ptr,
                           const char *key,
                           size_t key_length,
                           memcached_return_t *error);

memcached_server_instance_st
  memcached_server_get_last_disconnect (const memcached_st *ptr)

memcached_return_t
  memcached_server_cursor(const memcached_st *ptr,
                          const memcached_server_fn *callback,
                          void *context,
                          uint32_t number_of_callbacks);

🌸 DESCRIPTION 🌸

so libmemcached(3) does its whole thing on a list of hosts, and the order of those hosts? that's literally what determines routing to keys. like, the lineup matters, bestie. πŸ“‹

there are functions here to add keys to memcached_st structures, and if you wanna manipulate lists of servers themselves, go look at memcached_server_st(3) instead. different vibe, different page. πŸ’«

  • memcached_server_count() β€” hands you the count of how many servers your memcached_st structure is currently using. a headcount. a lil census. πŸ”’
  • memcached_server_add() β€” pushes one single TCP server into the memcached_st structure, and it lands at the end. duplicate servers are allowed, so nothing's getting checked, no dedupe, sorry girl. and heads up: if you run this while the MEMCACHED_BEHAVIOR_USE_UDP behavior is set, you get a MEMCACHED_INVALID_HOST_PROTOCOL. pick a lane. 😭
  • memcached_server_add_udp() β€” same deal but UDP: pushes a single UDP server into the memcached_st structure, placed at the end, duplicates allowed, no checking. and the reverse gotcha: run this without setting the MEMCACHED_BEHAVIOR_USE_UDP behavior and you get MEMCACHED_INVALID_HOST_PROTOCOL. it's giving "you had one job". πŸ’€
  • memcached_server_add_unix_socket() β€” pushes a single UNIX socket into the memcached_st structure, at the end, duplicates allowed, not checked. one very specific rule tho: the filename length has to be one character less than MEMCACHED_MAX_HOST_LENGTH. count your characters, babe. 🧚
  • memcached_server_push() β€” this one yeets an array of memcached_server_st into the memcached_st structure, at the end, duplicates allowed, not checked. and here's the tea: a copy is made of the structure, so the list you handed over (and any operations you do on that list) are not saved. it's a snapshot, not a situationship. πŸ“Έ
  • memcached_server_by_key() β€” give it a key and it tells you which server would be used for assignment. the returned structure is cloned from its original, so you must free it. if NULL comes back, go consult *error. and free that returned structure with memcached_server_free(). free it. free it. 🫢
  • memcached_server_get_last_disconnect() β€” returns a pointer to the last server that had a connection problem. important nuance: this does not mean that particular server is currently dead β€” but if the library is reporting a server dead, the returned one is a very good candidate. prime suspect, not convicted. πŸ•΅οΈ
  • 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 a value in via context, and that gets handed to each callback function. if any callback returns an error, the loop is terminated, periodt. also: memcached_server_cursor() gets passed the original caller's memcached_st in its current state. πŸŒ€

πŸ”₯ RETURN πŸ”₯

Varies β€” go read the particular function you're nosy about. it's giving "results may vary". πŸ™ˆ


🏠 HOME 🏠

wanna find out more? go here, bestie: <https://launchpad.net/libmemcached>


πŸ‘‘ AUTHOR πŸ‘‘

Brian Aker, <brian@tangent.org> β€” the icon, the legend, the moment. ✨


🌈 SEE ALSO 🌈


and that's a wrap on the Memcac...ervers(3pm) page!! this lil doc came to you via perl v5.42.3 on 2026-08-19 β€” go forth and manage your servers, you absolute main character. no cap, ily. πŸ’…πŸ¦‹πŸ’–

πŸ“¦ where this page comes from