I'm looking at the standard memcached documentation:

http://github.com/memcached/memcached/blob/master/doc/protocol.txt

<http://github.com/memcached/memcached/blob/master/doc/protocol.txt>"Note
that underflow in the "decr" command is caught: if a client tries

to decrease the value below 0, the new value will be 0.  Overflow in
the "incr" command will wrap around the 64 bit mark."


I'm not sure why our version of memcached behaves the way it does. I suspect
it has to do with storing numbers as either signed or unsigned ints
depending on what you first set the value to, with unsigned ints being the
90% case.

When in doubt, use the solution that results in the least confusion. And
document.

On Tue, Apr 6, 2010 at 9:09 AM, Nacho Coloma <[email protected]> wrote:

> Hi all,
>
> I am trying to use memcache.increment to move to negative values,
> starting at 0. According to the javadoc[1]:
>
> "To facilitate use as an atomic countdown, incrementing by a negative
> value (i.e. decrementing) will not go below zero: incrementing 2 by -5
> will return 0, not -3. However, due to the way numbers are stored,
> decrementing -3 by -5 will result in -8; so the zero-floor rule only
> applies to decrementing numbers that were positive."
>
> What is the rationale behind this, and why is 0 considered positive? I
> may have missed something, but I did not understand a similar behavior
> in python's memcache.decr() docs. If my counter can hold positive or
> negative values, what options do I have apart from initializing at
> 2^30?
>
> -- Nacho
>
> [1]
>
> http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/memcache/MemcacheService.html#increment(java.lang.Object,%20long)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>


-- 
Ikai Lan
Developer Programs Engineer, Google App Engine
http://googleappengine.blogspot.com | http://twitter.com/app_engine

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to