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 initialized memcached_st struct
  • result β€” pointer to an memcached_result_st instance to initialize, or nullptr to 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 initialized memcached_result_st struct

✨ memcached_result_key_value()

returns the key value associated with the current result object. πŸ”‘

Parameters

  • result β€” pointer to initialized memcached_result_st struct

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 initialized memcached_result_st struct

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 initialized memcached_result_st struct

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 call free(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 custom free() to release it. no cap, don't forget or it's a leak bestie. πŸ’€

Parameters

  • result β€” pointer to initialized memcached_result_st struct

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 initialized memcached_result_st struct

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 initialized memcached_result_st struct

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 initialized memcached_result_st struct

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 initialized memcached_result_st struct
  • value β€” byte array to set the value of the current result object to
  • length β€” the length of value, 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 initialized memcached_result_st struct
  • flags β€” a new value for the flags field

✨ 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 initialized memcached_result_st struct
  • expiration β€” a new value for the expiration field

🫢 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