We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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 https://simplapi.wordpress.com/2012/04/13/php-and-node-js-session-share-redi/

I think what I need change session adapter on dependency injection

$di->set('session', function(){
    $session = new SessionAdapter();
    $session->start();
    return $session;
});

How to make the most correct?



13.8k

I use this code

$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:

$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



98.9k

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