Return value of add

mama lailingmist at googlemail.com
Wed Aug 30 16:11:34 UTC 2006


Hello,

I am trying to add an entry to a cache in perl.
As I don't want to overwrite another entry and the key is random I am
doing this: 

        our $counter = 1;
        sub get_new_entry
        {
                until( $cache->add( $counter, $foo ) ) {
                        $counter += int( rand 100 );
                }
                return $counter++;
        }
        
Well, this turns out to be a infinite loop, as add doesn't return any
value indicating success or failure. Well, so how can i solve this
problem without introducing any race conditions?

Thanks for your help





More information about the memcached mailing list