public function createService(ServiceLocatorInterface $serviceLocator) { /** * This fetches the configuration array we created above */ $config = $serviceLocator->get('Config'); /** * The configuration options are encapsulated in a class called RedisOptions * Here we setup the server configuration using the values from our config file */ $redis_options = new RedisOptions(); $redis_options->setServer(array('host' => $config['redis']["host"], 'port' => $config['redis']["port"], 'timeout' => '30')); $redis_options->setNamespace($config['redis']['namespace']); if (isset($config['redis']['auth'])) { $redis_options->setPassword($config['redis']['auth']); } /** * This is not required, although it will allow to store anything that can be serialized by PHP in Redis */ $redis_options->setLibOptions(array(\Redis::OPT_SERIALIZER => \Redis::SERIALIZER_PHP)); /** * We create the cache passing the RedisOptions instance we just created */ $redis_cache = new Redis($redis_options); return $redis_cache->getRedisObj(); }
public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config'); $config = $config['redis']; $redisOptions = new RedisOptions(); $redisOptions->setServer(array('host' => $config["host"], 'port' => $config["port"], 'timeout' => '30')); $redisOptions->setLibOptions(array(\Redis::OPT_SERIALIZER => \Redis::SERIALIZER_PHP)); $redis = new Redis($redisOptions); return $redis; }
/** * Create service * * @param ServiceLocatorInterface $serviceLocator * * @return Redis */ public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('config'); if (!array_key_exists('redis', $config) || !array_key_exists('adapters', $config['redis'])) { throw new RedisFactoryException('No redis adapters exist'); } if (!array_key_exists('entityCache', $config['redis']['adapters'])) { throw new RedisFactoryException('Entity Cache Adapter config does not exists'); } $redisOptions = new RedisOptions(); $redisOptions->setServer($config['redis']['adapters']['entityCache']); $redisOptions->setLibOptions([\Redis::OPT_SERIALIZER => \Redis::SERIALIZER_PHP]); return new Redis($redisOptions); }
public function createService(ServiceLocatorInterface $serviceLocator) { /** * This fetches the configuration array we created above */ $config = $serviceLocator->get('Config'); $config = $config['redis']; $serverConfig = array('host' => $config["host"], 'port' => $config["port"], 'timeout' => '30'); $libOptions = array(\Redis::OPT_SERIALIZER => \Redis::SERIALIZER_PHP); $redisOptions = new RedisOptions(); $redisOptions->setServer($serverConfig); $redisOptions->setLibOptions($libOptions); $redisCache = new Redis($redisOptions); return $redisCache; }
public function testOptionsGetSetDatabase() { $database = 1; $this->_options->setDatabase($database); $this->assertEquals($database, $this->_options->getDatabase(), 'Database not set correctly using RedisOptions'); }