MEMCACHED_RESULT_KEY_VALUE(3)
π MEMCACHED_RESULT_KEY_VALUE π
okay bestie, welcome to libmemcached-awesome, section 3 of the manual β this is the one about working with result sets, and honestly? it's giving organized. π
β¨ NAME β¨
memcached_result_key_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_st *memcached_result_create(memcached_st *ptr,
memcached_result_st *result)
void memcached_result_free(memcached_result_st *result)
const char *memcached_result_key_value(memcached_result_st *result)
size_t memcached_result_key_length(const memcached_result_st *result)
const char *memcached_result_value(memcached_result_st *result)
char *memcached_result_take_value(memcached_result_st *result)
size_t memcached_result_length(const memcached_result_st *result)
uint32_t memcached_result_flags(const memcached_result_st *result)
uint64_t memcached_result_cas(const memcached_result_st *result)
memcached_return_t memcached_result_set_value(memcached_result_st
*result, const char *value, size_t length)
void memcached_result_set_flags(memcached_result_st *result, uint32_t
flags)
void memcached_result_set_expiration(memcached_result_st *result, time_t
expiration)
π DESCRIPTION π
okay so libmemcached can optionally hand you back a memcached_result_st, which is literally just a lil result object, and it's lowkey the main character. π«Ά why is it better than those plain character-pointer return values? because result objects are forward compatible with new return items that future memcached servers might implement β the best current example of this being the CAS return item, iykyk. plus they can be reused, which saves you calls to malloc(3). so yeah, the suggestion is right there: use result objects over char * return functions. periodt. π
the structure of memcached_result_st has been encapsulated, bestie β do NOT write code directly accessing members of the structure. we don't do that here. π
π§ the functions, one by one π§
β¨ memcached_result_create()
either allocates memory for a memcached_result_st or initializes a structure you pass in. your choice, no pressure. π
Parameters
ptrβ pointer to initializedmemcached_ststructresultβ pointer to anmemcached_result_stinstance to initialize, ornullptrto allocate a new instance
Returns
pointer to initialized memcached_result_st instance β¨
β¨ memcached_result_free()
deallocates any memory attached to the structure. and if the structure itself was also allocated? bestie, it deallocates that too. full cleanup, no crumbs. π§Ή
Parameters
resultβ pointer to initializedmemcached_result_ststruct
β¨ memcached_result_key_value()
returns the key value associated with the current result object. π
Parameters
resultβ pointer to initializedmemcached_result_ststruct
Returns
the key value associated with the current result object
β¨ memcached_result_key_length()
returns the key length associated with the current result object. π
Parameters
resultβ pointer to initializedmemcached_result_ststruct
Returns
the key length associated with the current result object
β¨ memcached_result_value()
returns the result value associated with the current result object. π
Parameters
resultβ pointer to initializedmemcached_result_ststruct
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. like, it's yours now, it's not the object's problem anymore.
β οΈ 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 cap, don't forget or it's a leak bestie. π
Parameters
resultβ pointer to initializedmemcached_result_ststruct
Returns
the result value associated with the current result object
β¨ memcached_result_length()
returns the result length associated with the current result object. π
Parameters
resultβ pointer to initializedmemcached_result_ststruct
Returns
the result length associated with the current result object
β¨ memcached_result_flags()
returns the flags associated with the current result object. π©
Parameters
resultβ pointer to initializedmemcached_result_ststruct
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. if it doesn't, don't come crying to me. π
Parameters
resultβ pointer to initializedmemcached_result_ststruct
Returns
the cas associated with the current result object
β¨ memcached_result_set_value()
takes a byte array and a size and sets the result to this value. this one's used for trigger responses. π―
Parameters
resultβ pointer to initializedmemcached_result_ststructvalueβ byte array to set the value of the current result object tolengthβ the length ofvalue, without any terminating zero
Returns
memcached_return_t indicating success
β¨ memcached_result_set_flags()
takes a result structure and stores a new value for the flags field. π
Parameters
resultβ pointer to initializedmemcached_result_ststructflagsβ a new value for theflagsfield
β¨ memcached_result_set_expiration()
takes a result structure and stores a new value for the expiration field (this is only used by read through triggers). β°
Parameters
resultβ pointer to initializedmemcached_result_ststructexpirationβ a new value for theexpirationfield
π«Ά RETURN VALUE π«Ά
varies, bestie β see the particular functions. π
but here's the thing 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. that's not a vibe. that's not the vibe at all. π
π¦ SEE ALSO π¦
and that's the whole page, angel! π this was libmemcached-awesome, version 1.1, dated Jul 24, 2025 β go forth and manage your result objects responsibly, 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