libmemcache mc_get() Usage

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


Hi,

At 18:34 04/07/2007, Mdecandia wrote:
>I'm trying to use libmemcache C api to send and retrieve buffers from
>memcached.
>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 */
mc_req_free(req);

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

Hope that helps,

Jacques.

>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?
>
>Thanks,
>Michele
>
>
>  --
>  Email.it, the professional e-mail, gratis per te: http://www.email.it/f
>
>  Sponsor:
>  Pulire risparmiando tempo: una lavapavimenti e' l'ideale e i detergenti te
>li regaliamo noi
>  Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=6759&d=20070704



More information about the memcached mailing list