Lookups returning wrong data?

Andy Powell andy at automated.it
Wed Feb 16 09:35:50 PST 2005

On 16/02/2005 at 07:56 John McCaskey wrote:
>This sounds like when you are making the mc_set() and mc_req_add() calls
>you are passing an incorrect key_len value causing only the first part
>of the key to get used... I'd check to make sure that's not the case.
>Apart from that I can't think of any other reason this should be

Found the problem, I was testing using some of the code from the regress.c 
in the libmemcache tarball. That uses MCM_CSTRLEN(varname) for the key 
length, as soon as I changed it to strlen(varname) the problem went away :D

>As for this part, with the way you are doing a check if it is set, then
>add, or replace you could have a race condition with 2 processes or 2
>threads checking at the same time, both finding it not set, then both
>trying to add.  One of them failing.
>In general this check, then add or replace is a wasteful way to do
>things.  The set() command does an add if the key doesn't exist, or a
>replace if it does and should never fail like this.  I'd use it instead.

Ok, I've changed it to use 'set' and this has cured the problem. I didn't
actually spot the set option until you mentioned it, which was the only
reason I was testing for the existance of the key... 

Many thanks John, all problems solved :D


More information about the memcached mailing list