You wrote too much code.  Libmemcached has a (documentation?) bug
that prevents you from using incement with initial unless you're using
the binary protocol.  If you switch to binary, it'll just work and you
can get rid of your race condition around initialization (you will
overwrite the value if you do this from concurrent clients).

  Otherwise, I'm sure Brian would be happy to get a patch implementing
memcached_increment_with_initial for the text protocol (which is
similar to what you're doing, but requires you to replace set with add
and potentially do a second increment).

  I made some changes to simplify it and add at least assertions for
error checking:  http://pastebin.com/16zvrMBg

On May 20, 3:52 am, ram <ramprasad...@gmail.com> wrote:
> Hello all
>
> I wrote a sample code.http://pastebin.com/jvq4T2UD
>
> Can you please review it for me
>
> ( I had made another post .. dont know why that has not appeared here.
> Sorry if this is duplicated )
>
> Thanks
> Ram
>
> On May 20, 12:05 am, Brian Aker <br...@tangent.org> wrote:
>
>
>
> > Hi!
>
> > I would suggest to look at tests/mem_function.c in the source tarsal. You 
> > may also want to look at the code in memcpy.c
>
> > There is also the man page "libmemcached_examples"
>
> > Cheers,
> >         -Brian
>
> > On May 17, 2010, at 8:23 AM, ram wrote:
>
> > > I am an absolute beginner with memcached & libmemcached ( a perl
> > > programmer by profession)
> > > I am trying to write a simple c  code that will do the foll algorithm
>
> > > ------------
> > > n = search_value_from_memcache(username);
> > > if(n) {
> > > increment_value_memcache(username)
> > > } else {
> > >   set_value_memcache(username,1);
> > > }
> > > -----------
>
> > > I am trying functions from
> > >http://docs.tangent.org/libmemcached/index.html
>
> > > but I couldnt functions simple enough to just get & put

Reply via email to