-
Notifications
You must be signed in to change notification settings - Fork 327
increment can't bigger than 4294967295 #58
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This is the result of an overflow. The value of 4294967296 (2^32) is just overflowing to 0. Incrementing by 4294967297 will result in an increment by 1. PHP-memcached is casting the offset value of the increment and decrement function to an unsigned int. This can be seen in the php_memcached.c file with the code below:
Fixing this is NOT as simple as just removing the cast from php_memcached.c. The memcached_increment function in libmemcached has a parameter called offset which is a uint32_t. This can be seen in the libmemcached file libmemcached/auto.cc with the code below:
You should probably file this issue with libmemcached. The function memcached_increment_by_key uses a uint64_t for the offset. It could be used by PHP-memcached instead but the API docs for libmemcached still list the offset parameter in memcached_increment_by_key as uint32_t. That can be seen here: |
Confirmed this is still a bug in 3.0.0 with PHP 7.0 and PHP 7.1. |
Ah, the value can be 64-bit, but the increment is limited to 32-bits per API call. The protocol does allow 64-bit increments, so it might only be an API issue in libmemcached: https://github.com/memcached/memcached/blob/master/doc/protocol.txt#L274 |
The problem still exists in the libmemcached: It is possible to work around this problem by replacing That would look something like this:
|
The documentation is mis-matched to the actual code! Yes, memcached_increment_by_key accepts a 64-bit offset. This should be straightforward to fix in the master branch. |
I can put together a PR if you want or you can take care of it if you want. |
Thanks for the offer! I've got it going in #306 |
$o = new Memcached();
$o->addServers( array(
array('127.0.0.1', 11211, 100)
));
$o->set('ddd', 0, 0);
$x = $o->increment('ddd', 4294967295); //OK
$x = $o->increment('ddd', 4294967296); //Error.
system is 64Bit.
The text was updated successfully, but these errors were encountered: