initial incr call
Cahill, Earl
ecahill at corp.untd.com
Fri Mar 18 08:40:45 PST 2005
Probably been over this before, but the initial incr call seems kind of
strange to me. Let's say I have a new key called counter, and I want to
incr it. I call $memd->incr('counter'); and get undef back. So, I set it
to 0, and then if I call incr, happy day. The problem is that setting to 0
is a total race condition, so I have to do something like this
sub incr {
my $self = shift;
my $key = shift;
unless($self->get($key)) {
require File::NFSLock;
my $lock = File::NFSLock->new("$nfs_path/memcache.incr.$key",
"BLOCKING", 15, 10);
if($lock) {
$self->set($key, 0);
}
}
$self->SUPER::incr($key);
}
where you lock however you like. Maybe it's too late now, but it sure seems
like it would be nice if the server would some do similar thing. I would
like to just call incr, regardless of whether the key has existed before or
not, and get back either 1 for new values, or the old value plus one. Is
there a reason incr behaves as it does?
Earl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20050318/bdc9f627/attachment.htm
More information about the memcached
mailing list