Hi all,
I'm building an app that rely on Redis to store cache and session but I'm having a few issues. Nothing really critical, but some options/parameters seem to be missing in the adapter. I've updated Phalcon and the incubator this morning.
First of all, I've install phpredis and igbinary and my app works just fine. But I'd like to push the configuration a bit further:
- using different redis.databases for session and different caches
- using different preffix for different type of cache ( "fe." for frontend, "be." for backend, "data." for generated sets of data...)
front & backend cache:
I'm using the default phalcon adapter here (Phalcon\Cache\Backend\Redis) and I can't find the way to customize the prefix or database used by Redis.
Tried many sets of config, but can't make redis use the prefix or database I want. See a sample below:
$asRedisConf = array(
'host' => '127.0.0.1:6379?weight=1&database='.CONF_REDIS_DB_CACHE,
'port' => 6379,
'persistent' => false,
'index' => CONF_REDIS_DB_CACHE,
'database' => CONF_REDIS_DB_CACHE,
'lifetime' => 43200,
'prefix' => '_dfe_',
'uniqueId' => '_dfe_',
'statsKey' => '_dfe_',
'prefix' => '_dfe_',
'name' => '_dfe_',
'index' => CONF_REDIS_DB_SESSION,
'database' => CONF_REDIS_DB_SESSION
);
$di->set('cache', function () use($asRedisConf) {
$oFrontCache = new Phalcon\Cache\Frontend\Data(array(
'lifetime' => 43200,
'prefix' => 'all.'
));
$oRedis = new Phalcon\Cache\Backend\Redis($oFrontCache, array('redis' => $asRedisConf));
return $oRedis;
});
Sessions
I've got roughly the same problems. I'm using the Redis class from the incubator here. I've found a way to specify a database in the connection url, but couldn't specify any prefix.
$___asConfig['session'] = array(
'path' => 'tcp://127.0.0.1:6379?weight=1&database='.CONF_REDIS_DB_SESSION,
'lifetime' => 43200, //12hr
'cookie_lifetime' => 0, // infinite
'cookie_secure' => true,
'uniqueId' => '_dses_',
'statsKey' => '_dses_',
'prefix' => '_dses_',
'name' => '_dses_',
'index' => CONF_REDIS_DB_SESSION,
'database' => CONF_REDIS_DB_SESSION
);
$di->get('loader')->registerClasses(array('Phalcon\Session\Adapter\Redis' => PATH_LIBS.'/PIncubator/Session/Adapter/Redis.php'), true);
$di->setShared('session', function() use($___asConfig){
$oRedis = new \Phalcon\Session\Adapter\Redis($___asConfig['session']);
//$oRedis->select(CONF_REDIS_DB_SESSION);
//->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY);
$oRedis->start();
return $oRedis;
});
Has anybody managed to make that work ? Should I give up Phalcon class and use phpRedis directly ? Or is there any plan to update the adapters to allow custom connections params (selectDb(), setPrefix()...)
Thanks