Phalcon + Redis (save session)

How I can add Predis library (https://github.com/nrk/predis) to Phalcon application? I want to use a Redis server to store user sessions. I use this manual http://simplapi.wordpress.com/2012/04/13/php-and-node-js-session-share-redi/

I think what I need change session adapter on dependency injection ```php $di->set('session', function(){ $session = new SessionAdapter(); $session->start(); return $session; }); ``` How to make the most correct?



8.8k

I use this code ```php $di->set('session', function(){ require(APP_PATH."/library/Predis/Autoloader.php"); //Registering Predis system Predis\Autoloader::register();

$session = new RedisSessionHandler();
$session->start();
return $session;

}); ``` but when I'm trying to get the session: ```php $session = $di->getShared('session'); $auth = $session->get('auth'); $user = $session->get('user-data'); ```

I get exception

Fatal error: Call to undefined method Academy\RedisSessionHandler::get() in G:\www\domains\localhost3\app\config\services.php on line 80



84.6k

You're returning a RedisSessionHandler instance, but you must return an object compatible with Phalcon\Session\AdapterInterface as session service.