MEMCACHED_FETCH_EXECUTE(3)
π MEMCACHED_FETCH_EXECUTE π
okay so hi bestie!! you found the page for memcached_fetch_execute β it lives in the libmemcached-awesome manual, section 3, and it's literally the whole vibe of "how do i get my data back out of the server" β¨ grab a snack, this one's a family reunion of functions π«Ά
πΈ NAME πΈ
memcached_fetch_execute β retrieving data from the server π
π SYNOPSIS π
#include <libmemcached/memcached.h>
and like, compile + link with:
-libmemcached
wait no, it's -lmemcached β typo era, we don't do that here π anyway. the whole squad of signatures:
memcached_result_st *memcached_fetch_result(memcached_st *ptr,
memcached_result_st *result, memcached_return_t *error)
char *memcached_get(memcached_st *ptr, const char *key, size_t
key_length, size_t *value_length, uint32_t *flags, memcached_return_t
*error)
memcached_return_t memcached_mget(memcached_st *ptr, const char *const
*keys, const size_t *key_length, size_t number_of_keys)
char *memcached_get_by_key(memcached_st *ptr, const char *group_key,
size_t group_key_length, const char *key, size_t key_length, size_t
*value_length, uint32_t *flags, memcached_return_t *error)
memcached_return_t memcached_mget_by_key(memcached_st *ptr, const char
*group_key, size_t group_key_length, const char *const *keys, const
size_t *key_length, size_t number_of_keys)
memcached_return_t memcached_fetch_execute(memcached_st *ptr,
memcached_execute_fn *callback, void *context, uint32_t
number_of_callbacks)
memcached_return_t memcached_mget_execute(memcached_st *ptr, const char
*const *keys, const size_t *key_length, size_t number_of_keys,
memcached_execute_fn *callback, void *context, uint32_t
number_of_callbacks)
memcached_return_t memcached_mget_execute_by_key(memcached_st *ptr,
const char *group_key, size_t group_key_length, const char *const *keys,
const size_t *key_length, size_t number_of_keys, memcached_execute_fn
*callback, void *context, uint32_t number_of_callbacks)
typedef memcached_return_t (*memcached_execute_fn)(const memcached_st
*ptr, memcached_result_st *result, void *context)
π¦ DESCRIPTION π¦
β¨ the getters β¨
memcached_get() is your girl for grabbing one single value off the server. you pass in a key and its length to fetch the object. you also gotta hand over three pointer variables so she can tell you the state of the returned object, and yes all three are mandatory, no skipping π
- a
uint32_tpointer β it holds whatever flags you stored alongside the value - a
size_tpointer β gets filled in with the size of the object - a
memcached_return_tpointer β holds any error
on success you get the object back π on failure you get NULL π and any object returned by memcached_get() has to be released by the caller application β that's you, bestie, that's your job, don't ghost it.
β¨ the multigetters β¨
memcached_mget() is the "select a bunch of keys at once" icon. for multiple key operations it is always faster to use this function β like, genuinely always, no cap. and she always works asynchronously, periodt. β‘
to actually retrieve data after a successful run of memcached_mget(), you're gonna need to call memcached_fetch_result(). keep calling it until it hands you a NULL (that's the signal for "no more values, we're done here"). and if you need to bail out in the middle of a memcached_mget() call, you can execute a memcached_quit() β though this is not required. do it for the drama if you want π§
β¨ fetch_result, the icon β¨
memcached_fetch_result() fetches an individual value from the server. memcached_mget() must always be called before you use this method β like, that's the prerequisite, that's the lore.
you must pass in a key and its length to fetch the object, and again you supply three pointer variables which will give you the state of the returned object:
- a
uint32_tpointer β containing whatever flags you stored with the value - a
size_tpointer β filled with the size of the object - a
memcached_return_tpointer β holding any error
the object comes back on success, NULL comes back on failure. MEMCACHED_END is returned by the *error value when all objects that have been found have been returned. and the final value upon MEMCACHED_END is null. π«
also β and this is the part people sleep on β memcached_fetch_result() is used to return a memcached_result_st structure from a memcached server. that result object is forward compatible with changes to the server π for more info pls refer to the memcached_result_st help. and if you don't pass one in? she will dynamically allocate a result structure for you. so generous, so main character. β¨
β¨ fetch_execute, the callback queen β¨
memcached_fetch_execute() is a callback function for result sets. instead of handing the results back to you for processing, she passes each of the result sets to the list of functions you provide. here's what each function call receives:
- a
memcached_stthat can be cloned for use in the called function β but it can not be used directly, ok? clone it, don't touch it π - a result set, which does not need to be freed π
- a
"context"β which is just a pointer to a memory reference you supply the calling function
currently only one value is being passed to each function call. in the future there will be an option to allow this to be an array. future tea β
β¨ mget_execute β¨
memcached_mget_execute() and memcached_mget_execute_by_key() are similar to memcached_mget(), but they may trigger the supplied callbacks with result sets while sending out the queries. why does that matter?? because if you try to perform a really large multiget with memcached_mget() you may encounter a deadlock in the OS kernel π± (it will fail to write data to the socket because the input buffer is full). memcached_mget_execute() solves this problem by processing some of the results before continuing to send out requests. slay
β οΈ pls note that this function is only available in the binary protocol. no binary protocol, no party.
β¨ the by_key duo β¨
memcached_get_by_key() and memcached_mget_by_key() behave in a similar nature as memcached_get() and memcached_mget(). the difference? they take a master key that is used for determining which server an object was stored on, if key partitioning was used for storage. that's it, that's the whole plot twist π₯
β¨ the UDP warning, listen up β¨
π all of the above functions are not tested whenMEMCACHED_BEHAVIOR_USE_UDPhas been set. executing any of these functions with this behavior on will result inMEMCACHED_NOT_SUPPORTEDbeing returned β or, for those functions which do not return amemcached_return_t, the error function parameter will be set toMEMCACHED_NOT_SUPPORTED. so like. don't. π
π RETURN VALUE π
- all objects retrieved via
memcached_get()ormemcached_get_by_key()must be freed withfree(3). free your friends, bestie π«Ά memcached_get()will returnNULLon error. you must look at the value of error to determine what the actual error was. she won't just tell you out loud, you gotta read the room.memcached_fetch_execute()returnsMEMCACHED_SUCCESSif all keys were successful.MEMCACHED_NOTFOUNDwill be returned if no keys at all were found. πmemcached_fetch_result()sets error toMEMCACHED_ENDupon successful conclusion.MEMCACHED_NOTFOUNDwill be returned if no keys at all were found. (yes, same energy. consistency is iconic.)
β SEE ALSO β
memcached(1) libmemcached(3) memcached_strerror(3)
and that's the page!! π this whole thing is from version 1.1, dated Jul 24, 2025 β so like, recent, fresh, and fully in her era. go forth and fetch responsibly, bestie πβ¨π¦
π¦ 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