YiiRedis icon indicating copy to clipboard operation
YiiRedis copied to clipboard

Config-level connection for session (and cache?)

Open 0x0ece opened this issue 11 years ago • 2 comments

Hi,

I'd like to separate data in different databases, in particular sessions from data, say respectively into database 1 and 2.

I noticed you can instantiate any RedisEntity by specifying a connection, so in principle I can do that. However, I'd find more usable/less error prone to setup the default connection for data, and configure session to use another connection.

A proposal follows, please let me know if you'd like a pull request. E.

  • changes to ARedisSession.php

    public $connection = null;
    
    /**
     * Initializes the application component.
     * This method overrides the parent implementation by checking if redis is available.
     */
    public function init()
    {
        if ($this->connection !== null)
            $this->setConnection($this->connection);
        else
            $this->getConnection();
        parent::init();
    }
    
    
    - example of main/config.php
    
    ```php
    'redis' => array(
        'class' => 'ext.redis.ARedisConnection',
        'hostname' => 'localhost',
        'database' => 2,
        'port' => 6379,
    ),
    'redis-session' => array(
        'class' => 'ext.redis.ARedisConnection',
        'hostname' => 'localhost',
        'database' => 1,
        'port' => 6379,
    ),
    'session' => array(
        'class' => 'ext.redis.ARedisSession',
        'connection' => 'redis-session',
    ),
    

0x0ece avatar Dec 04 '13 01:12 0x0ece

Hi ecesena,

+1

I can't agree more. And should be different from CRedisCache also. If you specify the change proposal we can develop it together.

Best,

Otávio

otaviofcs avatar Dec 13 '13 13:12 otaviofcs

+1. The same problem is in the ARedisStatePersister.php. That would be great, if you can provide pull request.

vgoodvin avatar Dec 16 '13 05:12 vgoodvin