Redis Cache


Mget operation does not work.

Doing so:






Gives empty answers

But separately is getting all right.

just a performance test (using servers in localhost)



10000 single integer write : 0.028426885604858 seconds



10000 single integer write : 6.9566950798035 seconds



10000 single integer write : 3.1675958633423 seconds

is this using my updated version or the original one ?

and can we compare to different redis implementations like this one

would you post the script you use to benchmark here

I’m using your version, without any modifications.

The script is a simple sequence of for using ‘get’ or ‘set’.

this my benchmark code

10,000 set of simple key and simple string value (I’ve also tried integer value of 10)

./protected/cmdrun cache benchmark

YiiRedis delta 1.1029698848724

Predis delta 1.7682290077209

[alsadi@localhost muayyad-appii]$ 

Argh !! I’ll try to use ->getClient to directly access redis… thanks for this benchmark

getClient is for the YiiRedis not PRedis

Hi Gustavo and Muayyad,

thanks for the great extension. I’m only having some issues with addValue(), which I’m using to implement exclusive locks for an application of mine. It looks like there’s some typo in the method, namely the $time variable which is not initialized anywhere. I will fix it in my copy, but I guess it would be better if you fixed it in your distribution as well.

	protected function addValue($key,$value,$expire)




            	return $this->_cache->expire($key,$time);

        	return false;


			return $this->_cache->setnx($key,$value);


Hi all,

I’m using CRedisCache with redis server 2.6.13 and getting stuck with mget function… It seems to me that the mget function of CCache.php does not work properly. Below is what I did

  • I used the


function to save to cache my objects under array format like this:

Yii::app()->cache->{'set'}($key, $value); // $key is an integer, $value is an array

  • After that i used


on passing a list of keys to get the corresponding objects, but it return an error like below:

PHP notice

Undefined offset: 0


268      */

269     public function writeCommand(ICommand $command)

270     {

271         $commandId = $command->getId();

272         $arguments = $command->getArguments();


274         $cmdlen = strlen($commandId);

275         $reqlen = count($arguments) + 1;


277         $buffer = "*{$reqlen}\r\n\${$cmdlen}\r\n{$commandId}\r\n";


279         for ($i = 0; $i < $reqlen - 1; $i++) {

[b]280             $argument = $arguments[$i];[/b]

281             $arglen = strlen($argument);

282             $buffer .= "\${$arglen}\r\n{$argument}\r\n";

283         }

292     {


  • I also try

multi & exec



but it doesn’t work either. There’s an error like:

unserialize(): Error at offset 0 of 6 bytes

Stack Trace


+  /Users/NguyenTuanQuyen/Sites/cms/core/yii/framework/caching/CCache.php(108): unserialize("QUEUED")


–  /Users/NguyenTuanQuyen/Sites/thethao/common/components/RedisCacheHelper.php(27): CCache->get("63")

22     const MAX_ARTICLE_PER_TERM = 500;


24     const PREFIX_HASH_KEY = 'hv_';


26     public static function get($key) {

27         return Yii::app()->cache->{'get'}($key);

28     }


Thanks a million for helping me!