Return value of add
mama
lailingmist at googlemail.com
Wed Aug 30 20:35:47 UTC 2006
On Wed, 2006-08-30 at 18:11 +0200, mama wrote:
> 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
>
>
Sorry, after checking the code, add in fact returns the right return
value, false for failure and true for success.
In my case it returned 0 not because the key was already used, but
because it wasn't connected, my fault.
Sorry for the inconvenience.
More information about the memcached
mailing list