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\Session\Adapter\Redis

I'm triying to set a "redis" param to the redis session adapter, but it does not work, it tries to connect to the default localhost, since I didn't define a host. Can't I define a redis connection on the adapters? Using phalcon 2.0.8

        $di->setShared('redis', function () {
            $redis = new \Redis();
            $redis->connect($this->config->redis->host, $this->config->redis->port);
            return $redis;
        });

         $di->setShared('session', function () use ($di) {
            $session = new Phalcon\Session\Adapter\Redis([
                'redis'      => $di->getRedis(), // HERE I SET THE ALREADY DEFINED CONNECTION
                'persistent' => false,
                'lifetime'   => 3600,
            ]);

            $session->start();

            return $session;
        });

As i see it does not work anymore using "redis" as one of the config parameters, for session adapter redis or caché. Is there any way to set the connection this way instead of reliying on Phalcon to connect each time?

You can set up redis session adapter in PHP config

session.save_handler = redis
session.save_path = "tcp://localhost:6379?auth=redisPassword"

and use standard session adapter Phalcon\Session\Adapter\Files in Phalcon, I am using it this way and works fine.

Or you can configure redis session adapter with these options

new Phalcon\Session\Adapter\Redis([
    'host' => 'localhost',
    'port' => 6379,
    'persistent' => true,
    'lifetime' => 3600
])