MEMCACHED_RESULT_CAS(3)

πŸ’– MEMCACHED_RESULT_CAS(3) πŸ’–

okay so bestie, welcome to the libmemcached-awesome page for memcached_result_cas β€” it's giving "result sets, but make it a whole thing" ✨. Stay with me, this one has twelve functions and every single one of them is important, no skipping πŸ’…


✨ NAME ✨

memcached_result_cas β€” 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 an initialized memcached_st struct
  • result β€” pointer to a memcached_result_st instance you want it to initialize, or nullptr if you'd rather it allocate a brand new instance for you πŸ‘‘

Returns

a pointer to the initialized memcached_result_st instance, slay


🧚 memcached_result_free

void memcached_result_free(memcached_result_st *result)

Parameters

  • result β€” pointer to an initialized memcached_result_st struct

πŸ¦‹ memcached_result_key_value

const char *memcached_result_key_value(memcached_result_st *result)

Parameters

  • result β€” pointer to an 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 an 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 an 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 an 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 an 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 an 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 an 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 an 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

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

πŸ’« DESCRIPTION πŸ’«

okay so here's the tea β˜• β€” libmemcached can optionally hand you back a memcached_result_st, which is basically a whole result object. and bestie, these result objects have added benefits over the plain character pointer return values:

  • they're forward compatible with new return items that future memcached servers might implement (the best current example of this? literally the CAS return item, iconic)
  • the structures can also be reused, which saves you calls to malloc(3)

so yeah, it's suggested that you use result objects over char * return functions. do it for the plot 🫢

the structure of memcached_result_st has been encapsulated, so do not write code that directly accesses members of the structure. hands off the merch, bestie πŸ™ˆ


memcached_result_create() will either allocate memory for a memcached_result_st, or initialize a structure that you passed in. either way, she's ready πŸ’…

memcached_result_free() will deallocate any memory attached to the structure. and if the structure was also allocated (like, by create), it will deallocate that too. full clean-up, 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.

⚠️ bestie listen β€” 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, that means you have to create your own custom free() to release it. no cap, this one is on you.

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 tho β€” this value will only be available if the server tests it πŸ‘€

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, bestie β€” see the particular functions. but the one thing that does not vary: all structures must have memcached_result_free() called on them for cleanup purposes.

πŸ’€ failure to do this will result in leaked memory. and not the cute kind of leak. call the free function, i am begging πŸ™

πŸ”— SEE ALSO πŸ”—


and that's the whole page, bestie!! πŸŽ€ this was libmemcached-awesome version 1.1, dated Jul 24, 2025 β€” go forth, use result objects over char *, and free your structures. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from