[PATCH] "incr" supports wraparound

Evan Miller emiller at imvu.com
Fri Aug 17 00:06:02 UTC 2007

Currently Memcached gives an error when incrementing large counters:

set foobar 0 0 10
incr foobar 1
incr foobar 1
CLIENT_ERROR cannot increment or decrement non-numeric value

I believe this is a bug. Attached is a patch to make counters wrap
around the 2**32 mark, similar to counters in routers. New behavior:

set foobar 0 0 10
incr foobar 1
incr foobar 1

A CLIENT_ERROR will continue to be returned if a value above 2**32 is
incremented, but the "incr" command will never push the value over that

A future version of Memcached should probably use a 64-bit counter
instead, but the 32-bit limit is in line with the existing docs. ("The
data for the item is treated as decimal representation of a 32-bit
unsigned integer.")

The patch also adds "const" keywords to arguments of do_add_delta and
mt_add_delta, to be consistent with the header file.

Documentation and tests have been updated.

Evan Miller
IMVU, Inc.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: memcached-incr-wrap.patch
Type: text/x-patch
Size: 2833 bytes
Desc: not available
Url : http://lists.danga.com/pipermail/memcached/attachments/20070816/ecef33ba/memcached-incr-wrap.bin

More information about the memcached mailing list