MEMCACHED_RESULT_ST(3)
π MEMCACHED_RESULT_ST π
okay bestie, so this is a page from libmemcached-awesome, and it's all about the memcached_result_st girlies β result sets!! π if you've been raw-dogging char * returns this whole time, this is your sign to level up. let's get into it β¨
πΈ 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 an initializedmemcached_ststructresultβ pointer to amemcached_result_stinstance you want initialized, ornullptrif you'd rather it just allocate a brand new one for you π
Returns
pointer to the initialized memcached_result_st instance π«Ά
β¨ memcached_result_free
void memcached_result_free(memcached_result_st *result)
Parameters
resultβ pointer to an initializedmemcached_result_ststruct
β¨ memcached_result_key_value
const char *memcached_result_key_value(memcached_result_st *result)
Parameters
resultβ pointer to an 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 an 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 an 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 an 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 an 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 an 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 an 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 an initializedmemcached_result_ststructvalueβ byte array to set the value of the current result object tolengthβ the length ofvaluewithout any terminating zero
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 an 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 an initializedmemcached_result_ststructexpirationβ a new value for the expiration field
π¦ DESCRIPTION π¦
so libmemcached can optionally hand you back a memcached_result_st, which is literally just a result object, and it's the moment fr fr. why is it better than getting a plain character pointer back? okay so:
- it's forward compatible with new return items that future memcached servers might implement (the best current example of this is the CAS return item β¨)
- the structures can be reused, which saves you calls to
malloc(3)πΈ
so like, the suggestion is literally right there: use result objects over char * return functions. it's giving glow-up, no cap. π
β οΈ also important bestie β the structure of memcached_result_st has been encapsulated, so do NOT write code that directly accesses members of the structure. hands off the internals, okay?? π
memcached_result_create() will either allocate memory for a memcached_result_st, or it will initialize a structure you pass to it. your choice, main character π
memcached_result_free() will deallocate any memory attached to the structure. and if the structure itself was also allocated? yeah, it deallocates that too. clean sweep π§Ή
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. listen carefully though: you must call free(3) to release this value, unless you've made use of a custom allocator. and if you ARE using a custom allocator, then you're gonna need to create your own custom free() to release it. iykyk π
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. and heads up: this value will only be available if the server tests it. not always gonna show up for you, bestie π
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 field. π©
memcached_result_set_expiration() takes a result structure and stores a new value for the expiration field β and just so you know, this is only used by read through triggers. π°οΈ
π RETURN VALUE π
varies, see particular functions. but the one universal rule?? all structures must have memcached_result_free() called on them for cleanup purposes. failure to do this will result in leaked memory. not the vibe. do not skip it. periodt. π«Ά
π₯ SEE ALSO π₯
and that's the whole page babes!! π this was libmemcached-awesome version 1.1, dated Jul 24, 2025 β go forth and free your result structs, mwah πβ¨π¦
π¦ 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