Yii 1.1: rediscache

Use Redis as your cache system
19 followers

Use Redis as your cache system

Redis is a great cache system, it store the cache in ram and send it to the hard drive once in a while, so you dont lose when the pc shut down

Requirements

  • PHP 5.2.x
  • Tested with Yii 1.1.5, should work with any 1.1.*
  • A redis server running

Usage

Download and extract it on your extensions folder . The main file must be located in application.extensions.redis.CRedisCache

To setup :

define in the application's configuration array ( by default configs/main.php)

'components'=>array(
                'cache'=>array(
                        'class'=>'ext.redis.CRedisCache',
                        //if you dont set up the servers options it will use the default one 
                        //"host=>'127.0.0.1',port=>6379"
                        'servers'=>array(
                                array(
                                        'host'=>'server1',
                                        'port'=>6379,
                                ),
                                //if you use 2 servers
                                array(
                                        'host'=>'server2',
                                        'port'=>6379,
                                ),
                        ),
                ),
        ),

Be sure that its under components

then you can use any redis function by calling it normally Yii way, like :

//yii's default functions
Yii::app()->cache->get($name);
Yii::app()->cache->set($name,$value,$time);
//redis specific functions
Yii::app()->cache->{$function}($arg1,$arg2,$arg3);
//example of selecting a db
Yii::app()->getCache()->select(2);

Version

  • 0.2 Fixed a couple of bugs and rewrite of the code (25/02/11)
  • 0.1 Release

Resources

forum / suport

It uses Predis as redis php client


Thumbs up

Total 7 comments

#16796 report it
Rajith R at 2014/03/29 02:29am
Hi Gustavo / muayyad alsadi

Hi,

This is a great extension .

I am using YIi User modules for user management . Is there any change in needed in user module when i use redis ?

#13467 report it
realtebo at 2013/05/30 04:11am
i'm moving to the forum

Please, follow me on the forum to go on with replying.

#13466 report it
muayyad alsadi at 2013/05/30 03:46am
it was the latest

I've done that on 2012/06/03. no worries the Predis is included in the archive attached in forum

it's here is you want it https://github.com/nrk/predis/tree/v0.7.2

#13465 report it
realtebo at 2013/05/30 03:39am
PRedis 7.2 ?

Sorry, but at

https://github.com/nrk/predis

version is 0.8 ! What's 7.2?

Also, YiiRedis require a php extension and we CANNOT use it. I need a php pure library

#13464 report it
muayyad alsadi at 2013/05/30 03:28am
yii redis

@realtebo it seems it's dead, I've upgraded the Predis to 7.2, and fixed it

it seems fine for my needs, but others are reporting that mget watch does not work see the yii forum link above

you might consider this alternative https://github.com/phpnode/YiiRedis

#13463 report it
realtebo at 2013/05/30 03:02am
is it updated and mantained ?

We'd like to start using your extension for a large application.

It looks like a very good start point, could you tell me if this extensions is 'live', is maintened and keep updated ?

#8437 report it
muayyad alsadi at 2012/06/03 09:21am
suggested update to Predis 7.2

here is an updated version

http://www.yiiframework.com/forum/index.php?app=core&module=attach&section=attach&attach_id=2926

you can discuss it in the forum

http://www.yiiframework.com/forum/index.php?/topic/13348-redis-cache/

Leave a comment

Please to leave your comment.

Create extension
Downloads