Giter VIP home page Giter VIP logo

Comments (6)

bvis avatar bvis commented on August 26, 2024

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.

kixorz avatar kixorz commented on August 26, 2024

We're experiencing the same issue here.

from php-memcached.

doapp-ryanp avatar doapp-ryanp commented on August 26, 2024

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.

mhagstrand avatar mhagstrand commented on August 26, 2024

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.

doapp-ryanp avatar doapp-ryanp commented on August 26, 2024

Thanks for the update. I have modified my app code to do what you mention and it seems to be working.

from php-memcached.

trvrnrth avatar trvrnrth commented on August 26, 2024

I haven't run the tests here explicitly but I believe pull request #75 should fix this.

from php-memcached.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.