2012-02-10 55 views
4

我有Zend Framework項目,我決定使用Rediska作爲Redis客戶端。 Rediska爲ZF提供緩存後端適配器 - Rediska_Zend_Cache_Backend_Redis。在緩存過程中Redis錯誤「連接讀取超時」

我從DB對象集合中獲取對象,並嘗試將它保存在緩存中但出現錯誤:連接讀取超時。我的代碼示例:

$rediskaOptions = array(
        'name' => 'cache', 
        'namespace' => 'Cache_', 
        'servers' => array('cache' => array(
         'host' => Rediska_Connection::DEFAULT_HOST, 
         'port' => Rediska_Connection::DEFAULT_PORT, 
         'password' => 'qwerty' 
         ) 
        ) 
     ); 

$cache = Zend_Cache::factory('Core', 'Rediska_Zend_Cache_Backend_Redis', 
    array('lifetime' => NULL, 'automatic_serialization' => true), 
    array('rediska' => $rediskaOptions), false, true 
); 
$cacheId = 'news_main'; 
if (!($topics = $cache->load($cacheId))) { 
    $topics = DAOFactory::getInstance()->getTopicDAO()->fetchTopic(1); 
    $cache->save($topics, $cacheId); 
} 

的序列化後的內容大小爲26787個字節。 也許Redis有發送的大小限制?

+0

值的Redis大小限制遠高於此值。字符串值的理論限制是512MB。存儲26KB對象應該沒有問題。 – 2012-02-11 09:59:33

+0

readTimeout參數的值是多少? http://rediska.geometria-lab.net/documentation/configuration/servers/ – 2012-02-11 10:11:52

+0

我在/etc/redis/redis.conf中設置了timeout 0,rediska中的readTimeout默認值爲null。 – Dmitro 2012-02-11 14:29:21

回答

0

如果有幫助,我也使用Zis的Rediska。這是我如何設置它。

$options = array(
       'servers' => array(
        array( 'host'  => '127.0.0.1', 
          'port'  => 6379, 
          'alias' => 'cache' 
       ), 
       //'name' => 'cache', 
       //'namespace' => 'Cache_' 
       ) 
      ); 

    $rediska = new Rediska($options); 

    $frontendOptions = array('automatic_serialization' => true); 
    $backendOptions = array('rediska' => $rediska); 

    $cache = Zend_Cache::factory('Core', 
      'Rediska_Zend_Cache_Backend_Redis', 
      $frontendOptions, 
      $backendOptions, 
      false, 
      true 
    ); 

我看到的差異是在後端選項。我將rediska指向rediska實例。

+0

我嘗試了你寫的,但它沒有幫助。 – Dmitro 2012-02-22 11:10:40