EllisLab text mark
Advanced Search
     
[SOLVED] Memcached in 2.1
Posted: 24 January 2012 03:05 AM   [ Ignore ]
Avatar
Joined: 2010-10-14
125 posts

Hi, I’m using CI 2.1 and trying to put some datas into memcached and retrieve it without success. I use Ubuntu and installed memcache and memcached. I can telnet into localhost to check if the caching working, I can add values manually then read them on console. And with netstat I see memcached is running and listening on port 11211.

If I use plain php oop commands to init and store / get datas, no probs, but using CI driver and commands always get bool/false.

Then I updated the Driver_memcached.php to the latest version (yesterday) from github, result is the same.

Using n0xie-s test method I always get the “Saving to the cache” message..

$this->load->driver('cache', array('adapter' => 'memcached''backup' => 'file'));

        
$foo $this->cache->get('testkey');

        if ( ! 
$foo )
        
{
             
echo 'Saving to the cache!<br />';
             
$foo 'test value';

             
// Save into the cache for 5 minutes
             
$this->cache->save('testkey'$foo300);
        
}
        
else
        
{
            var_dump
($foo);
        

Using this example all goes well:

$memcache = new Memcache;
  
$memcache->connect('localhost'11211) or die ("Could not connect");

  
$version $memcache->getVersion();
  echo 
"Server's version: ".$version."<br/>\n";

  
$tmp_object = new stdClass;
  
$tmp_object->str_attr 'test';
  
$tmp_object->int_attr 123;

  
$memcache->set('key'$tmp_objectfalse10) or die ("Failed to save data at the server");
  echo 
"Store data in the cache (data will expire in 10 seconds)<br/>\n";

  
$get_result $memcache->get('key');
  echo 
"Data from the cache:<br/>\n";

  
var_dump($get_result); 

My purpose is to use CI Driver, any idea what could the problem be?
Thanks

EDIT: I forgot to add memcached config file, thanks n0xie for the hint