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

Use both file and Redis for session

Recently i have started using Phalcon, I want use Redis for session management, But i don't want to stop using php session as well, Presently i am able to make session with each of them but one at a time, So what i tried is as following :

use Phalcon\Session\Adapter\Files as SessionAdapter;

use Phalcon\Session\Adapter\Redis as RedisSessionAdapter;

$di->setShared('session',

function () {

$session = new SessionAdapter();

$session->start();

return $session;

});

$di->setShared('sessionRedis',

function () {

$session = new RedisSessionAdapter(array(

        "scheme" => "tcp",

        'uniqueId' => 'my-private-app',

        'host' => '192.168.3.2',

        'port' => '6379',

        'persistent' => false,

        'lifetime' => '60',

        'prefix' => 'my_'

      ));

$session->start();

return $session;

});

Plz can some one answer this?

What you mean stop using php session ? Php session will be used anyway. Redis will be only adapter for storing it.

edited Nov '16

Thanks for reply,

I meant that, I have included both file( Phalcon\Session\Adapter\Files as SessionAdapter;) and redis(Phalcon\Session\Adapter\Redis as RedisSessionAdapter;) as service , And when i use as mention bellow it is not working, To make it work i have to remove files service( Phalcon\Session\Adapter\Files as SessionAdapter;) from services

public function indexAction() {

    $session = $this->sessionRedis;

    $session->set( 'abc', '56589' );

    echo $session->get( 'abc' );

    die;

}

So what i want is when i use $session = $this->sessionRedis; it should use redis, and when i use $session = $this->session; it should use files.

I have asked same question here too, So if any one not getting what is my doubt, Please read my question at bellow url

https://forum.phalcon.io/discussion/12087/use-phalconsessionadapterredis-to-store-seesions-user#C43181

You can use files or redis. Not both. Not sure why you even need both.

Presently we are having Redis server on a separate machine, So I want to write both service. So any developer from team want access regular file sessions then he can, and specifically any one want Redis then he can also for that he need not change services.

As you say it not possible then is it possible that i can create a configuration setting which can decide that what will be your adaptor, So that if there is a down time of redis server or any xyz reason so we can switch back to files