[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
2147483647
STORED
incr foobar 1
2147483648
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
4294967294
STORED
incr foobar 1
4294967295
incr foobar 1
0

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
mark.

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