MEMCACHED_RESULT_VALUE(3)
๐ MEMCACHED_RESULT_VALUE ๐
okay bestie, gather round, because this one is the page about result objects in libmemcached-awesome and honestly? it's giving organized. it's giving clean memory. it's giving "I free my structs because I respect myself". ๐
๐ธ NAME ๐ธ
memcached_result_value โ Working with result sets โจ
โจ SYNOPSIS โจ
#include <libmemcached/memcached.h>
Compile and link with -lmemcachedutil -lmemcached ๐ซถ
typedef struct memcached_result_st memcached_result_st
๐ memcached_result_create
memcached_result_st *memcached_result_create(memcached_st *ptr,
memcached_result_st *result)
Parameters
ptrโ pointer to initializedmemcached_ststructresultโ pointer to anmemcached_result_stinstance to initialize, ornullptrto allocate a brand new instance ๐ฑ
Returns
pointer to initialized memcached_result_st instance โ it's literally handing you the glow-up โจ
๐ฆ memcached_result_free
void memcached_result_free(memcached_result_st *result)
Parameters
resultโ pointer to initializedmemcached_result_ststruct
๐ memcached_result_key_value
const char *memcached_result_key_value(memcached_result_st *result)
Parameters
resultโ pointer to initializedmemcached_result_ststruct
Returns
the key value associated with the current result object ๐
๐ memcached_result_key_length
size_t memcached_result_key_length(const memcached_result_st *result)
Parameters
resultโ pointer to initializedmemcached_result_ststruct
Returns
the key length associated with the current result object ๐
๐ memcached_result_value
const char *memcached_result_value(memcached_result_st *result)
Parameters
resultโ pointer to initializedmemcached_result_ststruct
Returns
the result value associated with the current result object ๐
๐ง memcached_result_take_value
char *memcached_result_take_value(memcached_result_st *result)
Parameters
resultโ pointer to initializedmemcached_result_ststruct
Returns
the result value associated with the current result object ๐
โญ memcached_result_length
size_t memcached_result_length(const memcached_result_st *result)
Parameters
resultโ pointer to initializedmemcached_result_ststruct
Returns
the result length associated with the current result object ๐
๐ฅ memcached_result_flags
uint32_t memcached_result_flags(const memcached_result_st *result)
Parameters
resultโ pointer to initializedmemcached_result_ststruct
Returns
the flags associated with the current result object ๐ฉ
๐ซ memcached_result_cas
uint64_t memcached_result_cas(const memcached_result_st *result)
Parameters
resultโ pointer to initializedmemcached_result_ststruct
Returns
the cas associated with the current result object ๐
๐ธ memcached_result_set_value
memcached_return_t memcached_result_set_value(memcached_result_st
*result, const char *value, size_t length)
Parameters
resultโ pointer to initializedmemcached_result_ststructvalueโ byte array to set the value of the current result object tolengthโ the length ofvalue, wothout any terminating zero ๐ซ (yes, that's the original spelling and no, we are not touching it, it's iconic now)
Returns
memcached_return_t indicating success โ
๐ memcached_result_set_flags
void memcached_result_set_flags(memcached_result_st *result, uint32_t
flags)
Parameters
resultโ pointer to initializedmemcached_result_ststructflagsโ a new value for the flags field
๐ memcached_result_set_expiration
void memcached_result_set_expiration(memcached_result_st *result, time_t
expiration)
Parameters
resultโ pointer to initializedmemcached_result_ststructexpirationโ a new value for the expiration field โฐ
๐ซ DESCRIPTION ๐ซ
so here's the tea: libmemcached can optionally hand you back a memcached_result_st, which is basically a whole little result object, a main character with a whole personality. ๐ซถ
and bestie, these result objects have added benefits over just getting a character pointer back:
- they're forward compatible with new return items that future memcached servers might implement โ and the best current example of that? the CAS return item, periodt. ๐ฎ
- the structures can be reused, which saves you a whole bunch of calls to
malloc(3). recycling? we love her. โป๏ธ
It is suggested that you use result objects over char * return functions. like, genuinely, just do it. ๐
also: the structure of memcached_result_st has been encapsulated. do NOT write code that directly accesses members of the structure. it's not your business, it's not your moment, hands off the internals ๐
now the rundown, function by function:
memcached_result_create()will either allocate memory for amemcached_result_stor will initialize a structure passed to it. your call, bestie ๐ฑmemcached_result_free()will deallocate any memory attached to the structure. and if the structure was also allocated? it deallocates that too. full cleanup, no crumbs ๐งนmemcached_result_key_value()returns the key value associated with the current result object ๐memcached_result_key_length()returns the key length associated with the current result object ๐memcached_result_value()returns the result value associated with the current result object ๐memcached_result_take_value()returns and hands over the result value associated with the current result object. โ ๏ธ and listen: you must callfree(3)to release this value โ unless you've made use of a custom allocator. and if you're using a custom allocator, that requires you to create your own customfree()to release it. no skipping this step, that's how you get leaks ๐memcached_result_length()returns the result length associated with the current result object ๐memcached_result_flags()returns the flags associated with the current result object ๐ฉmemcached_result_cas()returns the cas associated with the current result object. โ ๏ธ heads up: this value will only be available if the server tests it. no server check, no cas, that's just the vibe ๐คทmemcached_result_set_value()takes a byte array and a size and sets the result to this value. this function is used for trigger responses ๐ฏmemcached_result_set_flags()takes a result structure and stores a new value for the flags fieldmemcached_result_set_expiration()takes a result structure and stores a new value for the expiration field โ and btw, this one is only used by read through triggers ๐
๐ซถ RETURN VALUE ๐ซถ
Varies, see particular functions โ every single one of these is its own little journey, iykyk โจ
but the one rule that applies to ALL of them: every structure must have memcached_result_free() called on it for cleanup purposes. Failure to do this will result in leaked memory. not a vibe, not a slay, not cute. call the free. ๐
๐ SEE ALSO ๐
that's the whole page bestie, you ate it, no cap. this one's from the libmemcached-awesome girlies, version 1.1, dated Jul 24, 2025 โ go forth and free your result structs ๐โจ๐๐ฆ
๐ฆ 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