MEMCACHED_MGET_EXECUTE(3)
β¨ NAME β¨
okay so bestie, welcome to memcached_mget_execute β this is the libmemcached-awesome page all about retrieving data from the server. yes that's the whole name, we're keeping it short and sweet. π
π SYNOPSIS π
first things first, you gotta bring the header in and link the lib, no cap:
#include <libmemcached/memcached.h>
Compile and link with -lmemcached
and here's the whole squad of function signatures, verbatim, don't @ me:
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 π¦
okay so let's go one by one, i promise this is all gonna make sense. π«Ά
memcached_get() is your girl for pulling one single value out of the server. you hand her a key and the key's length, and that's how you fetch the object. you also gotta pass in three pointer variables so she can tell you what state the returned object is in:
- a
uint32_tpointer β this one holds whatever flags you stored alongside the value - a
size_tpointer β this gets filled in with the size of the object - a
memcached_return_tpointer β this one catches any error
on success you get the object back, on failure you get NULL. and listen β anything memcached_get() hands you must be released by the caller application. that's on you, bestie. π«‘
memcached_mget() is for when you wanna grab multiple keys at once. for multi-key operations this is always faster, like it's not even close. and heads up: this function always works asynchronously.
so after memcached_mget() runs successfully, how do you actually get the data? you call memcached_fetch_result(). keep calling it until it returns NULL (that's the "no more values, we're done here" signal). and if you need to bail out halfway through a memcached_mget() call, you can run a memcached_quit() β though honestly it's not required.
memcached_fetch_result() pulls an individual value from the server. rule of thumb: memcached_mget() must always be called before you use this method. you pass in a key and its length to fetch the object, and you supply those same three pointer variables for the state of the returned object:
- a
uint32_tpointer for the flags you stored with the value - a
size_tpointer that gets filled with the size of the object - a
memcached_return_tpointer to hold any error
object comes back on success, NULL comes back on failure. MEMCACHED_END is what you get in the *error value once all the objects that were found have been returned. and the final value at MEMCACHED_END is null.
also memcached_fetch_result() is what returns a memcached_result_st structure from a memcached server. that result object is forward compatible with changes to the server β for more info go peek at the memcached_result_st help. and if you don't pass a result structure in, this function will dynamically allocate one for you. generous queen. π
memcached_fetch_execute() is the callback version for result sets. instead of handing results back to you to process, it passes each result set straight to the list of functions you gave it. what does it hand your function?
- a
memcached_stthat can be cloned for use inside the called function β but it cannot be used directly - a result set that does not need to be freed
- a "context" β which is just a pointer to a memory reference that you, the caller, supply
currently only one value gets passed to each function call. in the future there'll be an option to let that be an array. future tea, we love to see it. π΅
memcached_mget_execute() and memcached_mget_execute_by_key() are basically memcached_mget() but with a glow-up: they may trigger the supplied callbacks with result sets while sending out the queries. why does that matter? because if you try to do a really large multiget with memcached_mget(), you might hit a deadlock in the OS kernel β it'll fail to write data to the socket because the input buffer is full. π memcached_mget_execute() fixes this by processing some of the results before it keeps sending out requests. and important: this function is only available in the binary protocol. periodt.
memcached_get_by_key() and memcached_mget_by_key() behave in a similar nature to memcached_get() and memcached_mget(). the difference? they take a master key (the group_key), which is used for determining which server an object was stored on if key partitioning was used for storage. iykyk. π§
β οΈ and now for the important disclaimer, bestie: all of the above functions are not tested whenMEMCACHED_BEHAVIOR_USE_UDPhas been set. if you execute any of these with that behavior turned on, you'll getMEMCACHED_NOT_SUPPORTEDreturned β or, for those functions that don't return amemcached_return_t, the error function parameter will be set toMEMCACHED_NOT_SUPPORTEDinstead. don't say i didn't warn you. π
πΈ RETURN VALUE πΈ
- every single object you retrieve via
memcached_get()ormemcached_get_by_key()must be freed withfree(3). no exceptions, free your memory, it's self care. π«Ά memcached_get()returnsNULLon error β and you must look at the value oferrorto figure out what the actual error was. don't just stare at theNULL, bestie.memcached_fetch_execute()returnsMEMCACHED_SUCCESSif all keys were successful.MEMCACHED_NOTFOUNDcomes back if no keys at all were found.memcached_fetch_result()setserrortoMEMCACHED_ENDupon successful conclusion. and again,MEMCACHED_NOTFOUNDgets returned if no keys at all were found.
π SEE ALSO π
go read these next, they're all part of the lore:
that's the whole page, you absolutely ate it. this was libmemcached-awesome version 1.1, dated Jul 24, 2025 β love that for us. now go free your objects and hydrate. πβ¨π
π¦ 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