phpmemcachedcaslibmemcache

PHP Memcached CAS (check and set) issue


Hey all, here are the version of my current setup Memcached (1.2.2) Pecl Memcached Client 1.0.2 (using libmemcached 0.43)

Issue: I cant get a cas token returned during a get request

Here is the code in question!

 27   public function action_test() {
 28     //phpinfo();
 29     $m = Model_Mem::getSingleton();
 30     $found = $m->get('navigation');
 31     echo (int)count($found).'<br />'; // Returns an array of navigation objects
 32
 33     $cas = 0;
 34     $found = $m->get('navigation', null, &$cas);
 35     echo (int)count($found); // Returns nothing!
 36
 37     exit;
 38   }

The output from the first echo is 7, and the second echo is 1. Also, the $cas variable as well as the $found variable from the second group of code are both empty. Im not 100% sure if I am doing this right but the cas token just doesnt seem to be working for me at all. Ive went through the php Memcached documentation with no mention on any kind of CAS enable flag that i could easily spot. Ive also tried to look at the memcached.org site for some info but im lost!

Ive never had any problems with it, its just everytime i try and use the cas functionality on a get request i do something wrong. Thanks for anyone helping me out!

*EDIT Here is what the Model_Mem::getSingleton() function returns

  static function getSingleton() {
    if (self::$m) 
      return self::$m;

    self::$m = new Memcached();

    $servers = array(
      array('127.0.0.1', 11211, 25),
      array('127.0.0.1', 11212, 25),
      array('127.0.0.1', 11213, 25),
      array('127.0.0.1', 11214, 25)
    );

    // Sets up some options for the memcache server
    self::$m->setOption(Memcached::OPT_DISTRIBUTION,Memcached::DISTRIBUTION_CONSISTENT);
    self::$m->setOption(Memcached::OPT_PREFIX_KEY, Kohana::config('globals.prefix'));
    self::$m->addServers($servers);

    return self::$m;
  }

Solution

  • Arg, debian's latest [secure] memcached release didn't have this feature yet. Upgraded to the latest by installing the memcached server's source and all is well.