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

๐Ÿ’œ memcached_result_key_value

const char *memcached_result_key_value(memcached_result_st *result)

Parameters

  • result โ€” pointer to initialized memcached_result_st struct

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

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

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

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

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

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

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