Comments (6)
With decrement it's the same:
addServer('localhost', '11211'); $m->setOption(Memcached::OPT_BINARY_PROTOCOL, true); $key = uniqid('testIncrement'); assert($m->add($key, 7, 2) === true); // Adding value 7 assert($m->get($key) === 7); // Check right value was saved assert($m->decrement($key, 2) === 5); // Decrement to 5 Shows a warning in the last assert.from php-memcached.
We're experiencing the same issue here.
from php-memcached.
This is blocker for me - anyone have a workaround for this? If you do any operation before the increment/decrement it will always return -1:
php-memcached v2.1.0, libmemcached 1.0.15, ubuntu 12.04 64bit.
ex:
<?php
$m = new Memcached();
$newServers = array(
array('localhost', 11211, 100),
);
$m->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$m->addServers($newServers);
$d = $m->get('foo');
$m->set('counter', 5);
$n = $m->decrement('counter'); //should return 4, returns -1!?!?
var_dump($n);
$n = $m->decrement('counter', 10);
var_dump($n);
var_dump($m->get('counter'));
$m->set('counter', 'abc');
$n = $m->increment('counter');
var_dump($n);
Output is:
int(-1) int(4) int(0) int(-1)
from php-memcached.
I have a workaround. Using getMulti() instead of get() stops this issue from occurring. The code path for getMulti() and get() are very different. From bvis's example we can see the bug occur.
<?php
$m = new Memcached();
$m->addServer('localhost', '11211');
$m->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$key = uniqid('testIncrement');
assert($m->add($key, 7, 2) === true); // Adding value 7
assert($m->get($key) === 7); // Check right value was saved
assert($m->decrement($key, 2) === 5); // Decrement to 5
However this code works and does not have the bug:
<?php
$m = new Memcached();
$m->addServer('localhost', '11211');
$m->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$key = uniqid('testIncrement');
assert($m->add($key, 7, 2) === true); // Adding value 7
$retVal = $m->getMulti(array($key)); // Check right value was saved
assert($retVal[$key] === 7); // Check right value was saved
assert($m->decrement($key, 2) === 5); // Decrement to 5
The function php_memc_get_impl() in php_memcached.c uses the libmemcached function memcached_fetch(). The function memcached_fetch() is deprecated:
http://docs.libmemcached.org/libmemcached/memcached_fetch.html
I believe memcached_fetch() is causing this problem but I will have to do more research to confirm.
from php-memcached.
Thanks for the update. I have modified my app code to do what you mention and it seems to be working.
from php-memcached.
I haven't run the tests here explicitly but I believe pull request #75 should fix this.
from php-memcached.
Related Issues (20)
- Incorrect PHP reflection type for Memcached::cas $cas_token HOT 1
- Release 3.2.1 HOT 8
- Support for PHP 8.1.7 HOT 5
- get returns random values when lower than default OPT_POLL_TIMEOUT is set HOT 42
- When using sasl return false
- What is $udf_flags in memcached-api.php?
- Use memcache on wordpress with php 8.1 HOT 2
- Installing in docker, with apache + php-7.4 | GC_REFCOUNT HOT 3
- Problem stored float value in PHP 8.1/8.2 HOT 1
- pickle.phar installation of memcached doesn't work anymore as of PHP 8.1.20 and PHP 8.2.7 HOT 3
- OPT_NOREPLY: touch() stuck forever
- Suspicion of php-memcached bug regarding persistent sessions resulting in rare cases of session mixup
- No updated DLL version available HOT 3
- please help install php 8.0 memcache in docker HOT 1
- Undocumented 3.2.0 change: non-ascii keys no longer supported. HOT 10
- PHP 8.3 HOT 1
- Release zstd support
- memcached.so: php_msgpack_serialize: symbol not found HOT 2
- memcached returns wrong values.
- get/getMulti return RES_NOTFOUND after buffered increment with result RES_UNKNOWN_READ_FAILURE with OPT_BINARY_PROTOCOL HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-memcached.