當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CacheProvider::setRedis方法代碼示例

本文整理匯總了PHP中Doctrine\Common\Cache\CacheProvider::setRedis方法的典型用法代碼示例。如果您正苦於以下問題:PHP CacheProvider::setRedis方法的具體用法?PHP CacheProvider::setRedis怎麽用?PHP CacheProvider::setRedis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\Common\Cache\CacheProvider的用法示例。


在下文中一共展示了CacheProvider::setRedis方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: selectDriver

 public function selectDriver($config)
 {
     $cache_engine = $config['cache-engine'];
     //redis, apc, memcache, memcached e xcache
     switch ($cache_engine) {
         case 'redis':
             if (!extension_loaded('redis')) {
                 throw new \Exception("Extensão para {$cache_engine} não encontrada");
             }
             $redis = new \Redis();
             $redis->connect($config['cache-config']['host'], $config['cache-config']['port']);
             $this->driver = new RedisCache();
             $this->driver->setRedis($redis);
             break;
         case 'apc':
             if (!extension_loaded('apc')) {
                 throw new \Exception("Extensão para {$cache_engine} não encontrada");
             }
             $this->driver = new ApcCache();
             break;
         case 'memcache':
             if (!extension_loaded('memcache')) {
                 throw new \Exception("Extensão para {$cache_engine} não encontrada");
             }
             $memcache_config = new \Memcache();
             $memcache_config->connect($config['cache-config']['host'], $config['cache-config']['port']);
             $this->driver = new MemcacheCache();
             $this->driver->setMemcache($memcache_config);
             break;
         case 'memcached':
             if (!extension_loaded('memcache')) {
                 throw new \Exception("Extensão para {$cache_engine} não encontrada");
             }
             $memcached = new \Memcached();
             $memcached->addServer($config['cache-config']['host'], $config['cache-config']['port']);
             $this->driver = new MemcachedCache();
             $this->driver->setMemcached($memcached);
             break;
         case 'xcache':
             if (!extension_loaded('xcache')) {
                 throw new Exception("Extensão para {$cache_engine} não encontrada");
             }
             $this->driver = new XcacheCache();
             break;
         default:
             throw new \Exception('O driver especificado não foi encontado.');
     }
 }
開發者ID:anna-framework,項目名稱:anna,代碼行數:48,代碼來源:Cache.php

示例2: decorateWithConnectable

 /**
  * @param CacheProvider $cacheProvider
  *
  * @return CacheProvider
  */
 protected function decorateWithConnectable(CacheProvider $cacheProvider)
 {
     $redis = $this->getRedisAdapter();
     $settings = $this->config->getSettings();
     $redis->connect($settings['host'], $settings['port']);
     $cacheProvider->setRedis($redis);
     return $cacheProvider;
 }
開發者ID:pcelta,項目名稱:doctrine-cache-factory,代碼行數:13,代碼來源:RedisFactory.php

示例3: _initializeCache

 /**
  * @param string $type
  *
  * @throws \LogicException
  */
 protected function _initializeCache($type)
 {
     switch ($type) {
         case CacheTypes::REDIS:
             $_redis = new \Redis();
             if (false === $_redis->pconnect('127.0.0.1')) {
                 throw new \LogicException('Cannot connect to redis server @ 127.0.0.1');
             }
             $this->_store->setRedis($_redis);
             break;
     }
 }
開發者ID:kisma,項目名稱:kisma,代碼行數:17,代碼來源:Flexistore.php

示例4: getCacheDriver

 /**
  * Get cache driver instance
  *
  * @return \Doctrine\Common\Cache\CacheProvider
  */
 public function getCacheDriver()
 {
     if (!is_null($this->cacheDriver)) {
         return $this->cacheDriver;
     }
     if (php_sapi_name() === 'cli') {
         return $this->cacheDriver = new \Doctrine\Common\Cache\ArrayCache();
     }
     try {
         switch ($this->systemPreferences->get('DBCacheEngine', 'Array')) {
             case 'apc':
                 $this->cacheDriver = new \Doctrine\Common\Cache\ApcCache();
                 break;
             case 'memcache':
                 $memcache = new \Memcache();
                 $memcache->connect($this->systemPreferences->get('DBCacheEngineHost', '127.0.0.1'), $this->systemPreferences->get('DBCacheEnginePort', '11211'));
                 $this->cacheDriver = new \Doctrine\Common\Cache\MemcacheCache();
                 $this->cacheDriver->setMemcache($memcache);
                 break;
             case 'memcached':
                 $memcached = new \Memcached();
                 $memcached->addServer($this->systemPreferences->get('DBCacheEngineHost', '127.0.0.1'), $this->systemPreferences->get('DBCacheEnginePort', '11211'));
                 $this->cacheDriver = new \Doctrine\Common\Cache\MemcachedCache();
                 $this->cacheDriver->setMemcached($memcached);
                 break;
             case 'xcache':
                 $this->cacheDriver = new \Doctrine\Common\Cache\XcacheCache();
                 break;
             case 'redis':
                 $redis = new \Redis();
                 $redis->connect($this->systemPreferences->get('DBCacheEngineHost', '127.0.0.1'), $this->systemPreferences->get('DBCacheEnginePort', '6379'));
                 $this->cacheDriver = new \Doctrine\Common\Cache\RedisCache();
                 $this->cacheDriver->setRedis($redis);
                 break;
             default:
                 $this->cacheDriver = new \Doctrine\Common\Cache\ArrayCache();
                 break;
         }
     } catch (\Exception $e) {
         $this->cacheDriver = new \Doctrine\Common\Cache\ArrayCache();
     }
     return $this->cacheDriver;
 }
開發者ID:alvsgithub,項目名稱:Newscoop,代碼行數:48,代碼來源:CacheService.php


注:本文中的Doctrine\Common\Cache\CacheProvider::setRedis方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。