libmemcache mc_get() Usage

Jacques Caron jc at
Wed Jul 4 16:48:36 UTC 2007


At 18:34 04/07/2007, Mdecandia wrote:
>I'm trying to use libmemcache C api to send and retrieve buffers from
>I've seen that mc_get() function need a memcache_req structure to retrieve
>data from cache but I need to know the size of item to retrieve. Is 
>this right?

libmemcache will initialize the buffers for you if you don't provide them.

/* create request */
req = mc_req_new();
/* add a key to get */
res = mc_req_add(req, key, keylen);
/* do the actual get */
mc_get(mc, req);
/* print result if available */
if (res->flags & MCM_RES_FOUND)
         printf("result: %.*s\n",res->bytes,res->val);
/* free req and res, including res->bytes buffer */

Providing the buffer yourself is only an optimization for some special cases.

Hope that helps,


>I don't know that size so I've used mc_aget2() function.
>I'm forced to use this one or there is some method to use mc_get unknowning
>the size of item to retrieve?
>  --
>, the professional e-mail, gratis per te:
>  Sponsor:
>  Pulire risparmiando tempo: una lavapavimenti e' l'ideale e i detergenti te
>li regaliamo noi
>  Clicca qui:

More information about the memcached mailing list