缓存期间Redis错误“连接读取超时”

时间:2012-02-10 12:50:09

标签: php zend-framework redis zend-cache rediska

我有Zend Framework项目,我决定使用Rediska作为Redis客户端。 Rediska为ZF提供了缓存后端适配器 - Rediska_Zend_Cache_Backend_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有发送的大小限制?

1 个答案:

答案 0 :(得分:0)

如果有帮助,我也会使用Rediska和ZF。以下是我如何设置它。

$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实例。

相关问题