2013-05-31 3 views
0

кто-то может помочь мне настроить redis cache с помощью zend framework. Я успешно настроил кеш файловой системы следующим образом. global.pgpКак настроить Redis Cache с Zend framework 2?

return array(
    'db' => array(
     'driver' => 'Pdo', 
     'dsn' => 'mysql:dbname=tvguide;host=localhost', 
     'driver_options' => array(
      PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' 
     ), 
    ), 
    'service_manager' => array(
     'factories' => array(
      'Zend\Db\Adapter\Adapter' 
      => 'Zend\Db\Adapter\AdapterServiceFactory', 
     ), 
     'factories' => array(
      'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory', 
      'Zend\Cache\Storage\Filesystem' => function($sm) { 
       $cache = Zend\Cache\StorageFactory::factory(array(
          'adapter' => 'filesystem', 
          'plugins' => array(
           'exception_handler' => array('throw_exceptions' => false), 
           'serializer' 
          ) 
         )); 

       $cache->setOptions(array(
        'cache_dir' => './data/cache' 
       )); 

       return $cache; 
      }, 
     ), 
    ), 
); 

Мои module.php

'factories' => array(
       'json_hub\Model\Entity\CustomerQueriesTable' => function($sm) { 
        $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); 
        $cacheAdapter = $sm->get('Zend\Cache\Storage\Filesystem'); 
        $table = new Model\Entity\CustomerQueriesTable($dbAdapter); 
        $table->setCache($cacheAdapter); 
        return $table; 
       }, 
      ) 

в контроллере я позвонить в кэш, как показано ниже.

$this->cache->setItem('samplecache', $data); 

ваша помощь, если высоко оценил

ответ

3

Есть в конфигурационном файле:

... 
    'my-redis-cache' => array (
      'adapter' => array (
        'name' => 'redis', 
        'options' => array (
          'server' => [ 
            'host' => '127.0.0.1', 
            'port' => 6379, 
          ] 
        ) 
      ), 
    ) 
... 

, а затем где-то в контроллере:

use Zend\Cache\StorageFactory; 

... 

$redis = StorageFactory::factory ($this->getServiceLocator() 
     ->get ('config') ['my-redis-cache']); 

if ($redis->hasItem ('key')) 
{ 
     $value = $redis->getItem ('key'); 
} 
+0

отблагодарить ваш .. я постараюсь это:). – Chali

+0

нерабочий .. !! – Ritesh

Смежные вопросы